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

use built in clip #309

Closed
wants to merge 2 commits into from
Closed

use built in clip #309

wants to merge 2 commits into from

Conversation

raybellwaves
Copy link
Member

@raybellwaves raybellwaves commented May 8, 2021

Closes errors seen in #308

The latest xarray did some refactoring on the built in clip method. It broke something in xskillscore but it helped identify areas of improvement

we were calling np.clip(xarray object, min, max). There is the built in clip method which is preferred:

We were calling np.abs(xarray object). We can use the python abs method to do the same:

For what it's worth here's how the clip refactor showed up in xskillscore.

Latest:

conda remove --name test_env --all --y
conda create -n test_env python=3.9 --y
conda activate test_env
mamba install -c conda-forge xarray netCDF4 pooch --y
python

import xarray as xr
import numpy as np

ds = xr.tutorial.open_dataset("air_temperature")
np.clip(ds, 0, 1) # -> TypeError: clip() got an unexpected keyword argument 'out'

exit()
conda deactivate

xarray v0.17.0:

conda remove --name test_env --all --y
conda create -n test_env python=3.9 --y
conda activate test_env
mamba install -c conda-forge xarray==0.17.0 netCDF4 pooch --y
python

import xarray as xr
import numpy as np

ds = xr.tutorial.open_dataset("air_temperature")
np.clip(ds, 0, 1) # Works

@codecov
Copy link

codecov bot commented May 8, 2021

Codecov Report

Merging #309 (54ff8f2) into main (e2e3e7f) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #309   +/-   ##
=======================================
  Coverage   94.50%   94.50%           
=======================================
  Files          23       23           
  Lines        2566     2566           
=======================================
  Hits         2425     2425           
  Misses        141      141           
Impacted Files Coverage Δ
xskillscore/core/probabilistic.py 90.94% <100.00%> (ø)
xskillscore/tests/test_probabilistic.py 96.64% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67b47b9...54ff8f2. Read the comment docs.

@raybellwaves raybellwaves mentioned this pull request May 8, 2021
10 tasks
@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt np faster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no difference in speed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It calls __abs__ (unlike using the builtin sum, which would be much slower)

@raybellwaves
Copy link
Member Author

any idea why this got closed @aaronspring ?

@aaronspring
Copy link
Collaborator

any idea why this got closed @aaronspring ?

Ups. Sorry. No.

@aaronspring
Copy link
Collaborator

I used fixed and then mentioned this PR in my climpred PR. Didn’t know this works across repos

@aaronspring
Copy link
Collaborator

I don’t see how I could reopen…

@raybellwaves
Copy link
Member Author

No worries. Seems crazy that GitHub allows that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants