Skip to content

Commit c3b5ead

Browse files
andersy005Illviljandcherianpre-commit-ci[bot]shoyer
authored
initial refactor for NamedArray (#8075)
* initial prototype for NamedArray * move NDArrayMixin and NdimSizeLenMixin inside named_array * vendor is_duck_dask_array * vendor Frozen object * update import * move _default sentinel value * rename subpackage to namedarray per @TomNicholas suggestion * Remove NdimSizeLenMixin * fix typing * add annotations * Remove NDArrayMixin * Apply suggestions from code review Co-authored-by: Illviljan <[email protected]> * fix typing * fix return type * revert NDArrayMixin * [WIP] as_compatible_data refactor * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * duplicate sentinel value and leave the original sentinel object alone * Apply suggestions from code review Co-authored-by: Stephan Hoyer <[email protected]> * use DuckArray * Apply suggestions from code review Co-authored-by: Stephan Hoyer <[email protected]> * use sentinel value from xarray * remove unused code * fix variable constructor * fix as_compatible_data utility function * move _to_dense and _non_zero to NamedArray * more typing * add initial tests * Apply suggestions from code review Co-authored-by: Illviljan <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * attempt to fix some mypy errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update core.py * All input data can be arraylike * Update core.py * Update core.py * get and set attrs at the same level. * data doesn't have to be ndarray * avoid redefining typing use new variable names instead * import on runtime as well to be able to cast * requires ufunc and function to be a valid duck array * Add array_namespace * Update test_dataset.py * Update test_dataset.py * remove Frozen * update tests * update tests * switch to functional API * add fastpath * Test making sizes dict[Hashable, int] * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * A lot of errors... Try Mapping instead * Update groupby.py * Update types.py * Apply suggestions from code review Co-authored-by: Illviljan <[email protected]> Co-authored-by: Deepak Cherian <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update docstrings * update error messages * update tests * test explicitly index array * update tests * remove unused types * Update xarray/tests/test_namedarray.py Co-authored-by: Illviljan <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use Self --------- Co-authored-by: Illviljan <[email protected]> Co-authored-by: dcherian <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Stephan Hoyer <[email protected]> Co-authored-by: Deepak Cherian <[email protected]>
1 parent 84f5a0d commit c3b5ead

File tree

10 files changed

+700
-293
lines changed

10 files changed

+700
-293
lines changed

xarray/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _get_axis_num(self: Any, dim: Hashable) -> int:
223223
raise ValueError(f"{dim!r} not found in array dimensions {self.dims!r}")
224224

225225
@property
226-
def sizes(self: Any) -> Frozen[Hashable, int]:
226+
def sizes(self: Any) -> Mapping[Hashable, int]:
227227
"""Ordered mapping from dimension names to lengths.
228228
229229
Immutable.

xarray/core/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class GroupBy(Generic[T_Xarray]):
699699

700700
_groups: dict[GroupKey, GroupIndex] | None
701701
_dims: tuple[Hashable, ...] | Frozen[Hashable, int] | None
702-
_sizes: Frozen[Hashable, int] | None
702+
_sizes: Mapping[Hashable, int] | None
703703

704704
def __init__(
705705
self,
@@ -746,7 +746,7 @@ def __init__(
746746
self._sizes = None
747747

748748
@property
749-
def sizes(self) -> Frozen[Hashable, int]:
749+
def sizes(self) -> Mapping[Hashable, int]:
750750
"""Ordered mapping from dimension names to lengths.
751751
752752
Immutable.

xarray/core/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def dims(self) -> Frozen[Hashable, int] | tuple[Hashable, ...]:
106106
...
107107

108108
@property
109-
def sizes(self) -> Frozen[Hashable, int]:
109+
def sizes(self) -> Mapping[Hashable, int]:
110110
...
111111

112112
@property

0 commit comments

Comments
 (0)