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

Fix boolean dask index in tests #165

Merged
merged 8 commits into from
Jun 9, 2023
Merged
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
8 changes: 6 additions & 2 deletions xarrayutils/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ def test_linregress_ufunc():
assert np.isnan(_linregress_ufunc(x, y, nanmask=True)).all()


def _linregress_ufunc(a, b, nanmask=False):
def _linregress_ufunc(a: np.ndarray, b: np.ndarray, nanmask: bool = False):
"""ufunc to wrap check output of `xr_linregress` against pure scipy results"""
if nanmask:
idxa = np.isnan(a)
idxb = np.isnan(b)

mask = np.logical_and(~idxa, ~idxb)

if sum(~mask) < len(b): # only applies the mask if not all nan
a = a[mask]
b = b[mask]
Expand Down Expand Up @@ -216,7 +218,9 @@ def test_xr_linregress(chunks, dim, variant, dtype, nans, parameter, ni):
for jj in range(len(a[dims[1]])):
pos = dict({dims[0]: ii, dims[1]: jj})

expected = _linregress_ufunc(a.isel(**pos), b.isel(**pos), nanmask=True)
expected = _linregress_ufunc(
a.isel(**pos).load().data, b.isel(**pos).load().data, nanmask=True
)
reg_sub = reg.isel(**pos)

np.testing.assert_allclose(reg_sub[parameter].data, expected[ni])
Expand Down
Loading