-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make constructing slices lazily. #1994
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add a benchmark for rolling computations :).
xarray/core/rolling.py
Outdated
|
||
self._setup_windows() | ||
self.window_labels = self.obj[self.dim] | ||
self._stops = np.arange(1, len(self.window_labels) + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do this only when iteration is requested? that would be a bit more efficient for the common case where iteration is not done.
My guess is that iteration is slow enough that the overhead of recreating these objects will not be noticeable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The benchmark does not need to be complete, but it would be good to ensure we don't have a regression here. |
se = self.da_long.to_series() | ||
getattr(se.rolling(window=window), func)() | ||
else: | ||
getattr(self.da_long.rolling(x=window), func)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also added a benchmark using pandas for long 1d-array, in order to make it easier to find the cause of the regression.
But is it too verbose as pandas might make the similar benchmark tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
se = self.da_long.to_series() | ||
getattr(se.rolling(window=window), func)() | ||
else: | ||
getattr(self.da_long.rolling(x=window), func)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with this.
xarray/core/rolling.py
Outdated
|
||
def __iter__(self): | ||
for (label, indices) in zip(self.window_labels, self.window_indices): | ||
window = self.obj.isel(**{self.dim: indices}) | ||
_stops = np.arange(1, len(self.window_labels) + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need to preface with an underscore for variables that are already limited in scope to this method.
whats-new.rst
for all changes.Quick fix of #1993.
With this fix, the script shown in #1993 runs
Bottleneck: 0.08317923545837402 s
Pandas: 1.3338768482208252 s
Xarray: 1.1349339485168457 s