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

Make constructing slices lazily. #1994

Merged
merged 5 commits into from
Mar 18, 2018

Conversation

fujiisoup
Copy link
Member

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

Copy link
Member

@shoyer shoyer left a 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 :).


self._setup_windows()
self.window_labels = self.obj[self.dim]
self._stops = np.arange(1, len(self.window_labels) + 1)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@shoyer
Copy link
Member

shoyer commented Mar 15, 2018

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)()
Copy link
Member Author

@fujiisoup fujiisoup Mar 16, 2018

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?

Copy link
Member

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.

Copy link
Member

@shoyer shoyer left a 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)()
Copy link
Member

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.


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)
Copy link
Member

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.

@fujiisoup fujiisoup merged commit 1d0fbe6 into pydata:master Mar 18, 2018
@fujiisoup fujiisoup deleted the lazy_rolling_window branch March 18, 2018 08:56
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.

DataArray.rolling().mean() is way slower than it should be
2 participants