Skip to content

Commit

Permalink
Ensure contiguous data using astype (zarr-developers#513)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jakirkham authored and jrbourbeau committed Nov 15, 2019
1 parent 359f1cb commit be29d36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Upcoming Release
* Use ``ensure_ndarray`` in a few more places.
By :user:`John Kirkham <jakirkham>`; :issue:`506`.

* Ensure contiguous data using ``astype``.
By :user:`John Kirkham <jakirkham>`; :issue:`513`.

* Refactor out ``_tofile``/``_fromfile`` from ``DirectoryStore``.
By :user:`John Kirkham <jakirkham>`; :issue:`503`.

Expand Down
5 changes: 1 addition & 4 deletions zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,10 +1684,7 @@ def _chunk_setitem_nosync(self, chunk_coords, chunk_selection, value, fields=Non
else:

# ensure array is contiguous
if self._order == 'F':
chunk = np.asfortranarray(value, dtype=self._dtype)
else:
chunk = np.ascontiguousarray(value, dtype=self._dtype)
chunk = value.astype(self._dtype, order=self._order, copy=False)

else:
# partially replace the contents of this chunk
Expand Down

0 comments on commit be29d36

Please sign in to comment.