Skip to content

Commit 9badf39

Browse files
committed
Drop ensure_bytes definition from zarr.storage
As Numcodecs now includes a very versatile and effective `ensure_bytes` function, there is no need to define our own in `zarr.storage` as well. So go ahead and drop it.
1 parent 3e3920a commit 9badf39

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

zarr/storage.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
normalize_storage_path, buffer_size,
3939
normalize_fill_value, nolock, normalize_dtype)
4040
from zarr.meta import encode_array_metadata, encode_group_metadata
41-
from zarr.compat import PY2, binary_type, OrderedDict_move_to_end
41+
from zarr.compat import PY2, OrderedDict_move_to_end
4242
from numcodecs.registry import codec_registry
43+
from numcodecs.compat import ensure_bytes
4344
from zarr.errors import (err_contains_group, err_contains_array, err_bad_compressor,
4445
err_fspath_exists_notdir, err_read_only, MetadataError)
4546

@@ -444,23 +445,6 @@ def _init_group_metadata(store, overwrite=False, path=None, chunk_store=None):
444445
store[key] = encode_group_metadata(meta)
445446

446447

447-
def ensure_bytes(s):
448-
if isinstance(s, binary_type):
449-
return s
450-
if isinstance(s, np.ndarray):
451-
if PY2: # pragma: py3 no cover
452-
# noinspection PyArgumentList
453-
return s.tostring(order='A')
454-
else: # pragma: py2 no cover
455-
# noinspection PyArgumentList
456-
return s.tobytes(order='A')
457-
if hasattr(s, 'tobytes'):
458-
return s.tobytes()
459-
if PY2 and hasattr(s, 'tostring'): # pragma: py3 no cover
460-
return s.tostring()
461-
return memoryview(s).tobytes()
462-
463-
464448
def _dict_store_keys(d, prefix='', cls=dict):
465449
for k in d.keys():
466450
v = d[k]

0 commit comments

Comments
 (0)