-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Implement __iter__ for Rolling and Expanding #34201
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
Changes from 15 commits
7e461a1
1314059
8bcb313
24c3ede
dea38f2
cd9e7ac
e5e912b
045a76f
7e6779f
4d85ab9
fe74bc9
c0f4cf4
3bb2cf0
ac23518
7f74b79
5577efc
fd6e9a9
3cefb23
1623593
61af135
7e85f87
9b84e74
8379810
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,8 +247,31 @@ def __repr__(self) -> str: | |
return f"{self._window_type} [{attrs}]" | ||
|
||
def __iter__(self): | ||
url = "https://github.com/pandas-dev/pandas/issues/11704" | ||
raise NotImplementedError(f"See issue #11704 {url}") | ||
window = self._get_window(win_type=None) | ||
|
||
blocks, obj = self._create_blocks() | ||
index = self._get_window_indexer(window=window) | ||
|
||
# Choose the min between min_periods and window to determine the output size | ||
if self.min_periods is None: | ||
iter_threshold = window | ||
else: | ||
iter_threshold = min(window, self.min_periods) | ||
|
||
start, end = index.get_window_bounds( | ||
num_values=len(obj), | ||
min_periods=self.min_periods, | ||
center=self.center, | ||
closed=self.closed, | ||
) | ||
# From get_window_bounds, those two should be equal in length of array | ||
assert len(start) == len(end) | ||
|
||
window_size = len(start) | ||
for i in range(window_size): | ||
result = obj.iloc[slice(start[i], end[i])] | ||
if result.count().min() >= iter_threshold: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. emm, i am not sure about this actually, because but I also do not know if this matters in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right I am thinking it doesn't matter in From the user perspective, I can see a potential source of confusion if not all the windows are returned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, leaving it to users sounds more convincing! thanks, @mroeschke ! i have updated the PR to remove this check (also no error raising) here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, thanks! Might want to document this behavior in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, added! thanks for the reviews! @mroeschke |
||
yield result | ||
|
||
def _prep_values(self, values: Optional[np.ndarray] = None) -> np.ndarray: | ||
"""Convert input to numpy arrays for Cython routines""" | ||
|
Uh oh!
There was an error while loading. Please reload this page.