Skip to content

Commit be29d36

Browse files
jakirkhamjrbourbeau
authored andcommitted
Ensure contiguous data using astype (#513)
Previously we were calling `ascontiguousarray` and `asfortranarray` based on whether we wanted a C or Fortran ordered array. However we can simplify this by using `astype` to capture both cases. Additionally those functions ensure the array is at least 1-D, but that doesn't seem to matter for this use case since the scalar case is handled in a different branch. So we leave that part out.
1 parent 359f1cb commit be29d36

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Upcoming Release
4343
* Use ``ensure_ndarray`` in a few more places.
4444
By :user:`John Kirkham <jakirkham>`; :issue:`506`.
4545

46+
* Ensure contiguous data using ``astype``.
47+
By :user:`John Kirkham <jakirkham>`; :issue:`513`.
48+
4649
* Refactor out ``_tofile``/``_fromfile`` from ``DirectoryStore``.
4750
By :user:`John Kirkham <jakirkham>`; :issue:`503`.
4851

zarr/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,10 +1684,7 @@ def _chunk_setitem_nosync(self, chunk_coords, chunk_selection, value, fields=Non
16841684
else:
16851685

16861686
# ensure array is contiguous
1687-
if self._order == 'F':
1688-
chunk = np.asfortranarray(value, dtype=self._dtype)
1689-
else:
1690-
chunk = np.ascontiguousarray(value, dtype=self._dtype)
1687+
chunk = value.astype(self._dtype, order=self._order, copy=False)
16911688

16921689
else:
16931690
# partially replace the contents of this chunk

0 commit comments

Comments
 (0)