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 1 commit
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
Prev Previous commit
Next Next commit
Update test_utils.py
  • Loading branch information
jbusecke committed Jun 9, 2023
commit 148cbf9b0671e0ecd2c6938b75f5c95925fd063a
12 changes: 4 additions & 8 deletions xarrayutils/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +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)
# load dask arrays into memory
if isinstance(idxa, dsa.core.Array):
idxa = idxa.load()
if isinstance(idxb, dsa.core.Array):
idxb = idxb.load()


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 @@ -222,7 +218,7 @@ 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