Skip to content

Commit 2361cd7

Browse files
authored
add fill_value output to info (#3081)
* add fill_value output to info * changelog * fix tests * fix example in docs
1 parent f674236 commit 2361cd7

File tree

8 files changed

+24
-1
lines changed

8 files changed

+24
-1
lines changed

changes/3081.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adds ``fill_value`` to the list of attributes displayed in the output of the ``AsyncArray.info()`` method.

docs/user-guide/arrays.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ which can be used to print useful diagnostics, e.g.::
183183
Type : Array
184184
Zarr format : 3
185185
Data type : DataType.int32
186+
Fill value : 0
186187
Shape : (10000, 10000)
187188
Chunk shape : (1000, 1000)
188189
Order : C
@@ -200,6 +201,7 @@ prints additional diagnostics, e.g.::
200201
Type : Array
201202
Zarr format : 3
202203
Data type : DataType.int32
204+
Fill value : 0
203205
Shape : (10000, 10000)
204206
Chunk shape : (1000, 1000)
205207
Order : C
@@ -287,6 +289,7 @@ Here is an example using a delta filter with the Blosc compressor::
287289
Type : Array
288290
Zarr format : 3
289291
Data type : DataType.int32
292+
Fill value : 0
290293
Shape : (10000, 10000)
291294
Chunk shape : (1000, 1000)
292295
Order : C
@@ -601,6 +604,7 @@ Sharded arrays can be created by providing the ``shards`` parameter to :func:`za
601604
Type : Array
602605
Zarr format : 3
603606
Data type : DataType.uint8
607+
Fill value : 0
604608
Shape : (10000, 10000)
605609
Shard shape : (1000, 1000)
606610
Chunk shape : (100, 100)

docs/user-guide/groups.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ property. E.g.::
129129
Type : Array
130130
Zarr format : 3
131131
Data type : DataType.int64
132+
Fill value : 0
132133
Shape : (1000000,)
133134
Chunk shape : (100000,)
134135
Order : C
@@ -145,6 +146,7 @@ property. E.g.::
145146
Type : Array
146147
Zarr format : 3
147148
Data type : DataType.float32
149+
Fill value : 0.0
148150
Shape : (1000, 1000)
149151
Chunk shape : (100, 100)
150152
Order : C

docs/user-guide/performance.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ To use sharding, you need to specify the ``shards`` parameter when creating the
9292
Type : Array
9393
Zarr format : 3
9494
Data type : DataType.uint8
95+
Fill value : 0
9596
Shape : (10000, 10000, 1000)
9697
Shard shape : (1000, 1000, 1000)
9798
Chunk shape : (100, 100, 100)
@@ -122,6 +123,7 @@ ratios, depending on the correlation structure within the data. E.g.::
122123
Type : Array
123124
Zarr format : 3
124125
Data type : DataType.int32
126+
Fill value : 0
125127
Shape : (10000, 10000)
126128
Chunk shape : (1000, 1000)
127129
Order : C
@@ -141,6 +143,7 @@ ratios, depending on the correlation structure within the data. E.g.::
141143
Type : Array
142144
Zarr format : 3
143145
Data type : DataType.int32
146+
Fill value : 0
144147
Shape : (10000, 10000)
145148
Chunk shape : (1000, 1000)
146149
Order : F

src/zarr/core/_info.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def byte_info(size: int) -> str:
6767
return f"{size} ({human_readable_size(size)})"
6868

6969

70-
@dataclasses.dataclass(kw_only=True)
70+
@dataclasses.dataclass(kw_only=True, frozen=True, slots=True)
7171
class ArrayInfo:
7272
"""
7373
Visual summary for an Array.
@@ -79,6 +79,7 @@ class ArrayInfo:
7979
_type: Literal["Array"] = "Array"
8080
_zarr_format: ZarrFormat
8181
_data_type: np.dtype[Any] | DataType
82+
_fill_value: object
8283
_shape: tuple[int, ...]
8384
_shard_shape: tuple[int, ...] | None = None
8485
_chunk_shape: tuple[int, ...] | None = None
@@ -97,6 +98,7 @@ def __repr__(self) -> str:
9798
Type : {_type}
9899
Zarr format : {_zarr_format}
99100
Data type : {_data_type}
101+
Fill value : {_fill_value}
100102
Shape : {_shape}""")
101103

102104
if self._shard_shape is not None:

src/zarr/core/array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ def _info(
17021702
return ArrayInfo(
17031703
_zarr_format=self.metadata.zarr_format,
17041704
_data_type=_data_type,
1705+
_fill_value=self.metadata.fill_value,
17051706
_shape=self.shape,
17061707
_order=self.order,
17071708
_shard_shape=self.shards,

tests/test_array.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ def test_info_v2(self, chunks: tuple[int, int], shards: tuple[int, int] | None)
522522
expected = ArrayInfo(
523523
_zarr_format=2,
524524
_data_type=np.dtype("float64"),
525+
_fill_value=arr.fill_value,
525526
_shape=(8, 8),
526527
_chunk_shape=chunks,
527528
_shard_shape=None,
@@ -539,6 +540,7 @@ def test_info_v3(self, chunks: tuple[int, int], shards: tuple[int, int] | None)
539540
expected = ArrayInfo(
540541
_zarr_format=3,
541542
_data_type=DataType.parse("float64"),
543+
_fill_value=arr.fill_value,
542544
_shape=(8, 8),
543545
_chunk_shape=chunks,
544546
_shard_shape=shards,
@@ -564,6 +566,7 @@ def test_info_complete(self, chunks: tuple[int, int], shards: tuple[int, int] |
564566
expected = ArrayInfo(
565567
_zarr_format=3,
566568
_data_type=DataType.parse("float64"),
569+
_fill_value=arr.fill_value,
567570
_shape=(8, 8),
568571
_chunk_shape=chunks,
569572
_shard_shape=shards,
@@ -599,6 +602,7 @@ async def test_info_v2_async(
599602
expected = ArrayInfo(
600603
_zarr_format=2,
601604
_data_type=np.dtype("float64"),
605+
_fill_value=arr.metadata.fill_value,
602606
_shape=(8, 8),
603607
_chunk_shape=(2, 2),
604608
_shard_shape=None,
@@ -624,6 +628,7 @@ async def test_info_v3_async(
624628
expected = ArrayInfo(
625629
_zarr_format=3,
626630
_data_type=DataType.parse("float64"),
631+
_fill_value=arr.metadata.fill_value,
627632
_shape=(8, 8),
628633
_chunk_shape=chunks,
629634
_shard_shape=shards,
@@ -651,6 +656,7 @@ async def test_info_complete_async(
651656
expected = ArrayInfo(
652657
_zarr_format=3,
653658
_data_type=DataType.parse("float64"),
659+
_fill_value=arr.metadata.fill_value,
654660
_shape=(8, 8),
655661
_chunk_shape=chunks,
656662
_shard_shape=shards,

tests/test_info.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_array_info(zarr_format: ZarrFormat) -> None:
5454
info = ArrayInfo(
5555
_zarr_format=zarr_format,
5656
_data_type=np.dtype("int32"),
57+
_fill_value=0,
5758
_shape=(100, 100),
5859
_chunk_shape=(10, 100),
5960
_order="C",
@@ -66,6 +67,7 @@ def test_array_info(zarr_format: ZarrFormat) -> None:
6667
Type : Array
6768
Zarr format : {zarr_format}
6869
Data type : int32
70+
Fill value : 0
6971
Shape : (100, 100)
7072
Chunk shape : (10, 100)
7173
Order : C
@@ -92,6 +94,7 @@ def test_array_info_complete(
9294
info = ArrayInfo(
9395
_zarr_format=zarr_format,
9496
_data_type=np.dtype("int32"),
97+
_fill_value=0,
9598
_shape=(100, 100),
9699
_chunk_shape=(10, 100),
97100
_order="C",
@@ -107,6 +110,7 @@ def test_array_info_complete(
107110
Type : Array
108111
Zarr format : {zarr_format}
109112
Data type : int32
113+
Fill value : 0
110114
Shape : (100, 100)
111115
Chunk shape : (10, 100)
112116
Order : C

0 commit comments

Comments
 (0)