-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Timedelta drops decimals if precision is greater than nanoseconds #36771
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e1e4296
Fix timedelta problem when input is more precise than nanoseconds
phofl 78a9938
Modify whatsnew
phofl 52463cf
Merge branch 'master' of https://github.com/pandas-dev/pandas into 36738
phofl 4d6c9dc
Add docstring and test
phofl f4ff3e0
Fix docstring
phofl f79106d
Add additional tests
phofl e3c133d
Merge branch 'master' of https://github.com/pandas-dev/pandas into 36738
phofl 193921e
Merge branch 'master' of https://github.com/pandas-dev/pandas into 36738
phofl 83111d9
Adress review comments
phofl d038085
Merge branch 'master' of https://github.com/pandas-dev/pandas into 36738
phofl 4ce27c8
Add comments and testcases
phofl 8b00890
Move whatsnew
phofl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,3 +210,20 @@ def test_to_timedelta_nullable_int64_dtype(self): | |
result = to_timedelta(Series([1, None], dtype="Int64"), unit="days") | ||
|
||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
("input", "expected"), | ||
[ | ||
("8:53:08.71800000001", "8:53:08.718"), | ||
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. can you add a case with the trailing digit being 9 to clarify the truncating/rounding distinction 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. Done |
||
("8:53:08.718001", "8:53:08.718001"), | ||
("8:53:08.7180000001", "8:53:08.7180000001"), | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
("-8:53:08.71800000001", "-8:53:08.718"), | ||
("8:53:08.7180000089", "8:53:08.718000008"), | ||
], | ||
) | ||
@pytest.mark.parametrize("func", [pd.Timedelta, pd.to_timedelta]) | ||
def test_to_timedelta_precision_over_nanos(self, input, expected, func): | ||
# GH: 36738 | ||
expected = pd.Timedelta(expected) | ||
result = func(input) | ||
assert result == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
clarify this is for a string input
do additional digits round or just drop (and if just drop, are we sure thats the desired behavior?)
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.
Dropd additional digits. Was not sure either so I started with the easier implementation
#36771 (comment)