Skip to content

Commit 80be178

Browse files
committed
test and fix for array(dtype=None); resolves #80
1 parent 6ee7da7 commit 80be178

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

zarr/creation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,20 @@ def array(data, **kwargs):
289289
data = np.asanyarray(data)
290290

291291
# setup dtype
292-
kwargs.setdefault('dtype', data.dtype)
292+
kw_dtype = kwargs.get('dtype', None)
293+
if kw_dtype is None:
294+
kwargs['dtype'] = data.dtype
295+
else:
296+
kwargs['dtype'] = kw_dtype
293297

294298
# setup shape and chunks
295-
shape, chunks = _get_shape_chunks(data)
296-
kwargs['shape'] = data.shape
297-
kwargs.setdefault('chunks', chunks)
299+
data_shape, data_chunks = _get_shape_chunks(data)
300+
kwargs['shape'] = data_shape
301+
kw_chunks = kwargs.get('chunks', None)
302+
if kw_chunks is None:
303+
kwargs['chunks'] = data_chunks
304+
else:
305+
kwargs['chunks'] = kw_chunks
298306

299307
# instantiate array
300308
z = create(**kwargs)

zarr/tests/test_creation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ def test_array():
9191
eq(c.shape, z5.shape)
9292
assert_is_instance(z5.chunks, tuple)
9393

94+
# with dtype=None
95+
a = np.arange(100, dtype='i4')
96+
z = array(a, dtype=None)
97+
assert_array_equal(a[:], z[:])
98+
eq(a.dtype, z.dtype)
99+
94100

95101
def test_empty():
96102
z = empty(100, chunks=10)

0 commit comments

Comments
 (0)