Skip to content

Commit fa32f1e

Browse files
authored
Merge pull request #147 from alimanfoo/issue_143
Test and fix for #143 index with numpy integer item
2 parents 07eb69e + 17cb751 commit fa32f1e

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@ branches:
66

77
sudo: false
88

9-
addons:
10-
apt:
11-
packages:
12-
- liblzma-dev
13-
149
python:
1510
- 2.7
1611
- 3.4
1712
- 3.5
1813
- 3.6
1914

2015
install:
21-
- pip install -U tox-travis coveralls pip setuptools wheel
22-
- pip install -r requirements_dev.txt
23-
- python setup.py build_ext --inplace
16+
- pip install -U pip setuptools wheel
17+
- pip install -U tox-travis coveralls
2418

2519
script:
2620
- tox

zarr/compat.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
text_type = unicode
1313
binary_type = str
14-
integer_types = (int, long)
1514
reduce = reduce
1615

1716
else:
1817

1918
text_type = str
2019
binary_type = bytes
21-
integer_types = int,
2220
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)

zarr/util.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from __future__ import absolute_import, print_function, division
33
import operator
44
from textwrap import TextWrapper
5+
import numbers
56

67

78
import numpy as np
89

910

10-
from zarr.compat import integer_types, PY2, reduce
11+
from zarr.compat import PY2, reduce
1112

1213

1314
def normalize_shape(shape):
@@ -17,7 +18,7 @@ def normalize_shape(shape):
1718
raise TypeError('shape is None')
1819

1920
# handle 1D convenience form
20-
if isinstance(shape, integer_types):
21+
if isinstance(shape, numbers.Integral):
2122
shape = (int(shape),)
2223

2324
# normalize
@@ -89,7 +90,7 @@ def normalize_chunks(chunks, shape, typesize):
8990
return guess_chunks(shape, typesize)
9091

9192
# handle 1D convenience form
92-
if isinstance(chunks, integer_types):
93+
if isinstance(chunks, numbers.Integral):
9394
chunks = (int(chunks),)
9495

9596
# handle bad dimensionality
@@ -137,7 +138,8 @@ def normalize_axis_selection(item, length):
137138
"""Convenience function to normalize a selection within a single axis
138139
of size `l`."""
139140

140-
if isinstance(item, int):
141+
if isinstance(item, numbers.Integral):
142+
item = int(item)
141143

142144
# handle wraparound
143145
if item < 0:
@@ -191,7 +193,7 @@ def normalize_array_selection(item, shape):
191193
the given `shape`."""
192194

193195
# normalize item
194-
if isinstance(item, integer_types):
196+
if isinstance(item, numbers.Integral):
195197
item = (int(item),)
196198
elif isinstance(item, slice):
197199
item = (item,)

0 commit comments

Comments
 (0)