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

BUG: fix timedelta floordiv with scalar float (correction of #44466) #44471

Conversation

jorisvandenbossche
Copy link
Member

Follow-up on #44466 (comment)

I still need to add a test that would actually catch this

@jorisvandenbossche jorisvandenbossche added Bug Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type labels Nov 15, 2021
@jorisvandenbossche jorisvandenbossche added this to the 1.4 milestone Nov 15, 2021
@jorisvandenbossche
Copy link
Member Author

Actually, I don't directly find a way to edit the test that it would have catched this. It seems that in practice timedelta division already acts similar as a floor division:

In [16]: np.array([1, 2, 3, 4, 5], dtype="m8[ns]") / 3
Out[16]: array([0, 0, 1, 1, 1], dtype='timedelta64[ns]')

In [17]: np.array([1, 2, 3, 4, 5], dtype="m8[ns]") // 3
Out[17]: array([0, 0, 1, 1, 1], dtype='timedelta64[ns]')

In [18]: np.array([1, 2, 3, 4, 5], dtype="m8[ns]").astype(float) / 3
Out[18]: array([0.33333333, 0.66666667, 1.        , 1.33333333, 1.66666667])

(so the integers for timedelta divison result already seem to be obtained with a floor round)

@jorisvandenbossche
Copy link
Member Author

Actually with a round towards zero (so np.fix and not np.floor), but that is still done for both division and floor division.

@jorisvandenbossche
Copy link
Member Author

jorisvandenbossche commented Nov 16, 2021

To conclude: this can be merged as is?

(the one failure is a CSV compression failure, so I assume unrelated)

@jbrockmendel
Copy link
Member

later today ill look at the scalar timedelta tests to see if past-me came up with anything.

@jbrockmendel
Copy link
Member

BTW @jorisvandenbossche can you take a look at #43840

@jbrockmendel
Copy link
Member

Looking at the scalar Timedelta.__floordiv__ i dont see anywhere where this makes a difference.

LGTM

@jorisvandenbossche
Copy link
Member Author

OK, merging this then

@jorisvandenbossche jorisvandenbossche merged commit 8c4bd0e into pandas-dev:master Nov 18, 2021
@jorisvandenbossche jorisvandenbossche deleted the timedeltaarray-div-float branch November 18, 2021 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants