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

Add T_DuckArray to DataArray #8211

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from xarray.core.indexing import is_fancy_indexer, map_index_queries
from xarray.core.merge import PANDAS_TYPES, MergeError
from xarray.core.options import OPTIONS, _get_keep_attrs
from xarray.core.types import DaCompatible, T_DataArray, T_DataArrayOrSet
from xarray.core.types import DaCompatible, T_DataArray, T_DataArrayOrSet, T_DuckArray
from xarray.core.utils import (
Default,
HybridMappingProxy,
Expand Down Expand Up @@ -249,6 +249,7 @@ class DataArray(
DataWithCoords,
DataArrayArithmetic,
DataArrayAggregations,
Generic[T_DuckArray],
):
"""N-dimensional array with labeled coordinates and dimensions.

Expand Down Expand Up @@ -403,7 +404,7 @@ class DataArray(

def __init__(
self,
data: Any = dtypes.NA,
data: T_DuckArray | ArrayLike = dtypes.NA,
coords: Sequence[Sequence[Any] | pd.Index | DataArray]
| Mapping[Any, Any]
| None = None,
Expand Down Expand Up @@ -455,7 +456,7 @@ def __init__(
coords = {k: v.copy() for k, v in coords.variables.items()}

# These fully describe a DataArray
self._variable = variable
self._variable: Variable = variable
assert isinstance(coords, dict)
self._coords = coords
self._name = name
Expand Down Expand Up @@ -731,7 +732,7 @@ def __len__(self) -> int:
return len(self.variable)

@property
def data(self) -> Any:
def data(self) -> T_DuckArray:
"""
The DataArray's data as an array. The underlying array type
(e.g. dask, sparse, pint) is preserved.
Expand All @@ -745,7 +746,7 @@ def data(self) -> Any:
return self.variable.data

@data.setter
def data(self, value: Any) -> None:
def data(self, value: T_DuckArray | ArrayLike) -> None:
self.variable.data = value

@property
Expand Down