|
15 | 15 | from numcodecs.compat import ensure_bytes, ensure_ndarray
|
16 | 16 | from numcodecs.tests.common import greetings
|
17 | 17 | from numpy.testing import assert_array_almost_equal, assert_array_equal
|
| 18 | +from pkg_resources import parse_version |
18 | 19 |
|
19 | 20 | from zarr.core import Array
|
20 | 21 | from zarr.meta import json_loads
|
@@ -1362,6 +1363,44 @@ def test_object_codec_warnings(self):
|
1362 | 1363 | if hasattr(z.store, 'close'):
|
1363 | 1364 | z.store.close()
|
1364 | 1365 |
|
| 1366 | + @unittest.skipIf(parse_version(np.__version__) < parse_version('1.14.0'), |
| 1367 | + "unsupported numpy version") |
| 1368 | + def test_structured_array_contain_object(self): |
| 1369 | + |
| 1370 | + if "PartialRead" in self.__class__.__name__: |
| 1371 | + pytest.skip("partial reads of object arrays not supported") |
| 1372 | + |
| 1373 | + # ----------- creation -------------- |
| 1374 | + |
| 1375 | + structured_dtype = [('c_obj', object), ('c_int', int)] |
| 1376 | + a = np.array([(b'aaa', 1), |
| 1377 | + (b'bbb', 2)], dtype=structured_dtype) |
| 1378 | + |
| 1379 | + # zarr-array with structured dtype require object codec |
| 1380 | + with pytest.raises(ValueError): |
| 1381 | + self.create_array(shape=a.shape, dtype=structured_dtype) |
| 1382 | + |
| 1383 | + # create zarr-array by np-array |
| 1384 | + za = self.create_array(shape=a.shape, dtype=structured_dtype, object_codec=Pickle()) |
| 1385 | + za[:] = a |
| 1386 | + |
| 1387 | + # must be equal |
| 1388 | + assert_array_equal(a, za[:]) |
| 1389 | + |
| 1390 | + # ---------- indexing --------------- |
| 1391 | + |
| 1392 | + assert za[0] == a[0] |
| 1393 | + |
| 1394 | + za[0] = (b'ccc', 3) |
| 1395 | + za[1:2] = np.array([(b'ddd', 4)], dtype=structured_dtype) # ToDo: not work with list |
| 1396 | + assert_array_equal(za[:], np.array([(b'ccc', 3), (b'ddd', 4)], dtype=structured_dtype)) |
| 1397 | + |
| 1398 | + za['c_obj'] = [b'eee', b'fff'] |
| 1399 | + za['c_obj', 0] = b'ggg' |
| 1400 | + assert_array_equal(za[:], np.array([(b'ggg', 3), (b'fff', 4)], dtype=structured_dtype)) |
| 1401 | + assert za['c_obj', 0] == b'ggg' |
| 1402 | + assert za[1, 'c_int'] == 4 |
| 1403 | + |
1365 | 1404 | def test_iteration_exceptions(self):
|
1366 | 1405 | # zero d array
|
1367 | 1406 | a = np.array(1, dtype=int)
|
@@ -1905,6 +1944,10 @@ def test_structured_with_object(self):
|
1905 | 1944 | # Cannot hacking out object codec as N5 doesn't allow object codecs
|
1906 | 1945 | pass
|
1907 | 1946 |
|
| 1947 | + def test_structured_array_contain_object(self): |
| 1948 | + # Cannot hacking out object codec as N5 doesn't allow object codecs |
| 1949 | + pass |
| 1950 | + |
1908 | 1951 | def test_attrs_n5_keywords(self):
|
1909 | 1952 | z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
|
1910 | 1953 | for k in n5_keywords:
|
@@ -2338,6 +2381,10 @@ def test_object_arrays_danger(self):
|
2338 | 2381 | # skip this one, cannot use delta with objects
|
2339 | 2382 | pass
|
2340 | 2383 |
|
| 2384 | + def test_structured_array_contain_object(self): |
| 2385 | + # skip this one, cannot use delta on structured array |
| 2386 | + pass |
| 2387 | + |
2341 | 2388 |
|
2342 | 2389 | # custom store, does not support getsize()
|
2343 | 2390 | class CustomMapping(object):
|
|
0 commit comments