From 58a5ba07a0b59ec83fb54580d015af17014325aa Mon Sep 17 00:00:00 2001 From: jswhit Date: Sun, 21 Jan 2024 09:24:35 -0700 Subject: [PATCH 1/3] fix for issue1306 --- src/netCDF4/_netCDF4.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index dcfe221a2..1fe1070ec 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4987,7 +4987,10 @@ 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: + data[tuple(i)] = datout.item() + else: + data[tuple(i)] = datout.reshape(shape) # Remove extra singleton dimensions. if hasattr(data,'shape'): From 69824b34c1adef5cff0c5553e2ae3c91074b3970 Mon Sep 17 00:00:00 2001 From: jswhit Date: Sun, 21 Jan 2024 09:29:38 -0700 Subject: [PATCH 2/3] update --- src/netCDF4/_netCDF4.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 1fe1070ec..271a9e4a9 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4988,6 +4988,7 @@ rename a `Variable` attribute named `oldname` to `newname`.""" data[0] = datout else: 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) From 0214a9c149a122eee726c5e1baca614ca795296a Mon Sep 17 00:00:00 2001 From: jswhit Date: Sun, 21 Jan 2024 09:50:05 -0700 Subject: [PATCH 3/3] add test --- test/test_vlen.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_vlen.py b/test/test_vlen.py index 5d7d4f2ce..9e51bfb2d 100644 --- a/test/test_vlen.py +++ b/test/test_vlen.py @@ -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])