diff --git a/requirements_dev_optional.txt b/requirements_dev_optional.txt index b037f0e77f..d60113445d 100644 --- a/requirements_dev_optional.txt +++ b/requirements_dev_optional.txt @@ -9,6 +9,7 @@ ipytree==0.2.1 azure-storage-blob==12.8.1 # pyup: ignore redis==3.5.3 types-redis +types-setuptools pymongo==3.12.0 # optional test requirements tox==3.24.1 diff --git a/zarr/storage.py b/zarr/storage.py index f858e42191..73e480a7dd 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -423,7 +423,7 @@ def _init_array_metadata( filters_config = [] # deal with object encoding - if dtype == object: + if dtype.hasobject: if object_codec is None: if not filters: # there are no filters so we can be sure there is no object codec diff --git a/zarr/tests/test_core.py b/zarr/tests/test_core.py index b1346d760e..5ff4767a79 100644 --- a/zarr/tests/test_core.py +++ b/zarr/tests/test_core.py @@ -15,6 +15,7 @@ from numcodecs.compat import ensure_bytes, ensure_ndarray from numcodecs.tests.common import greetings from numpy.testing import assert_array_almost_equal, assert_array_equal +from pkg_resources import parse_version from zarr.core import Array from zarr.meta import json_loads @@ -1362,6 +1363,44 @@ def test_object_codec_warnings(self): if hasattr(z.store, 'close'): z.store.close() + @unittest.skipIf(parse_version(np.__version__) < parse_version('1.14.0'), + "unsupported numpy version") + def test_structured_array_contain_object(self): + + if "PartialRead" in self.__class__.__name__: + pytest.skip("partial reads of object arrays not supported") + + # ----------- creation -------------- + + structured_dtype = [('c_obj', object), ('c_int', int)] + a = np.array([(b'aaa', 1), + (b'bbb', 2)], dtype=structured_dtype) + + # zarr-array with structured dtype require object codec + with pytest.raises(ValueError): + self.create_array(shape=a.shape, dtype=structured_dtype) + + # create zarr-array by np-array + za = self.create_array(shape=a.shape, dtype=structured_dtype, object_codec=Pickle()) + za[:] = a + + # must be equal + assert_array_equal(a, za[:]) + + # ---------- indexing --------------- + + assert za[0] == a[0] + + za[0] = (b'ccc', 3) + za[1:2] = np.array([(b'ddd', 4)], dtype=structured_dtype) # ToDo: not work with list + assert_array_equal(za[:], np.array([(b'ccc', 3), (b'ddd', 4)], dtype=structured_dtype)) + + za['c_obj'] = [b'eee', b'fff'] + za['c_obj', 0] = b'ggg' + assert_array_equal(za[:], np.array([(b'ggg', 3), (b'fff', 4)], dtype=structured_dtype)) + assert za['c_obj', 0] == b'ggg' + assert za[1, 'c_int'] == 4 + def test_iteration_exceptions(self): # zero d array a = np.array(1, dtype=int) @@ -1893,6 +1932,10 @@ def test_object_arrays_danger(self): # Cannot hacking out object codec as N5 doesn't allow object codecs pass + def test_structured_array_contain_object(self): + # skip this one, this data type not supported by N5 + pass + def test_attrs_n5_keywords(self): z = self.create_array(shape=(1050,), chunks=100, dtype='i4') for k in n5_keywords: @@ -2326,6 +2369,10 @@ def test_object_arrays_danger(self): # skip this one, cannot use delta with objects pass + def test_structured_array_contain_object(self): + # skip this one, cannot use delta on structured array + pass + # custom store, does not support getsize() class CustomMapping(object):