-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Timestamp rounding wrong implementation fixed #11963 #11964
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
Conversation
attribs = self._get_attributes_dict() | ||
if 'freq' in attribs: | ||
attribs['freq'] = None | ||
if 'tz' in attribs: |
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.
pls reuse the existing code rather than repeating, e.g. something like:
def _round(self, freq, rounder):
from pandas.tseries.frequencies import to_offset
unit = to_offset(freq).nanos
if getattr(self,'tz',None) is not None:
values = self.tz_localize(None).asi8
else:
values = self.asi8
result = (unit*rounder(values/unit)).astype('i8')
attribs = self._get_attributes_dict()
if 'freq' in attribs:
result = result.tz_localize(self.tz)
return result
def round(self, freq):
return self._round(freq, np.round)
def floor(self, freq):
return self._round(freq, np.floor)
furtther use an Appender on the doc-string to avoid repeating
pls update |
----- | ||
For values exactly halfway between rounded decimal values, | ||
Numpy rounds to the nearest even value. Thus the new Timedelta | ||
may be lower than the original Timedelta. | ||
""" |
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.
@jreback please note the warning I add in the round
documentation about rounding of float
. The behaviour is slightly different than the arithmetical definition but it refers to Numpy implementation
looks good. small comments. pls run |
ping on green. |
I think it's okay |
merged via 4437e9c |
closes #11963