Skip to content

Improved duck array wrapping #9798

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

Merged
merged 30 commits into from
Nov 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd6b339
lots more duck array compat, plus tests
slevang Nov 18, 2024
893408c
Merge branch 'main' into more-array-api-compat
slevang Nov 18, 2024
f7866ce
merge sliding_window_view
slevang Nov 18, 2024
90037fe
namespaces constant
slevang Nov 18, 2024
5ba1a2f
revert dask allowed
slevang Nov 18, 2024
6225ae3
fix up some tests
slevang Nov 19, 2024
e2911c2
backwards compat sparse mask
slevang Nov 19, 2024
2ac37f9
add as_array methods
slevang Nov 21, 2024
1cc344b
to_like_array helper
slevang Nov 21, 2024
69080a5
Merge branch 'main' into more-array-api-compat
slevang Nov 21, 2024
372439c
only cast non-numpy
slevang Nov 21, 2024
0eef2cb
better idxminmax approach
slevang Nov 21, 2024
6739504
fix mypy
slevang Nov 21, 2024
9e6d6f8
naming, add is_array_type
slevang Nov 21, 2024
e721011
add public doc and whats new
slevang Nov 21, 2024
1fe4131
update comments
slevang Nov 21, 2024
205c199
add support for chunked arrays in as_array_type
slevang Nov 21, 2024
7752088
Merge branch 'main' into more-array-api-compat
slevang Nov 21, 2024
c8d4e5e
revert array_type methods
slevang Nov 22, 2024
e67a819
Merge branch 'main' into more-array-api-compat
slevang Nov 22, 2024
f306768
fix up whats new
slevang Nov 22, 2024
18ebdcd
comment about bool_
slevang Nov 22, 2024
f51e3fb
Merge branch 'main' into more-array-api-compat
slevang Nov 22, 2024
121af9e
add jax to complete ci envs
slevang Nov 23, 2024
472ae7e
add pint and sparse to tests
slevang Nov 23, 2024
5aa4a39
remove from windows
slevang Nov 23, 2024
390df6f
mypy, xfail one more sparse
slevang Nov 23, 2024
f6074d2
add dask and a few other methods
slevang Nov 25, 2024
561f21b
Merge branch 'main' into more-array-api-compat
slevang Nov 25, 2024
bfd6aeb
move whats new
slevang Nov 25, 2024
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
add dask and a few other methods
  • Loading branch information
slevang committed Nov 25, 2024
commit f6074d2fa3b9c2d3900cda25c4cb322f2c698bd1
73 changes: 60 additions & 13 deletions xarray/tests/test_duck_array_wrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@

# Don't run cupy in CI because it requires a GPU
NAMESPACE_ARRAYS = {
"jax.numpy": {
"cupy": {
"attrs": {
"array": "ndarray",
"constructor": "asarray",
},
"xfails": {"quantile": "no nanquantile"},
},
"dask.array": {
"attrs": {
"array": "Array",
"constructor": "from_array",
},
"xfails": {
"rolling": "no sliding_window_view",
"rolling_mean": "no sliding_window_view",
"argsort": "no argsort",
"conjugate": "conj but no conjugate",
"searchsorted": "dask.array.searchsorted but no Array.searchsorted",
},
},
"cupy": {
"jax.numpy": {
"attrs": {
"array": "ndarray",
"constructor": "asarray",
},
"xfails": {"quantile": "no nanquantile"},
"xfails": {
"rolling_construct": "no sliding_window_view",
"rolling_reduce": "no sliding_window_view",
"cumulative_construct": "no sliding_window_view",
"cumulative_reduce": "no sliding_window_view",
},
},
"pint": {
Copy link
Contributor Author

@slevang slevang Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added dask, pint, and sparse, and more consolidated xfail lists. Some of these are probably desired behavior, like all the methods that return bool or int not returning a pint.Quantity, but it was easiest to just xfail them.

"attrs": {
Expand All @@ -42,7 +55,8 @@
"isin": "returns a bool",
"isnull": "returns a bool",
"notnull": "returns a bool",
"rolling_mean": "no dispatch for numbagg/bottleneck",
"rolling_reduce": "no dispatch for numbagg/bottleneck",
"cumulative_reduce": "no dispatch for numbagg/bottleneck",
"searchsorted": "returns an int",
"weighted": "no tensordot",
},
Expand All @@ -59,8 +73,12 @@
"count": "dense output",
"dot": "fails on some platforms/versions",
"isin": "no isin",
"rolling": "no sliding_window_view",
"rolling_mean": "no sliding_window_view",
"rolling_construct": "no sliding_window_view",
"rolling_reduce": "no sliding_window_view",
"cumulative_construct": "no sliding_window_view",
"cumulative_reduce": "no sliding_window_view",
"coarsen_construct": "pad constant_values must be fill_value",
"coarsen_reduce": "pad constant_values must be fill_value",
"weighted": "fill_value error",
"coarsen": "pad constant_values must be fill_value",
"quantile": "no non skipping version",
Expand Down Expand Up @@ -119,7 +137,7 @@ def setUp(self, request, namespace):

def test_apply_ufunc(self):
func = lambda x: x + 1
result = xr.apply_ufunc(func, self.x1)
result = xr.apply_ufunc(func, self.x1, dask="parallelized")
assert isinstance(result.data, self.Array)

def test_align(self):
Expand Down Expand Up @@ -248,26 +266,51 @@ def test_groupby(self):
result = self.x.groupby("x").mean()
assert isinstance(result.data, self.Array)

def test_rolling(self):
def test_groupby_bins(self):
result = self.x.groupby_bins("x", bins=[0, 2, 4, 6]).mean()
assert isinstance(result.data, self.Array)

def test_rolling_iter(self):
result = self.x.rolling(x=3)
elem = next(iter(result))[1]
assert isinstance(elem.data, self.Array)

def test_rolling_construct(self):
result = self.x.rolling(x=3).construct(x="window")
assert isinstance(result.data, self.Array)

@pytest.mark.parametrize("skipna", [True, False])
def test_rolling_mean(self, skipna):
def test_rolling_reduce(self, skipna):
result = self.x.rolling(x=3).mean(skipna=skipna)
assert isinstance(result.data, self.Array)

@pytest.mark.xfail(reason="rolling_exp uses numbagg")
def test_rolling_exp(self):
def test_rolling_exp_reduce(self):
result = self.x.rolling_exp(x=3).mean()
assert isinstance(result.data, self.Array)

def test_cumulative_iter(self):
result = self.x.cumulative("x")
elem = next(iter(result))[1]
assert isinstance(elem.data, self.Array)

def test_cumulative_construct(self):
result = self.x.cumulative("x").construct(x="window")
assert isinstance(result.data, self.Array)

def test_cumulative_reduce(self):
result = self.x.cumulative("x").sum()
assert isinstance(result.data, self.Array)

def test_weighted(self):
result = self.x.weighted(self.x.fillna(0)).mean()
assert isinstance(result.data, self.Array)

def test_coarsen(self):
def test_coarsen_construct(self):
result = self.x.coarsen(x=2, boundary="pad").construct(x=["a", "b"])
assert isinstance(result.data, self.Array)

def test_coarsen_reduce(self):
result = self.x.coarsen(x=2, boundary="pad").mean()
assert isinstance(result.data, self.Array)

Expand Down Expand Up @@ -391,6 +434,10 @@ def test_argsort(self):
result = self.x.argsort()
assert isinstance(result.data, self.Array)

def test_astype(self):
result = self.x.astype(int)
assert isinstance(result.data, self.Array)

def test_clip(self):
result = self.x.clip(min=2.0, max=4.0)
assert isinstance(result.data, self.Array)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy