-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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:Floating point accuracy with DatetimeIndex.round (#14440) #15568
Conversation
@@ -175,6 +175,17 @@ def test_round(self): | |||
tm.assertRaisesRegexp(ValueError, msg, rng.round, freq='M') | |||
tm.assertRaisesRegexp(ValueError, msg, elt.round, freq='M') | |||
|
|||
# GH 14440 |
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.
can you also round to us/ns here as well (which should equal the original)
as an aside, you can now do parametrized tests (but have to move them to separate functions and not class based)
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.
So the rounding is happening correctly for microseconds but not with nanoseconds:
In [7]: pd.DatetimeIndex(['2016-10-17 12:00:00.0015']).round('ns')
Out[7]: DatetimeIndex(['2016-10-17 12:00:00.001499904'], dtype='datetime64[ns]', freq=None)
The rounding methodology seems sound. I am unsure if this is a limitation of the date going from int64 to float64 to int64 as this is essentially what is happening:
(Pdb) np.round(np.array([1476705600001500000])/1.).astype('i8')
array([1476705600001499904])
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.
yes this is just losing precision - not sure much can be done
we could warn / raise potentially though
would that be useful?
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.
created a new issue. #15578
small testing addition. ping when pushed / green. |
Codecov Report
@@ Coverage Diff @@
## master #15568 +/- ##
==========================================
- Coverage 91.05% 91.03% -0.03%
==========================================
Files 137 137
Lines 49291 49291
==========================================
- Hits 44883 44873 -10
- Misses 4408 4418 +10
Continue to review full report at Codecov.
|
thanks! |
closes pandas-dev#14440 Employs @eoincondron's fix for float point inaccuracies when rounding by milliseconds for `DatetimeIndex.round` and `Timestamp.round` Author: Matt Roeschke <emailformattr@gmail.com> Closes pandas-dev#15568 from mroeschke/fix_14440 and squashes the following commits: c5a7cbc [Matt Roeschke] BUG:Floating point accuracy with DatetimeIndex.round (pandas-dev#14440)
DatetimeIndex.round
#14440git diff upstream/master | flake8 --diff
Employs @eoincondron's fix for float point inaccuracies when rounding by milliseconds for
DatetimeIndex.round
andTimestamp.round