Skip to content

use built in clip - #309

Closed
raybellwaves wants to merge 2 commits into
xarray-contrib:mainfrom
raybellwaves:fix-clip
Closed

use built in clip#309
raybellwaves wants to merge 2 commits into
xarray-contrib:mainfrom
raybellwaves:fix-clip

Conversation

@raybellwaves

@raybellwaves raybellwaves commented May 8, 2021

Copy link
Copy Markdown
Member

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

@raybellwaves
raybellwaves requested a review from aaronspring May 8, 2021 10:09
@codecov

codecov Bot commented May 8, 2021

Copy link
Copy Markdown

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
np.trapz, tpr, fpr, input_core_dims=[[dim], [dim]], dask="allowed"
)
area = np.abs(area)
area = abs(area)

Copy link
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown

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
Copy Markdown
Member Author

any idea why this got closed @aaronspring ?

@aaronspring

Copy link
Copy Markdown
Collaborator

any idea why this got closed @aaronspring ?

Ups. Sorry. No.

@aaronspring

Copy link
Copy Markdown
Collaborator

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

@aaronspring

Copy link
Copy Markdown
Collaborator

I don’t see how I could reopen…

@raybellwaves

Copy link
Copy Markdown
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