You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I was looking at the recent ENH #4314 and there is a wrong implementation of round method for datetime.
defround(self, freq):
""" return a new Timestamp rounded to this resolution Parameters ---------- freq : a freq string indicating the rouding resolution"""
cdef int64_t unit
cdef object result, value
from pandas.tseries.frequencies import to_offset
unit = to_offset(freq).nanos
ifself.tz isnotNone:
value =self.tz_localize(None).value
else:
value =self.value
result = Timestamp(unit*np.floor(value/unit),unit='ns')
ifself.tz isnotNone:
result = result.tz_localize(self.tz)
return result
You are flooring the nano timestamp instead of rounding. You should replace np.floor by np.round.
Also I propose to add floor and ceil method to Timestamp in order to have the same behavior that float. (It is very usefull to get the upper/lower bound for a specific freq, likely more usefull than round)
hmm, though looks right. Will need some specific tests that catch this.
I would add addtl functions .ceil & .floor (with the same signature). You can of course re-use the impl completely. (just subst the functions). (maybe move the impl to a private ._round which takes the rounding function).
This is used in DatetimeIndex/TimedeltaIndex, Timestamp, Timedelta (the scalars have slightly diff impl).
Just add the this issue number onto the existing note in whatsnew.
Hi,
I was looking at the recent ENH #4314 and there is a wrong implementation of
round
method for datetime.You are flooring the nano timestamp instead of rounding. You should replace
np.floor
bynp.round
.Also I propose to add
floor
andceil
method to Timestamp in order to have the same behavior thatfloat
. (It is very usefull to get the upper/lower bound for a specific freq, likely more usefull than round)Do you agree @jreback ?
The text was updated successfully, but these errors were encountered: