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

Timestamp .round precision for ns #15578

Closed
jreback opened this issue Mar 5, 2017 · 1 comment
Closed

Timestamp .round precision for ns #15578

jreback opened this issue Mar 5, 2017 · 1 comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Mar 5, 2017

xref https://github.com/pandas-dev/pandas/pull/15568/files#r104304074

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)

This is the unfortunate problem of converting from int64->float64->int64. I am not sure there is an easy way to fix this. We could:

  • ignore (maybe doc it)
  • raise/warn
@jreback jreback added Error Reporting Incorrect or improved errors from pandas Datetime Datetime data dtype labels Mar 5, 2017
@jreback jreback added this to the Next Major Release milestone Mar 5, 2017
@jreback
Copy link
Contributor Author

jreback commented Mar 5, 2017

so actually this is 'easy'; I think for values of round < 1us (e.g. ns values), you can simply do something like this.

simulating .round('10ns')

In [48]: i
Out[48]: DatetimeIndex(['2016-10-17 12:00:00.001501031'], dtype='datetime64[ns]', freq=None)

In [49]: DatetimeIndex(1000000 * (i.asi8 // 1000000) + 10*(np.round((i.asi8 % 1000000)/float(10))).astype('i8'))
Out[49]: DatetimeIndex(['2016-10-17 12:00:00.001501030'], dtype='datetime64[ns]', freq=None)

IOW, we avoid the float precision problem by only working with the last 6 digits, then adding back the original portion.

cc @mroeschke

mroeschke added a commit to mroeschke/pandas that referenced this issue Mar 6, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 6, 2017
mroeschke added a commit to mroeschke/pandas that referenced this issue Mar 7, 2017
@jreback jreback closed this as completed in fdee922 Mar 7, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#15578

Author: Matt Roeschke <emailformattr@gmail.com>

Closes pandas-dev#15588 from mroeschke/fix_15578 and squashes the following commits:

af95baa [Matt Roeschke] BUG: Timestamp.round precision error for ns (pandas-dev#15578)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant