Skip to content

Commit 4702421

Browse files
committed
Merge pull request #469 from shoyer/fix-int32-encoding
Fixed a bug that could occur in serialization of 0-dimensional integer arrays
2 parents 648a61b + 9a1fecc commit 4702421

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

doc/whats-new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Bug fixes
4545
- :py:func:`~xray.open_dataset` and :py:func:`~xray.open_mfdataset` support
4646
supplying chunks as a single integer.
4747
- Fixed a bug in serializing scalar datetime variable to netCDF.
48+
- Fixed a bug that could occur in serialization of 0-dimensional integer arrays.
4849
4950
v0.5.1 (15 June 2015)
5051
---------------------

xray/conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def maybe_encode_dtype(var):
574574
dtype = np.dtype(encoding.pop('dtype'))
575575
if dtype != var.dtype and dtype.kind != 'O':
576576
if np.issubdtype(dtype, int):
577-
data = ops.around(data)
577+
data = ops.around(data)[...]
578578
if dtype == 'S1' and data.dtype != 'S1':
579579
data = string_to_char(np.asarray(data, 'S'))
580580
dims = dims + ('string%s' % data.shape[-1],)

xray/test/test_conventions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ def test_invalid_coordinates(self):
456456
actual = conventions.decode_cf(original)
457457
self.assertDatasetIdentical(original, actual)
458458

459+
def test_0d_int32_encoding(self):
460+
original = Variable((), np.int32(0), encoding={'dtype': 'int64'})
461+
expected = Variable((), np.int64(0))
462+
actual = conventions.maybe_encode_dtype(original)
463+
self.assertDatasetIdentical(expected, actual)
464+
459465

460466
class CFEncodedInMemoryStore(InMemoryDataStore):
461467
def store(self, variables, attributes):

0 commit comments

Comments
 (0)