|
31 | 31 | import warnings
|
32 | 32 |
|
33 | 33 |
|
34 |
| -import numpy as np |
35 |
| - |
36 |
| - |
37 | 34 | from zarr.util import (normalize_shape, normalize_chunks, normalize_order,
|
38 | 35 | normalize_storage_path, buffer_size,
|
39 | 36 | normalize_fill_value, nolock, normalize_dtype)
|
40 | 37 | from zarr.meta import encode_array_metadata, encode_group_metadata
|
41 | 38 | from zarr.compat import PY2, OrderedDict_move_to_end
|
42 | 39 | from numcodecs.registry import codec_registry
|
43 |
| -from numcodecs.compat import ensure_bytes |
| 40 | +from numcodecs.compat import ensure_bytes, ensure_contiguous_ndarray |
44 | 41 | from zarr.errors import (err_contains_group, err_contains_array, err_bad_compressor,
|
45 | 42 | err_fspath_exists_notdir, err_read_only, MetadataError)
|
46 | 43 |
|
@@ -725,9 +722,8 @@ def __getitem__(self, key):
|
725 | 722 |
|
726 | 723 | def __setitem__(self, key, value):
|
727 | 724 |
|
728 |
| - # handle F-contiguous numpy arrays |
729 |
| - if isinstance(value, np.ndarray) and value.flags.f_contiguous: |
730 |
| - value = ensure_bytes(value) |
| 725 | + # coerce to flat, contiguous array (ideally without copying) |
| 726 | + value = ensure_contiguous_ndarray(value) |
731 | 727 |
|
732 | 728 | # destination path for key
|
733 | 729 | file_path = os.path.join(self.path, key)
|
@@ -1176,7 +1172,7 @@ def __getitem__(self, key):
|
1176 | 1172 | def __setitem__(self, key, value):
|
1177 | 1173 | if self.mode == 'r':
|
1178 | 1174 | err_read_only()
|
1179 |
| - value = ensure_bytes(value) |
| 1175 | + value = ensure_contiguous_ndarray(value) |
1180 | 1176 | with self.mutex:
|
1181 | 1177 | self.zf.writestr(key, value)
|
1182 | 1178 |
|
|
0 commit comments