Skip to content

Commit 366ed0e

Browse files
committed
test and fix for #143 index with numpy integer item
1 parent 07eb69e commit 366ed0e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

zarr/compat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@
44
import sys
55

66

7+
import numpy as np
8+
9+
710
PY2 = sys.version_info[0] == 2
811

912

13+
numpy_integer_types = np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, \
14+
np.uint64
15+
16+
1017
if PY2: # pragma: no cover
1118

1219
text_type = unicode
1320
binary_type = str
14-
integer_types = (int, long)
21+
integer_types = (int, long) + numpy_integer_types
1522
reduce = reduce
1623

1724
else:
1825

1926
text_type = str
2027
binary_type = bytes
21-
integer_types = int,
28+
integer_types = (int,) + numpy_integer_types
2229
from functools import reduce

zarr/tests/test_core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ def test_array_1d(self):
130130
# single item
131131
eq(a[0], z[0])
132132
eq(a[-1], z[-1])
133+
# unusual integer items
134+
eq(a[42], z[np.int64(42)])
135+
eq(a[42], z[np.int32(42)])
136+
eq(a[42], z[np.uint64(42)])
137+
eq(a[42], z[np.uint32(42)])
133138

134139
# check partial assignment
135140
b = np.arange(1e5, 2e5)

0 commit comments

Comments
 (0)