Skip to content
2 changes: 1 addition & 1 deletion xskillscore/core/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def pearson_r_eff_p_value(
<xarray.DataArray (x: 3, y: 3)> Size: 72B
array([[0.82544245, nan, 0.25734167],
[0.78902959, 0.57503354, 0.8059353 ],
[0.79242625, 0.66792245, nan]])
[0.79242625, 0.66792245, 1. ]])
Dimensions without coordinates: x, y
"""
_fail_if_dim_empty(dim)
Expand Down
20 changes: 5 additions & 15 deletions xskillscore/core/np_deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _effective_sample_size(a, b, axis, skipna):
b = np.rollaxis(b, axis)

# count total number of samples that are non-nan.
n = np.count_nonzero(~np.isnan(np.atleast_1d(a)), axis=0)
n = np.count_nonzero(~np.isnan(a), axis=0)

# compute lag-1 autocorrelation.
am, bm = __compute_anomalies(a, b, weights=None, axis=0, skipna=skipna)
Expand Down Expand Up @@ -347,7 +347,7 @@ def _pearson_r_p_value(a, b, weights, axis, skipna):
a = np.rollaxis(a, axis)
b = np.rollaxis(b, axis)
# count non-nans
dof = np.count_nonzero(~np.isnan(np.atleast_1d(a)), axis=0) - 2
dof = np.count_nonzero(~np.isnan(a), axis=0) - 2
with warnings.catch_warnings():
warnings.simplefilter("ignore", RuntimeWarning)
t_squared = r**2 * (dof / ((1.0 - r) * (1.0 + r)))
Expand All @@ -358,14 +358,7 @@ def _pearson_r_p_value(a, b, weights, axis, skipna):
_b = 0.5
res = special.betainc(_a, _b, _x)
# reset masked values to nan
# raises <__array_function__ internals>:5: DeprecationWarning: Calling nonzero
# on 0d arrays is deprecated, as it behaves surprisingly. Use
# `atleast_1d(cond).nonzero()` if the old behavior was intended. If the context
# of this warning is of the form `arr[nonzero(cond)]`, just use `arr[cond]`.
nan_locs = np.where(np.isnan(np.atleast_1d(r)))
if len(nan_locs[0]) > 0:
res[nan_locs] = np.nan
return res
return np.where(np.isnan(r), np.nan, res)


def _pearson_r_eff_p_value(a, b, axis, skipna):
Expand Down Expand Up @@ -417,10 +410,7 @@ def _pearson_r_eff_p_value(a, b, axis, skipna):
_b = 0.5
res = special.betainc(_a, _b, _x)
# reset masked values to nan
nan_locs = np.where(np.isnan(np.atleast_1d(r)))
if len(nan_locs[0]) > 0:
res[nan_locs] = np.nan
return res
return np.where(np.isnan(r), np.nan, res)


def _spearman_r(a, b, weights, axis, skipna):
Expand Down Expand Up @@ -490,7 +480,7 @@ def _spearman_r_p_value(a, b, weights, axis, skipna):
a = np.rollaxis(a, axis)
b = np.rollaxis(b, axis)
# count non-nans
dof = np.count_nonzero(~np.isnan(np.atleast_1d(a)), axis=0) - 2
dof = np.count_nonzero(~np.isnan(a), axis=0) - 2
with warnings.catch_warnings():
warnings.simplefilter("ignore", RuntimeWarning)
t = rs * np.sqrt((dof / ((rs + 1.0) * (1.0 - rs))).clip(0))
Expand Down
7 changes: 2 additions & 5 deletions xskillscore/core/stattests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def multipletests(
[ 0.1 , 0.1 , 0.1 ],
[ 0.1 , 0.1 , 0.1 ]]])
Coordinates:
* result (result) <U15 240B 'reject' ... 'alphacBonf'
* x (x) int64 24B 0 1 2
* y (y) int64 24B 0 1 2
multipletests_method <U6 24B 'fdr_bh'
multipletests_alpha float64 8B 0.1
* result (result) <U15 240B 'reject' ... 'alphacBonf'
"""
MULTIPLE_TESTS = [
"bonferroni",
Expand Down Expand Up @@ -182,10 +182,7 @@ def multipletests(
ret = tuple(r.unstack("s").transpose(*p.dims, ...) for r in ret)

def _add_kwargs_as_coords(r: XArray):
return r.assign_coords(
multipletests_method=method,
multipletests_alpha=alpha
)
return r.assign_coords(multipletests_method=method, multipletests_alpha=alpha)

ret = tuple(_add_kwargs_as_coords(r) for r in ret)

Expand Down
Loading