Skip to content

Commit 5e5efc5

Browse files
committed
py2 compat
1 parent 228924a commit 5e5efc5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

zarr/compat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
class PermissionError(Exception):
1717
pass
1818

19+
def OrderedDict_move_to_end(od, key):
20+
od[key] = od.pop(key)
21+
22+
1923
else: # pragma: py2 no cover
2024

2125
text_type = str
2226
binary_type = bytes
2327
from functools import reduce
2428
PermissionError = PermissionError
29+
30+
def OrderedDict_move_to_end(od, key):
31+
od.move_to_end(key)

zarr/storage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
normalize_storage_path, buffer_size,
2929
normalize_fill_value, nolock, normalize_dtype)
3030
from zarr.meta import encode_array_metadata, encode_group_metadata
31-
from zarr.compat import PY2, binary_type
31+
from zarr.compat import PY2, binary_type, OrderedDict_move_to_end
3232
from numcodecs.registry import codec_registry
33-
from zarr.errors import (err_contains_group, err_contains_array, err_path_not_found,
34-
err_bad_compressor, err_fspath_exists_notdir, err_read_only)
33+
from zarr.errors import (err_contains_group, err_contains_array, err_bad_compressor,
34+
err_fspath_exists_notdir, err_read_only)
3535

3636

3737
array_meta_key = '.zarray'
@@ -1783,7 +1783,7 @@ def __getitem__(self, key):
17831783
# cache hit if no KeyError is raised
17841784
self.hits += 1
17851785
# treat the end as most recently used
1786-
self._values_cache.move_to_end(key)
1786+
OrderedDict_move_to_end(self._values_cache, key)
17871787

17881788
except KeyError:
17891789
# cache miss, retrieve value from the store

zarr/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ def buffer_size(v):
318318
return v.buffer_info()[1] * v.itemsize
319319
else: # pragma: py2 no cover
320320
v = memoryview(v)
321-
return reduce(operator.mul, v.shape, 1) * v.itemsize
321+
if v.shape:
322+
return reduce(operator.mul, v.shape) * v.itemsize
323+
else:
324+
return v.itemsize
322325

323326

324327
def info_text_report(items):

0 commit comments

Comments
 (0)