From 5bcd13c310b03a88dd8758ef49ec282e855d31d0 Mon Sep 17 00:00:00 2001 From: raybellwaves Date: Sat, 8 May 2021 05:47:23 -0400 Subject: [PATCH] use built in clip --- CHANGELOG.rst | 14 +++++++++----- ci/dev.yml | 2 +- ci/doc.yml | 2 +- ci/docs_notebooks.yml | 2 +- ci/minimum-tests.yml | 2 +- xskillscore/core/probabilistic.py | 4 ++-- xskillscore/tests/test_probabilistic.py | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ac3fed6e..f0d0beff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,14 @@ Changelog History xskillscore v0.0.20 (2021-XX-XX) -------------------------------- +Features +~~~~~~~~ +- Specify category distribution type with ``input_distributions`` in + :py:func:`~xskillscore.rps` if ``category_edges==None`` that forecasts and + observations are probability distributions ``p`` or cumulative + distributionss ``c``. See :py:func:`~xskillscore.rps` docstrings and doctests for + examples. (:pr:`300`) `Aaron Spring`_ + Internal Changes ~~~~~~~~~~~~~~~~ - Use ``pytest-xdist`` and ``matplotlib-base`` in environments to speed up CI. @@ -12,12 +20,8 @@ Internal Changes - :py:func:`~xskillscore.rps` does not break from masking NaNs anymore. :py:func:`~xskillscore.rps` expilicty checks for ``bin_dim`` if ``category_edges==None``. (:pr:`287`) `Aaron Spring`_ -- Specify category distribution type with ``input_distributions`` in - :py:func:`~xskillscore.rps` if ``category_edges==None`` that forecasts and - observations are probability distributions ``p`` or cumulative - distributionss ``c``. See :py:func:`~xskillscore.rps` docstrings and doctests for - examples. (:pr:`300`) `Aaron Spring`_ - Add doctest on the docstring examples. (:pr:`302`) `Ray Bell`_ +- Use built in ``xarray`` clip method. (:pr:`309`) `Ray Bell`_ xskillscore v0.0.19 (2021-03-12) diff --git a/ci/dev.yml b/ci/dev.yml index c384582a..452d4ea7 100644 --- a/ci/dev.yml +++ b/ci/dev.yml @@ -24,7 +24,7 @@ dependencies: - xarray>=0.16.1 # xhistogram 0.1.3 introduced an error that broke xskillscore # see https://github.com/xgcm/xhistogram/issues/48 - - xhistogram!=0.1.3 + - xhistogram==0.1.2 # Package Management - asv - black diff --git a/ci/doc.yml b/ci/doc.yml index fc16ddca..978df426 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -21,6 +21,6 @@ dependencies: - xarray>=0.16.1 # xhistogram 0.1.3 introduced an error that broke xskillscore # see https://github.com/xgcm/xhistogram/issues/48 - - xhistogram!=0.1.3 + - xhistogram==0.1.2 - pip: - -e .. diff --git a/ci/docs_notebooks.yml b/ci/docs_notebooks.yml index 3b4a096d..540ad2bf 100644 --- a/ci/docs_notebooks.yml +++ b/ci/docs_notebooks.yml @@ -14,7 +14,7 @@ dependencies: - xarray>=0.16.1 # xhistogram 0.1.3 introduced an error that broke xskillscore # see https://github.com/xgcm/xhistogram/issues/48 - - xhistogram!=0.1.3 + - xhistogram==0.1.2 - importlib_metadata - jupyterlab - matplotlib-base diff --git a/ci/minimum-tests.yml b/ci/minimum-tests.yml index 5860e54a..ce70b61b 100644 --- a/ci/minimum-tests.yml +++ b/ci/minimum-tests.yml @@ -15,7 +15,7 @@ dependencies: - xarray>=0.16.1 # xhistogram 0.1.3 introduced an error that broke xskillscore # see https://github.com/xgcm/xhistogram/issues/48 - - xhistogram!=0.1.3 + - xhistogram==0.1.2 - coveralls - pytest - pytest-cov diff --git a/xskillscore/core/probabilistic.py b/xskillscore/core/probabilistic.py index 0aaf97ae..4188c8e6 100644 --- a/xskillscore/core/probabilistic.py +++ b/xskillscore/core/probabilistic.py @@ -1153,9 +1153,9 @@ def _auc(fpr, tpr, dim="probability_bin"): area = xr.apply_ufunc( np.trapz, tpr, fpr, input_core_dims=[[dim], [dim]], dask="allowed" ) - area = np.abs(area) + area = abs(area) if ((area > 1)).any(): - area = np.clip(area, 0, 1) # allow only values between 0 and 1 + area = area.clip(0, 1) # allow only values between 0 and 1 return area diff --git a/xskillscore/tests/test_probabilistic.py b/xskillscore/tests/test_probabilistic.py index 3631152d..2e3c894d 100644 --- a/xskillscore/tests/test_probabilistic.py +++ b/xskillscore/tests/test_probabilistic.py @@ -996,7 +996,7 @@ def test_roc_bin_edges_continuous_against_sklearn( forecast_1d_long, observation_1d_long, drop_intermediate_bool ): """Test xs.roc against sklearn.metrics.roc_curve/auc_score.""" - fp = np.clip(forecast_1d_long, 0, 1) # prob + fp = forecast_1d_long.clip(0, 1) # prob ob = observation_1d_long > 0 # binary # sklearn sk_fpr, sk_tpr, _ = roc_curve(ob, fp, drop_intermediate=drop_intermediate_bool) @@ -1017,7 +1017,7 @@ def test_roc_bin_edges_continuous_against_sklearn( def test_roc_bin_edges_drop_intermediate(forecast_1d_long, observation_1d_long): """Test that drop_intermediate reduces probability_bins in xs.roc .""" - fp = np.clip(forecast_1d_long, 0, 1) # prob + fp = forecast_1d_long.clip(0, 1) # prob ob = observation_1d_long > 0 # binary # xs txs_fpr, txs_tpr, txs_area = roc(