Skip to content

Commit 635a35f

Browse files
committed
fixes doctests
1 parent 3bf61c5 commit 635a35f

File tree

7 files changed

+44
-30
lines changed

7 files changed

+44
-30
lines changed

docs/user-guide/arrays.rst

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ argument accepted by all array creation functions. For example::
168168
>>> data = np.arange(100000000, dtype='int32').reshape(10000, 10000)
169169
>>> z = zarr.create_array(store='data/example-5.zarr', shape=data.shape, dtype=data.dtype, chunks=(1000, 1000), compressors=compressors)
170170
>>> z[:] = data
171-
>>> z.metadata.codecs
172-
[BytesCodec(endian=<Endian.little: 'little'>), BloscCodec(typesize=4, cname=<BloscCname.zstd: 'zstd'>, clevel=3, shuffle=<BloscShuffle.bitshuffle: 'bitshuffle'>, blocksize=0)]
171+
>>> z.compressors
172+
(BloscCodec(typesize=4, cname=<BloscCname.zstd: 'zstd'>, clevel=3, shuffle=<BloscShuffle.bitshuffle: 'bitshuffle'>, blocksize=0),)
173173

174174
This array above will use Blosc as the primary compressor, using the Zstandard
175175
algorithm (compression level 3) internally within Blosc, and with the
@@ -188,7 +188,8 @@ which can be used to print useful diagnostics, e.g.::
188188
Order : C
189189
Read-only : False
190190
Store type : LocalStore
191-
Codecs : [{'endian': <Endian.little: 'little'>}, {'typesize': 4, 'cname': <BloscCname.zstd: 'zstd'>, 'clevel': 3, 'shuffle': <BloscShuffle.bitshuffle: 'bitshuffle'>, 'blocksize': 0}]
191+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
192+
Compressors : (BloscCodec(typesize=4, cname=<BloscCname.zstd: 'zstd'>, clevel=3, shuffle=<BloscShuffle.bitshuffle: 'bitshuffle'>, blocksize=0),)
192193
No. bytes : 400000000 (381.5M)
193194

194195
The :func:`zarr.Array.info_complete` method inspects the underlying store and
@@ -203,7 +204,8 @@ prints additional diagnostics, e.g.::
203204
Order : C
204205
Read-only : False
205206
Store type : LocalStore
206-
Codecs : [{'endian': <Endian.little: 'little'>}, {'typesize': 4, 'cname': <BloscCname.zstd: 'zstd'>, 'clevel': 3, 'shuffle': <BloscShuffle.bitshuffle: 'bitshuffle'>, 'blocksize': 0}]
207+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
208+
Compressors : (BloscCodec(typesize=4, cname=<BloscCname.zstd: 'zstd'>, clevel=3, shuffle=<BloscShuffle.bitshuffle: 'bitshuffle'>, blocksize=0),)
207209
No. bytes : 400000000 (381.5M)
208210
No. bytes stored : 9696302
209211
Storage ratio : 41.3
@@ -223,8 +225,8 @@ here is an array using Gzip compression, level 1::
223225
>>> data = np.arange(100000000, dtype='int32').reshape(10000, 10000)
224226
>>> z = zarr.create_array(store='data/example-6.zarr', shape=data.shape, dtype=data.dtype, chunks=(1000, 1000), compressors=zarr.codecs.GzipCodec(level=1))
225227
>>> z[:] = data
226-
>>> z.metadata.codecs
227-
[BytesCodec(endian=<Endian.little: 'little'>), GzipCodec(level=1)]
228+
>>> z.compressors
229+
(GzipCodec(level=1),)
228230

229231
Here is an example using LZMA from NumCodecs_ with a custom filter pipeline including LZMA's
230232
built-in delta filter::
@@ -236,23 +238,24 @@ built-in delta filter::
236238
>>> compressors = LZMA(filters=lzma_filters)
237239
>>> data = np.arange(100000000, dtype='int32').reshape(10000, 10000)
238240
>>> z = zarr.create_array(store='data/example-7.zarr', shape=data.shape, dtype=data.dtype, chunks=(1000, 1000), compressors=compressors)
239-
>>> z.metadata.codecs
240-
[BytesCodec(endian=<Endian.little: 'little'>), _make_bytes_bytes_codec.<locals>._Codec(codec_name='numcodecs.lzma', codec_config={'id': 'lzma', 'filters': [{'id': 3, 'dist': 4}, {'id': 33, 'preset': 1}]})]
241+
>>> z.compressors
242+
(LZMA(codec_name='numcodecs.lzma', codec_config={'id': 'lzma', 'filters': [{'id': 3, 'dist': 4}, {'id': 33, 'preset': 1}]}),)
241243

242244
The default compressor can be changed by setting the value of the using Zarr's
243245
:ref:`user-guide-config`, e.g.::
244246

245247
>>> with zarr.config.set({'array.v2_default_compressor.numeric': {'id': 'blosc'}}):
246248
... z = zarr.create_array(store={}, shape=(100000000,), chunks=(1000000,), dtype='int32', zarr_format=2)
247-
>>> z.metadata.filters
248-
>>> z.metadata.compressor
249-
Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
249+
>>> z.filters
250+
()
251+
>>> z.compressors
252+
(Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0),)
250253

251254
To disable compression, set ``compressors=None`` when creating an array, e.g.::
252255

253256
>>> z = zarr.create_array(store='data/example-8.zarr', shape=(100000000,), chunks=(1000000,), dtype='int32', compressors=None)
254-
>>> z.metadata.codecs
255-
[BytesCodec(endian=<Endian.little: 'little'>)]
257+
>>> z.compressors
258+
()
256259

257260
.. _user-guide-filters:
258261

@@ -287,7 +290,9 @@ Here is an example using a delta filter with the Blosc compressor::
287290
Order : C
288291
Read-only : False
289292
Store type : LocalStore
290-
Codecs : [{'codec_name': 'numcodecs.delta', 'codec_config': {'id': 'delta', 'dtype': 'int32'}}, {'endian': <Endian.little: 'little'>}, {'typesize': 4, 'cname': <BloscCname.zstd: 'zstd'>, 'clevel': 1, 'shuffle': <BloscShuffle.shuffle: 'shuffle'>, 'blocksize': 0}]
293+
Filters : (Delta(codec_name='numcodecs.delta', codec_config={'id': 'delta', 'dtype': 'int32'}),)
294+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
295+
Compressors : (BloscCodec(typesize=4, cname=<BloscCname.zstd: 'zstd'>, clevel=1, shuffle=<BloscShuffle.shuffle: 'shuffle'>, blocksize=0),)
291296
No. bytes : 400000000 (381.5M)
292297

293298
For more information about available filter codecs, see the `Numcodecs
@@ -600,11 +605,12 @@ Sharded arrays can be created by providing the ``shards`` parameter to :func:`za
600605
Order : C
601606
Read-only : False
602607
Store type : LocalStore
603-
Codecs : [{'chunk_shape': (100, 100), 'codecs': ({'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}), 'index_codecs': ({'endian': <Endian.little: 'little'>}, {}), 'index_location': <ShardingCodecIndexLocation.end: 'end'>}]
608+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
609+
Compressors : (ZstdCodec(level=0, checksum=False),)
604610
No. bytes : 100000000 (95.4M)
605611
No. bytes stored : 3981060
606612
Storage ratio : 25.1
607-
Chunks Initialized : 100
613+
Shards Initialized : 100
608614

609615
In this example a shard shape of (1000, 1000) and a chunk shape of (100, 100) is used.
610616
This means that 10*10 chunks are stored in each shard, and there are 10*10 shards in total.

docs/user-guide/consolidated_metadata.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ that can be used.:
5252
chunk_key_encoding=DefaultChunkKeyEncoding(name='default',
5353
separator='/'),
5454
fill_value=np.float64(0.0),
55-
codecs=[BytesCodec(endian=<Endian.little: 'little'>),
56-
ZstdCodec(level=0, checksum=False)],
55+
codecs=(BytesCodec(endian=<Endian.little: 'little'>),
56+
ZstdCodec(level=0, checksum=False)),
5757
attributes={},
5858
dimension_names=None,
5959
zarr_format=3,
@@ -65,8 +65,8 @@ that can be used.:
6565
chunk_key_encoding=DefaultChunkKeyEncoding(name='default',
6666
separator='/'),
6767
fill_value=np.float64(0.0),
68-
codecs=[BytesCodec(endian=<Endian.little: 'little'>),
69-
ZstdCodec(level=0, checksum=False)],
68+
codecs=(BytesCodec(endian=<Endian.little: 'little'>),
69+
ZstdCodec(level=0, checksum=False)),
7070
attributes={},
7171
dimension_names=None,
7272
zarr_format=3,
@@ -78,8 +78,8 @@ that can be used.:
7878
chunk_key_encoding=DefaultChunkKeyEncoding(name='default',
7979
separator='/'),
8080
fill_value=np.float64(0.0),
81-
codecs=[BytesCodec(endian=<Endian.little: 'little'>),
82-
ZstdCodec(level=0, checksum=False)],
81+
codecs=(BytesCodec(endian=<Endian.little: 'little'>),
82+
ZstdCodec(level=0, checksum=False)),
8383
attributes={},
8484
dimension_names=None,
8585
zarr_format=3,

docs/user-guide/groups.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ property. E.g.::
109109
Order : C
110110
Read-only : False
111111
Store type : MemoryStore
112-
Codecs : [{'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}]
112+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
113+
Compressors : (ZstdCodec(level=0, checksum=False),)
113114
No. bytes : 8000000 (7.6M)
114115
No. bytes stored : 1432
115116
Storage ratio : 5586.6
@@ -123,7 +124,8 @@ property. E.g.::
123124
Order : C
124125
Read-only : False
125126
Store type : MemoryStore
126-
Codecs : [{'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}]
127+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
128+
Compressors : (ZstdCodec(level=0, checksum=False),)
127129
No. bytes : 4000000 (3.8M)
128130

129131
Groups also have the :func:`zarr.Group.tree` method, e.g.::

docs/user-guide/performance.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ To use sharding, you need to specify the ``shards`` parameter when creating the
9898
Order : C
9999
Read-only : False
100100
Store type : MemoryStore
101-
Codecs : [{'chunk_shape': (100, 100, 100), 'codecs': ({'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}), 'index_codecs': ({'endian': <Endian.little: 'little'>}, {}), 'index_location': <ShardingCodecIndexLocation.end: 'end'>}]
101+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
102+
Compressors : (ZstdCodec(level=0, checksum=False),)
102103
No. bytes : 100000000000 (93.1G)
103104

104105
.. _user-guide-chunks-order:
@@ -125,7 +126,8 @@ ratios, depending on the correlation structure within the data. E.g.::
125126
Order : C
126127
Read-only : False
127128
Store type : MemoryStore
128-
Codecs : [{'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}]
129+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
130+
Compressors : (ZstdCodec(level=0, checksum=False),)
129131
No. bytes : 400000000 (381.5M)
130132
No. bytes stored : 342588717
131133
Storage ratio : 1.2
@@ -142,7 +144,8 @@ ratios, depending on the correlation structure within the data. E.g.::
142144
Order : F
143145
Read-only : False
144146
Store type : MemoryStore
145-
Codecs : [{'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}]
147+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
148+
Compressors : (ZstdCodec(level=0, checksum=False),)
146149
No. bytes : 400000000 (381.5M)
147150
No. bytes stored : 342588717
148151
Storage ratio : 1.2

src/zarr/core/_info.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ def __repr__(self) -> str:
109109
Read-only : {_read_only}
110110
Store type : {_store_type}""")
111111

112-
kwargs = dataclasses.asdict(self)
112+
# We can't use dataclasses.asdict, because we only want a shallow dict
113+
kwargs = {field.name: getattr(self, field.name) for field in dataclasses.fields(self)}
114+
113115
if self._chunk_shape is None:
114116
# for non-regular chunk grids
115117
kwargs["chunk_shape"] = "<variable>"

src/zarr/core/array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ def _info(
16241624
_data_type = self.metadata.dtype
16251625
else:
16261626
_data_type = self.metadata.data_type
1627+
16271628
return ArrayInfo(
16281629
_zarr_format=self.metadata.zarr_format,
16291630
_data_type=_data_type,

tests/test_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_array_info(zarr_format: ZarrFormat) -> None:
7171
Order : C
7272
Read-only : True
7373
Store type : MemoryStore
74-
Serializer : {{'endian': <Endian.little: 'little'>}}""")
74+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)""")
7575

7676

7777
@pytest.mark.parametrize("zarr_format", ZARR_FORMATS)
@@ -110,7 +110,7 @@ def test_array_info_complete(
110110
Order : C
111111
Read-only : True
112112
Store type : MemoryStore
113-
Serializer : {{'endian': <Endian.little: 'little'>}}
113+
Serializer : BytesCodec(endian=<Endian.little: 'little'>)
114114
No. bytes : {count_bytes} ({count_bytes_formatted})
115115
No. bytes stored : {count_bytes_stored_formatted}
116116
Storage ratio : {storage_ratio_formatted}

0 commit comments

Comments
 (0)