Skip to content

Commit

Permalink
Merge pull request xarray-contrib#122 from ahuang11/expose_keep_attrs
Browse files Browse the repository at this point in the history
Expose keep_attrs
  • Loading branch information
aaronspring committed Aug 16, 2020
2 parents 03cda99 + a28573e commit 8bab6a7
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 89 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Features
--------
- Added contingency table and associated metrics (:pr:`119`). `Dougie Squire`_
- Add `dim` and `weights` for probabilistic metrics. (:pr:`121`) `Aaron Spring`_
- Add `keep_attrs` for all metrics. (:pr:`122`) `Andrew Huang`_

Breaking Changes
----------------
Expand Down
83 changes: 53 additions & 30 deletions xskillscore/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,77 +40,91 @@ def _in_ds(self, x):
else:
return self._obj[x]

def pearson_r(self, a, b, dim, weights=None, skipna=False):
def pearson_r(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return pearson_r(a, b, dim, weights=weights, skipna=skipna)
return pearson_r(
a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs
)

def r2(self, a, b, dim, weights=None, skipna=False):
def r2(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return r2(a, b, dim, weights=weights, skipna=skipna)
return r2(a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs)

def pearson_r_p_value(self, a, b, dim, weights=None, skipna=False):
def pearson_r_p_value(
self, a, b, dim, weights=None, skipna=False, keep_attrs=False
):
a = self._in_ds(a)
b = self._in_ds(b)
return pearson_r_p_value(a, b, dim, weights=weights, skipna=skipna)
return pearson_r_p_value(
a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs
)

def effective_sample_size(self, a, b, dim, skipna=False):
def effective_sample_size(self, a, b, dim, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return effective_sample_size(a, b, dim, skipna=skipna)
return effective_sample_size(a, b, dim, skipna=skipna, keep_attrs=keep_attrs)

def pearson_r_eff_p_value(self, a, b, dim, skipna=False):
def pearson_r_eff_p_value(self, a, b, dim, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return pearson_r_eff_p_value(a, b, dim, skipna=skipna)
return pearson_r_eff_p_value(a, b, dim, skipna=skipna, keep_attrs=keep_attrs)

def spearman_r(self, a, b, dim, weights=None, skipna=False):
def spearman_r(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return spearman_r(a, b, dim, weights=weights, skipna=skipna)
return spearman_r(
a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs
)

def spearman_r_p_value(self, a, b, dim, weights=None, skipna=False):
def spearman_r_p_value(
self, a, b, dim, weights=None, skipna=False, keep_attrs=False
):
a = self._in_ds(a)
b = self._in_ds(b)
return spearman_r_p_value(a, b, dim, weights=weights, skipna=skipna)
return spearman_r_p_value(
a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs
)

def spearman_r_eff_p_value(self, a, b, dim, skipna=False):
def spearman_r_eff_p_value(self, a, b, dim, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return spearman_r_eff_p_value(a, b, dim, skipna=skipna)
return spearman_r_eff_p_value(a, b, dim, skipna=skipna, keep_attrs=keep_attrs)

def rmse(self, a, b, dim, weights=None, skipna=False):
def rmse(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return rmse(a, b, dim, weights=weights, skipna=skipna)
return rmse(a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs)

def mse(self, a, b, dim, weights=None, skipna=False):
def mse(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return mse(a, b, dim, weights=weights, skipna=skipna)
return mse(a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs)

def mae(self, a, b, dim, weights=None, skipna=False):
def mae(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return mae(a, b, dim, weights=weights, skipna=skipna)
return mae(a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs)

def median_absolute_error(self, a, b, dim, skipna=False):
def median_absolute_error(self, a, b, dim, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return median_absolute_error(a, b, dim, skipna=skipna)
return median_absolute_error(a, b, dim, skipna=skipna, keep_attrs=keep_attrs)

def mape(self, a, b, dim, weights=None, skipna=False):
def mape(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return mape(a, b, dim, weights=weights, skipna=skipna)
return mape(a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs)

def smape(self, a, b, dim, weights=None, skipna=False):
def smape(self, a, b, dim, weights=None, skipna=False, keep_attrs=False):
a = self._in_ds(a)
b = self._in_ds(b)
return smape(a, b, dim, weights=weights, skipna=skipna)
return smape(a, b, dim, weights=weights, skipna=skipna, keep_attrs=keep_attrs)

def crps_gaussian(self, observations, mu, sig, dim=None, weights=None):
def crps_gaussian(
self, observations, mu, sig, dim=None, weights=None, keep_attrs=False
):
observations = self._in_ds(observations)
mu = self._in_ds(mu)
sig = self._in_ds(sig)
Expand Down Expand Up @@ -139,7 +153,15 @@ def crps_ensemble(
)

def crps_quadrature(
self, x, cdf_or_dist, xmin=None, xmax=None, tol=1e-6, dim=None, weights=None
self,
x,
cdf_or_dist,
xmin=None,
xmax=None,
tol=1e-6,
dim=None,
weights=None,
keep_attrs=False,
):
x = self._in_ds(x)
cdf_or_dist = self._in_ds(cdf_or_dist)
Expand All @@ -156,6 +178,7 @@ def threshold_brier_score(
dim=None,
member_dim='member',
weights=None,
keep_attrs=False,
):
observations = self._in_ds(observations)
forecasts = self._in_ds(forecasts)
Expand Down

0 comments on commit 8bab6a7

Please sign in to comment.