-
-
Notifications
You must be signed in to change notification settings - Fork 20k
BUG: fix to_timedelta ignoring unit for mixed round/non-round floats #65170
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 2 commits
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 |
|---|---|---|
|
|
@@ -354,6 +354,17 @@ def test_to_timedelta_unit_non_round_floats(self): | |
| result2 = to_timedelta(arr2, unit="s") | ||
| assert result2.unit == "ns" | ||
|
|
||
| def test_to_timedelta_unit_mixed_round_and_non_round_floats(self): | ||
| # GH#65150 - round floats mixed with non-round floats should | ||
| # respect the unit for all values | ||
| result = to_timedelta([1.0, 1.01], unit="s") | ||
| expected = to_timedelta(np.array([1.0, 1.01]), unit="s") | ||
| tm.assert_index_equal(result, expected) | ||
|
|
||
| # Also test integers mixed with non-round floats | ||
| result2 = to_timedelta([1, 1.01], unit="s") | ||
| tm.assert_index_equal(result2, expected) | ||
|
|
||
| def test_float_to_timedelta_raise_near_bounds(self): | ||
| # GH#57366 | ||
| oneday_in_ns = 1e9 * 60 * 60 * 24 | ||
|
|
@@ -438,7 +449,7 @@ def test_uint64_to_timedelta_coerce(self): | |
| arr = np.array([uint64_max], dtype=np.uint64) | ||
|
|
||
| result = to_timedelta(arr, unit="ns", errors="coerce") | ||
| expected = TimedeltaIndex([pd.NaT]) | ||
| expected = TimedeltaIndex([pd.NaT], dtype="m8[ns]") | ||
|
Member
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. How is this change related exactly?
Member
Author
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. its a side-effect, but it matches the to_datetime behavior
Member
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. It's the
Member
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. Yes, understood |
||
| tm.assert_index_equal(result, expected) | ||
|
|
||
| # scalar | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that this works correctly for arrays (instead of lists), I don't know if that actually is tested separately?
Could also create expected with
to_timedelta(["0 days 00:00:01", "0 days 00:00:01.01"]), that seems more explicit / safer anywayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update