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

Fix date_range(start, end, freq) when end-start is divisible by freq #16516

Merged

Conversation

mroeschke
Copy link
Contributor

Description

xref #16507

date_range generates its dates via range, and the end of this range was calculated via math.ceil((end - start) / freq). If (end - start) / freq did not produce a remainder, math.ceil would not correctly increment this value by 1 to capture the last date.

Instead, this PR uses math.floor((end - start) / freq) + 1 to always ensure the last date is captured

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke added bug Something isn't working Python Affects Python cuDF API. non-breaking Non-breaking change labels Aug 8, 2024
@mroeschke mroeschke requested a review from a team as a code owner August 8, 2024 22:09
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

Do we need to add some test cases for non-integer multiples too? Also for reference I think this is how pandas calculates the space: https://github.com/pandas-dev/pandas/blob/93198fb47a754051f84c235dea8920ffc3cf1b13/pandas/core/arrays/datetimes.py#L511-L514

Co-authored-by: Bradley Dice <bdice@bradleydice.com>
@mroeschke
Copy link
Contributor Author

Do we need to add some test cases for non-integer multiples too?

IIUC, there is a test python/cudf/cudf/tests/test_datetime.py::test_date_range_start_end_freq that tests resulting periods that are non-integer

@mroeschke
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 4cd87d3 into rapidsai:branch-24.10 Aug 9, 2024
79 checks passed
@mroeschke mroeschke deleted the bug/date_range/fencepost branch August 9, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants