Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ def __getitem__(self, key):
def __setitem__(self, key, value):
if self.mode == 'r':
raise ReadOnlyError()
value = ensure_contiguous_ndarray(value)
value = ensure_contiguous_ndarray(value).view("u1")
with self.mutex:
# writestr(key, value) writes with default permissions from
# zipfile (600) that are too restrictive, build ZipInfo for
Expand Down
7 changes: 7 additions & 0 deletions zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,13 @@ def test_permissions(self):
assert perm == '0o40775'
z.close()

def test_store_and_retrieve_ndarray(self):
store = ZipStore('data/store.zip')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure why some of these tests use data/store.zip explicitly here, but I think for your test, @orenwatson, it would be best to use the self.create_store() method so that you are testing a fresh zip, independently of other tests.

I can confirm though that this test fails without this PR and passes with it. 👍

NB: A second run with this PR raises the warning:

/usr/local/anaconda3/envs/z/lib/python3.9/zipfile.py:1505: UserWarning: Duplicate name: 'foo'
  return self._open_to_write(zinfo, force_zip64=force_zip64)

which is what makes me think that create_store would be safer.

Copy link
Member

@jakirkham jakirkham Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point Josh 👍

I think with test_permissions this is needed because the file needs to be flushed/closed and then reopened for the test (so it doesn't follow the norm). Though agree we should be able to use create_store here

Edit: As an aside I think this all precedes moving to pytest. So we can probably do some maintenance on this kind of thing to improve the ergonomics

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. If the test is passing, I say we release @orenwatson (and add a grand "Huzzah!" in thanks 🎉) and we can handle the cleanup separately.

x = np.array([[1, 2], [3, 4]])
store['foo'] = x
y = np.frombuffer(store['foo'], dtype=x.dtype).reshape(x.shape)
assert np.array_equiv(y, x)


class TestDBMStore(StoreTests):

Expand Down