Skip to content

Conversation

@alimanfoo
Copy link
Member

This PR provides tests and implementation of support for 0-dimensional arrays. This builds off work done in #154, however I needed to add special case implementations of __getitem__ and __setitem__ to the Array class to get indexing working with both empty tuple and ellipsis.

@alimanfoo alimanfoo added this to the v2.2 milestone Oct 24, 2017
@alimanfoo
Copy link
Member Author

OK, I think this is good to go.


else:

out = self._decode_chunk(cdata)
Copy link
Member

Choose a reason for hiding this comment

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

Minor point. This seems a bit spaced out. Not sure if that was intentional or not.

@alimanfoo
Copy link
Member Author

Behaviour should be consistent with h5py and numpy, e.g.:

>>> import zarr
>>> z = zarr.zeros(())
>>> z
<zarr.core.Array () float64>
>>> z[...]
array(0.0)
>>> z[()]
0.0
>>> z[...] = 42
>>> z[...]
array(42.0)
>>> z[()] = 43
>>> z[()]
43.0
>>> z[:]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aliman/src/github/alimanfoo/zarr/zarr/core.py", line 451, in __getitem__
    return self._getitem_zd(item)
  File "/home/aliman/src/github/alimanfoo/zarr/zarr/core.py", line 460, in _getitem_zd
    raise IndexError('too many indices for array')
IndexError: too many indices for array

eq((), z.chunks)
eq(1, z.nchunks)
# compressor always None - no point in compressing a scalar value
assert_is_none(z.compressor)
Copy link
Member

@jakirkham jakirkham Oct 24, 2017

Choose a reason for hiding this comment

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

Would it be worth checking nbytes as well or is that too far afield?

@jakirkham
Copy link
Member

Does _cdata_shape need to be updated?

@alimanfoo
Copy link
Member Author

Thanks @jakirkham, have pushed some tweaks to tests and properties.

@alimanfoo
Copy link
Member Author

Also can now set scalar on group:

>>> import zarr
>>> g = zarr.group()
>>> g['foo'] = 42
>>> g['foo']
<zarr.core.Array '/foo' () int64>
>>> g['foo'][()]
42
>>> g['bar/baz/qux'] = 123.4
>>> g['bar/baz/qux']
<zarr.core.Array '/bar/baz/qux' () float64>
>>> g['bar/baz/qux'][()]
123.40000000000001

@jakirkham
Copy link
Member

LGTM

@alimanfoo alimanfoo merged commit 0bfc30e into master Oct 25, 2017
@alimanfoo alimanfoo deleted the scalars branch October 25, 2017 21:50
@alimanfoo alimanfoo added enhancement New features or improvements release notes done Automatically applied to PRs which have release notes. labels Nov 20, 2017
@joshmoore
Copy link
Member

As a reminder to future selves, JuliaIO/Zarr.jl#117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New features or improvements release notes done Automatically applied to PRs which have release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants