Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return scalar when accessing zero dimensional array #2718

Open
wants to merge 69 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
a9531ca
Return scalar when accessing zero dimensional array
brokkoli71 Jan 15, 2025
1a290c7
returning npt.ArrayLike instead of NDArrayLike because of scalar retu…
brokkoli71 Jan 15, 2025
3348439
returning npt.ArrayLike instead of NDArrayLike because of scalar retu…
brokkoli71 Jan 15, 2025
34bf260
fix mypy in tests
brokkoli71 Jan 16, 2025
75d6cdf
fix mypy in tests
brokkoli71 Jan 16, 2025
66c0798
fix mypy in tests
brokkoli71 Jan 16, 2025
a86d041
improve test_scalar_array
brokkoli71 Jan 23, 2025
f8393b0
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Jan 29, 2025
c2a0de0
fix typo
brokkoli71 Jan 29, 2025
2475960
add ScalarWrapper
brokkoli71 Jan 29, 2025
cced470
use ScalarWrapper as NDArrayLike
brokkoli71 Jan 29, 2025
d57e1f2
Revert "fix mypy in tests"
brokkoli71 Jan 29, 2025
842bf95
Revert "fix mypy in tests"
brokkoli71 Jan 29, 2025
ee6d62d
Revert "fix mypy in tests"
brokkoli71 Jan 29, 2025
e302ae6
format
brokkoli71 Jan 29, 2025
b55c8b3
Revert "returning npt.ArrayLike instead of NDArrayLike because of sca…
brokkoli71 Jan 29, 2025
f1cb6e1
Revert "returning npt.ArrayLike instead of NDArrayLike because of sca…
brokkoli71 Jan 29, 2025
c76be48
fix mypy for ScalarWrapper
brokkoli71 Jan 29, 2025
359eb66
add missing import NDArrayLike
brokkoli71 Jan 29, 2025
fc0937e
ignore unavoidable mypy error
brokkoli71 Jan 29, 2025
8454d7b
format
brokkoli71 Jan 29, 2025
15c5103
fix __array__
brokkoli71 Jan 29, 2025
a93ce00
extend tests
brokkoli71 Jan 29, 2025
805a8df
format
brokkoli71 Jan 29, 2025
f6b48ba
fix typing in test_scalar_array
brokkoli71 Jan 29, 2025
1b7966f
add dtype to ScalarWrapper
brokkoli71 Jan 29, 2025
81ab808
correct dtype type
brokkoli71 Jan 29, 2025
56c52ae
fix test_basic_indexing
brokkoli71 Jan 29, 2025
a3473fb
fix test_basic_indexing
brokkoli71 Jan 29, 2025
b98578b
Merge remote-tracking branch 'origin/return-scalar-for-zero-dim-index…
brokkoli71 Jan 29, 2025
c150462
fix test_basic_indexing for dtype=datetime64[Y]
brokkoli71 Jan 29, 2025
a7d4421
increase codecov
brokkoli71 Jan 29, 2025
632cad0
fix typing
brokkoli71 Jan 29, 2025
50fd5ff
document changes
brokkoli71 Jan 29, 2025
2aca6c2
move test_scalar_wrapper to test_buffer.py
brokkoli71 Jan 29, 2025
15ec284
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Jan 30, 2025
a842e88
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 1, 2025
e0ef9b1
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 5, 2025
24ed5c2
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 9, 2025
ab7afbb
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 11, 2025
98e13a8
remove ScalarWrapper usage
brokkoli71 Feb 12, 2025
862481a
Merge branch 'refs/heads/main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 12, 2025
888304a
create NDArrayOrScalarLike
brokkoli71 Feb 12, 2025
422e0d8
fix NDArrayOrScalarLike
brokkoli71 Feb 12, 2025
a9c0eab
fix mypy
brokkoli71 Feb 12, 2025
b005620
fix mypy
brokkoli71 Feb 12, 2025
9284246
fix mypy
brokkoli71 Feb 12, 2025
73c835f
fix mypy in asynchronous.py
brokkoli71 Feb 12, 2025
ada708e
fix mypy in test_api.py
brokkoli71 Feb 12, 2025
0886e77
fix mypy in test_api.py and synchronous.py
brokkoli71 Feb 12, 2025
300d03a
fix mypy in test_api.py and test_array.py
brokkoli71 Feb 12, 2025
584762b
fix mypy in test_array.py
brokkoli71 Feb 12, 2025
3835768
fix mypy in test_array.py
brokkoli71 Feb 12, 2025
363f06b
fix mypy in test_array.py
brokkoli71 Feb 12, 2025
17d4a9b
fix mypy in test_array.py
brokkoli71 Feb 12, 2025
d4b8bfb
fix mypy in test_array.py, test_api.py, test_buffer.py, test_sharding.py
brokkoli71 Feb 12, 2025
2b18ab1
add bytes, str and datetime to ScalarType
brokkoli71 Feb 12, 2025
070c673
only support numpy datetime64 in ScalarType
brokkoli71 Feb 12, 2025
655d464
remove ScalarWrapper and update changes
brokkoli71 Feb 12, 2025
f03c026
undo wrong code changes
brokkoli71 Feb 12, 2025
a557456
rename ``NDArrayOrScalarLike`` to ``NDArrayLikeOrScalar``
brokkoli71 Feb 12, 2025
b23994c
rename ``NDArrayOrScalarLike`` to ``NDArrayLikeOrScalar``
brokkoli71 Feb 15, 2025
b4c53a9
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 15, 2025
995a5d5
fix mypy in test_array.py
brokkoli71 Feb 15, 2025
8e5f47d
fix mypy in test_array.py
brokkoli71 Feb 15, 2025
b68c60e
Merge branch 'main' into return-scalar-for-zero-dim-indexing
brokkoli71 Feb 19, 2025
56d1dea
handle datetype scalars for different units
brokkoli71 Feb 19, 2025
276bdf3
fix mypy
brokkoli71 Feb 19, 2025
75a267b
fix mypy
brokkoli71 Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "returning npt.ArrayLike instead of NDArrayLike because of sca…
…lar return values"

This reverts commit 1a290c7.
brokkoli71 committed Jan 29, 2025
commit b55c8b3b3a30f04cce728add4057a6fd55de4ae0
2 changes: 1 addition & 1 deletion src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
@@ -232,7 +232,7 @@ async def load(
path: str | None = None,
zarr_format: ZarrFormat | None = None,
zarr_version: ZarrFormat | None = None,
) -> npt.ArrayLike | dict[str, npt.ArrayLike]:
) -> NDArrayLike | dict[str, NDArrayLike]:
"""Load data from an array or group into memory.
Parameters
22 changes: 11 additions & 11 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
@@ -1203,7 +1203,7 @@ async def _get_selection(
prototype: BufferPrototype,
out: NDBuffer | None = None,
fields: Fields | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
# check fields are sensible
out_dtype = check_fields(fields, self.dtype)

@@ -1253,7 +1253,7 @@ async def getitem(
selection: BasicSelection,
*,
prototype: BufferPrototype | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
"""
Asynchronous function that retrieves a subset of the array's data based on the provided selection.
@@ -1266,7 +1266,7 @@ async def getitem(
Returns
-------
npt.ArrayLike
NDArrayLike
The retrieved subset of the array's data.
Examples
@@ -2224,7 +2224,7 @@ def __array__(

return arr_np

def __getitem__(self, selection: Selection) -> npt.ArrayLike:
def __getitem__(self, selection: Selection) -> NDArrayLike:
"""Retrieve data for an item or region of the array.
Parameters
@@ -2235,7 +2235,7 @@ def __getitem__(self, selection: Selection) -> npt.ArrayLike:
Returns
-------
npt.ArrayLike
NDArrayLike
An array-like containing the data for the requested region.
Examples
@@ -2482,7 +2482,7 @@ def get_basic_selection(
out: NDBuffer | None = None,
prototype: BufferPrototype | None = None,
fields: Fields | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
"""Retrieve data for an item or region of the array.
Parameters
@@ -2702,7 +2702,7 @@ def get_orthogonal_selection(
out: NDBuffer | None = None,
fields: Fields | None = None,
prototype: BufferPrototype | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
"""Retrieve data by making a selection for each dimension of the array. For
example, if an array has 2 dimensions, allows selecting specific rows and/or
columns. The selection for each dimension can be either an integer (indexing a
@@ -2938,7 +2938,7 @@ def get_mask_selection(
out: NDBuffer | None = None,
fields: Fields | None = None,
prototype: BufferPrototype | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
"""Retrieve a selection of individual items, by providing a Boolean array of the
same shape as the array against which the selection is being made, where True
values indicate a selected item.
@@ -3100,7 +3100,7 @@ def get_coordinate_selection(
out: NDBuffer | None = None,
fields: Fields | None = None,
prototype: BufferPrototype | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
"""Retrieve a selection of individual items, by providing the indices
(coordinates) for each selected item.
@@ -3288,7 +3288,7 @@ def get_block_selection(
out: NDBuffer | None = None,
fields: Fields | None = None,
prototype: BufferPrototype | None = None,
) -> npt.ArrayLike:
) -> NDArrayLike:
"""Retrieve a selection of individual items, by providing the indices
(coordinates) for each selected item.
@@ -3306,7 +3306,7 @@ def get_block_selection(
Returns
-------
npt.ArrayLike
NDArrayLike
An array-like containing the data for the requested block selection.
Examples
6 changes: 3 additions & 3 deletions src/zarr/core/indexing.py
Original file line number Diff line number Diff line change
@@ -928,7 +928,7 @@ class OIndex:
array: Array

# TODO: develop Array generic and move zarr.Array[np.intp] | zarr.Array[np.bool_] to ArrayOfIntOrBool
def __getitem__(self, selection: OrthogonalSelection | Array) -> npt.ArrayLike:
def __getitem__(self, selection: OrthogonalSelection | Array) -> NDArrayLike:
from zarr.core.array import Array

# if input is a Zarr array, we materialize it now.
@@ -1037,7 +1037,7 @@ def __iter__(self) -> Iterator[ChunkProjection]:
class BlockIndex:
array: Array

def __getitem__(self, selection: BasicSelection) -> npt.ArrayLike:
def __getitem__(self, selection: BasicSelection) -> NDArrayLike:
fields, new_selection = pop_fields(selection)
new_selection = ensure_tuple(new_selection)
new_selection = replace_lists(new_selection)
@@ -1226,7 +1226,7 @@ class VIndex:
array: Array

# TODO: develop Array generic and move zarr.Array[np.intp] | zarr.Array[np.bool_] to ArrayOfIntOrBool
def __getitem__(self, selection: CoordinateSelection | MaskSelection | Array) -> npt.ArrayLike:
def __getitem__(self, selection: CoordinateSelection | MaskSelection | Array) -> NDArrayLike:
from zarr.core.array import Array

# if input is a Zarr array, we materialize it now.