Skip to content

Commit

Permalink
fix: array creation prototype (#2306)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman authored Oct 7, 2024
1 parent a24e194 commit 1674282
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
44 changes: 16 additions & 28 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,24 +768,20 @@ async def full(
)

async def empty_like(
self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any
self, *, name: str, data: async_api.ArrayLike, **kwargs: Any
) -> AsyncArray:
return await async_api.empty_like(a=prototype, store=self.store_path, path=name, **kwargs)
return await async_api.empty_like(a=data, store=self.store_path, path=name, **kwargs)

async def zeros_like(
self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any
self, *, name: str, data: async_api.ArrayLike, **kwargs: Any
) -> AsyncArray:
return await async_api.zeros_like(a=prototype, store=self.store_path, path=name, **kwargs)
return await async_api.zeros_like(a=data, store=self.store_path, path=name, **kwargs)

async def ones_like(
self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any
) -> AsyncArray:
return await async_api.ones_like(a=prototype, store=self.store_path, path=name, **kwargs)
async def ones_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> AsyncArray:
return await async_api.ones_like(a=data, store=self.store_path, path=name, **kwargs)

async def full_like(
self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any
) -> AsyncArray:
return await async_api.full_like(a=prototype, store=self.store_path, path=name, **kwargs)
async def full_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> AsyncArray:
return await async_api.full_like(a=data, store=self.store_path, path=name, **kwargs)

async def move(self, source: str, dest: str) -> None:
raise NotImplementedError
Expand Down Expand Up @@ -1171,25 +1167,17 @@ def full(
)
)

def empty_like(self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(
self._sync(self._async_group.empty_like(name=name, prototype=prototype, **kwargs))
)
def empty_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(self._sync(self._async_group.empty_like(name=name, data=data, **kwargs)))

def zeros_like(self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(
self._sync(self._async_group.zeros_like(name=name, prototype=prototype, **kwargs))
)
def zeros_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(self._sync(self._async_group.zeros_like(name=name, data=data, **kwargs)))

def ones_like(self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(
self._sync(self._async_group.ones_like(name=name, prototype=prototype, **kwargs))
)
def ones_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(self._sync(self._async_group.ones_like(name=name, data=data, **kwargs)))

def full_like(self, *, name: str, prototype: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(
self._sync(self._async_group.full_like(name=name, prototype=prototype, **kwargs))
)
def full_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
return Array(self._sync(self._async_group.full_like(name=name, data=data, **kwargs)))

def move(self, source: str, dest: str) -> None:
return self._sync(self._async_group.move(source, dest))
Expand Down
10 changes: 5 additions & 5 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def test_group_array_creation(
assert empty_array.shape == shape
assert empty_array.store_path.store == store

empty_like_array = group.empty_like(name="empty_like", prototype=empty_array)
empty_like_array = group.empty_like(name="empty_like", data=empty_array)
assert isinstance(empty_like_array, Array)
assert empty_like_array.fill_value == 0
assert empty_like_array.shape == shape
Expand All @@ -459,7 +459,7 @@ def test_group_array_creation(
assert empty_array_bool.shape == shape
assert empty_array_bool.store_path.store == store

empty_like_array_bool = group.empty_like(name="empty_like_bool", prototype=empty_array_bool)
empty_like_array_bool = group.empty_like(name="empty_like_bool", data=empty_array_bool)
assert isinstance(empty_like_array_bool, Array)
assert not empty_like_array_bool.fill_value
assert empty_like_array_bool.shape == shape
Expand All @@ -471,7 +471,7 @@ def test_group_array_creation(
assert zeros_array.shape == shape
assert zeros_array.store_path.store == store

zeros_like_array = group.zeros_like(name="zeros_like", prototype=zeros_array)
zeros_like_array = group.zeros_like(name="zeros_like", data=zeros_array)
assert isinstance(zeros_like_array, Array)
assert zeros_like_array.fill_value == 0
assert zeros_like_array.shape == shape
Expand All @@ -483,7 +483,7 @@ def test_group_array_creation(
assert ones_array.shape == shape
assert ones_array.store_path.store == store

ones_like_array = group.ones_like(name="ones_like", prototype=ones_array)
ones_like_array = group.ones_like(name="ones_like", data=ones_array)
assert isinstance(ones_like_array, Array)
assert ones_like_array.fill_value == 1
assert ones_like_array.shape == shape
Expand All @@ -495,7 +495,7 @@ def test_group_array_creation(
assert full_array.shape == shape
assert full_array.store_path.store == store

full_like_array = group.full_like(name="full_like", prototype=full_array, fill_value=43)
full_like_array = group.full_like(name="full_like", data=full_array, fill_value=43)
assert isinstance(full_like_array, Array)
assert full_like_array.fill_value == 43
assert full_like_array.shape == shape
Expand Down

0 comments on commit 1674282

Please sign in to comment.