From 8aa8e9e72e85c11cbd83e4508806d68c9362ac23 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Mon, 18 Nov 2024 13:13:03 +0100 Subject: [PATCH 1/4] array name is not nullable --- src/zarr/core/array.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 249168723f..1e815d4d0e 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -810,7 +810,7 @@ def path(self) -> str: return self.store_path.path @property - def name(self) -> str | None: + def name(self) -> str: """Array name following h5py convention. Returns @@ -818,16 +818,14 @@ def name(self) -> str | None: str The name of the array. """ - if self.path: - # follow h5py convention: add leading slash - name = self.path - if name[0] != "/": - name = "/" + name - return name - return None + # follow h5py convention: add leading slash + name = self.path + if not name.startswith("/"): + name = "/" + name + return name @property - def basename(self) -> str | None: + def basename(self) -> str: """Final component of name. Returns @@ -835,9 +833,7 @@ def basename(self) -> str | None: str The basename or final component of the array name. """ - if self.name is not None: - return self.name.split("/")[-1] - return None + return self.name.split("/")[-1] @property def cdata_shape(self) -> ChunkCoords: @@ -1626,8 +1622,7 @@ def path(self) -> str: return self._async_array.path @property - def name(self) -> str | None: - """Array name following h5py convention.""" + def name(self) -> str: return self._async_array.name @property From d396ffef63439829369bc040e8c1ab7ce24f16fc Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Mon, 18 Nov 2024 13:13:17 +0100 Subject: [PATCH 2/4] alter test for nullable array name --- tests/test_array.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_array.py b/tests/test_array.py index 975873053d..f0f36cf70d 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -122,8 +122,8 @@ def test_array_name_properties_no_group( ) -> None: arr = Array.create(store=store, shape=(100,), chunks=(10,), zarr_format=zarr_format, dtype="i4") assert arr.path == "" - assert arr.name is None - assert arr.basename is None + assert arr.name == "/" + assert arr.basename == "" @pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) From 1cd2390c649e46f9e2935f987df9e87eaa112af6 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Mon, 18 Nov 2024 16:51:38 +0100 Subject: [PATCH 3/4] assert a.name is not None --- src/zarr/testing/strategies.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zarr/testing/strategies.py b/src/zarr/testing/strategies.py index aed5b82e57..aaa0a36cbb 100644 --- a/src/zarr/testing/strategies.py +++ b/src/zarr/testing/strategies.py @@ -153,6 +153,7 @@ def arrays( assert isinstance(a, Array) if a.metadata.zarr_format == 3: assert a.fill_value is not None + assert a.name is not None assert isinstance(root[array_path], Array) assert nparray.shape == a.shape assert chunks == a.chunks From 87543868f5277853564f293243a3b65a2c1a8e0b Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Mon, 18 Nov 2024 16:53:27 +0100 Subject: [PATCH 4/4] assert a.name is not None, outside of the conditional --- src/zarr/testing/strategies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zarr/testing/strategies.py b/src/zarr/testing/strategies.py index aaa0a36cbb..f0a7e97d3a 100644 --- a/src/zarr/testing/strategies.py +++ b/src/zarr/testing/strategies.py @@ -153,7 +153,7 @@ def arrays( assert isinstance(a, Array) if a.metadata.zarr_format == 3: assert a.fill_value is not None - assert a.name is not None + assert a.name is not None assert isinstance(root[array_path], Array) assert nparray.shape == a.shape assert chunks == a.chunks