Skip to content

Commit

Permalink
Merge pull request #1309 from Unidata/issue1306
Browse files Browse the repository at this point in the history
fix for issue #1306
  • Loading branch information
jswhit authored Jan 22, 2024
2 parents 7b4f881 + 0214a9c commit 5dbda10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/netCDF4/_netCDF4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4987,7 +4987,11 @@ rename a `Variable` attribute named `oldname` to `newname`."""
# special case of scalar VLEN
data[0] = datout
else:
data[tuple(i)] = datout.reshape(shape)
if self._isvlen and not shape:
# issue #1306 - convert length 1 object array to string
data[tuple(i)] = datout.item()
else:
data[tuple(i)] = datout.reshape(shape)

# Remove extra singleton dimensions.
if hasattr(data,'shape'):
Expand Down
2 changes: 2 additions & 0 deletions test/test_vlen.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def runTest(self):
assert_array_equal(f.variables['vlen_scalar'][...],np.array([1,2,3],np.int16))
data2 = v[:]
data2s = vs[:]
# issue #1306
assert repr(vs[[0,2,3],0]) == "array(['ab', 'abcdefghijkl', 'abcdefghijklmnopq'], dtype=object)"
for i in range(nlons):
for j in range(nlats):
assert_array_equal(data2[j,i], data[j,i])
Expand Down

0 comments on commit 5dbda10

Please sign in to comment.