Skip to content

Fix off-by-one in aggregations #55920

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 2 commits into from
Nov 13, 2023
Merged
Changes from all commits
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
2 changes: 1 addition & 1 deletion pandas/core/indexers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_window_bounds(
closed: str | None = None,
step: int | None = None,
) -> tuple[np.ndarray, np.ndarray]:
if center:
if center or self.window_size == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this result in the same resulting offset as before? i.e.

In [1]: 0 - 1 // 2
Out[1]: 0

Copy link
Member Author

Choose a reason for hiding this comment

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

In your code 1 // 2 is getting evaluated first. The parentheses matter

>>> (0 - 1) // 2
-1

Copy link
Member Author

Choose a reason for hiding this comment

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

I verified this fixed the segfault via a local run of #55102 - hopefully can make progress soon to getting that up in CI since this is now 2 releases in a row where we have a segfault when cutting the release.

#55151 is a big step towards getting UBSAN/ASAN set up as the datetime code issues a ton of errors, and by design those tools stop at the first error encountered. If you have any time to help review that and push through would appreciate it

offset = (self.window_size - 1) // 2
else:
offset = 0
Expand Down