-
Notifications
You must be signed in to change notification settings - Fork 39
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
Switch some attributes over to dynamic calculation? #158
Comments
Can you try PR #160 (branch |
This looks awesome, @jswhit! Thanks for the quick turnaround. @spencerkclark I think this nails the problem. Thoughts? We get ~200x speedup on Current setup: import xarray as xr
import cftime
import datetime
print(xr.__version__)
>>> 0.15.1
print(cftime.__version__)
>>> 1.1.1.1
date = cftime.DatetimeNoLeap(2000, 1, 1)
%timeit date.replace(year=2001)
>>> 222 µs ± 44.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
timedelta = datetime.timedelta(days=9)
%timeit date + timedelta
>>> 207 µs ± 36.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
times = xr.cftime_range('1950', '2000', freq='AS')
%timeit times.shift(1, 'YS')
>>> 14.3 ms ± 1.7 ms per loop (mean ± std. dev. of 7 runs, 100 loops each) With #160: import xarray as xr
import cftime
import datetime
print(xr.__version__)
>>> 0.15.1
print(cftime.__version__)
>>> 1.1.1.1
date = cftime.DatetimeNoLeap(2000, 1, 1)
%timeit date.replace(year=2001)
>>> 1.15 µs ± 113 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
timedelta = datetime.timedelta(days=9)
%timeit date + timedelta
>>> 512 ns ± 41.7 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
times = xr.cftime_range('1950', '2000', freq='AS')
%timeit times.shift(1, 'YS')
>>> 796 µs ± 58.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
change dayofwk and dayofyr into properties (issue #158)
Merged now - will be in the 1.1.2 release. Let me know if you need a release sooner rather than later. Does the xarray test suite still pass with this change? |
Good question; one failing test does appear, which seems related to the changes:
A minimal example of the issue would be:
We would expect [5] to return 33. |
#163 provides a fix for the issue above. |
Merged #163 |
I am moving a discussion from
pangeo
over to here: pangeo-data/pangeo#764.xarray
has a method on theirCFTimeIndex
to shift thecftime
.E.g.,
I am using this heavily in my package to shift large
CFTimeIndex
's many times in succession. It's running fairly slow and we're finding that the bottleneck is most likely incftime
rather thanxarray.CFTimeIndex.shift()
. Please see @spencerkclark's timing comments toward the bottom of that issue discussion.It looks like the calculation of
dayofwk
anddayofyr
is the bottleneck here, since it's being computed on initialization of the object (cftime/cftime/_cftime.pyx
Lines 1468 to 1473 in 9f7c576
Would it be feasible to make these dynamic attributes? E.g. they are calculated as a property of the object only when requested by the user?
Details:
cftime
version: 1.0.4.2environment: Mac OSX, python 3.7.3
The text was updated successfully, but these errors were encountered: