8000 Backport PR: Series rolling count ignores min_periods by fujiaxiang · Pull Request #31320 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Backport PR: Series rolling count ignores min_periods #31320

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

Merged
merged 12 commits into from
Jan 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: handles min_periods argument in rolling.count (GH26996)
  • Loading branch information
fujiaxiang committed Jan 26, 2020
commit bd0fb503e5d311042ef32f0a424d2759137cab4b
10 changes: 8 additions & 2 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,14 @@ def count(self):

window = self._get_window()
window = min(window, len(obj)) if not self.center else window
min_periods = self.min_periods if self.min_periods is not None else 0
min_periods = min(min_periods, len(obj)) if not self.center else min_periods

# We set the default value min_periods to be 0 because count method
# is meant to count NAs, we don't want it by default requires all
# values in the window to be valid to produce a valid count
min_periods = 0 if self.min_periods is None else self.min_periods

# this is required as window is mutate above
min_periods = min(min_periods, window)

results = []
for b in blocks:
Expand Down
0