-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG/PERF: offsets.apply doesnt preserve nanosecond #7697
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
@@ -26,15 +27,17 @@ | |||
|
|||
# convert to/from datetime/timestamp to allow invalid Timestamp ranges to pass thru | |||
def as_timestamp(obj): | |||
if isinstance(obj, Timestamp): | |||
return obj | |||
if type(obj) == date: |
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.
shouldn't this be isinstance(obj, date)
? not sure if you need to include (np.datetime64,datetime,date)
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.
Because `datetimeis a subclass of
date``. Modified to use``isinstance``.
>>> dt = datetime.datetime(2011, 1, 1)
>>> isinstance(dt, datetime.date)
True
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.
Ah, Timestamp
can accept datetime.date
. Thus this check seems not to be required at all.
@sinhrks revisit? |
@jreback Rebased. Is any other thing required? |
|
Affected offset (reset nanosecond)If the aply logic includes
Affected offset (dateutil support)
|
Caused by these:
https://github.com/pydata/pandas/blob/master/pandas/tslib.pyx#784
https://github.com/pydata/pandas/blob/master/pandas/tslib.pyx#784 |
not sure what you mean (about Tick being calced more than once). The 2nd time is simply int_64 addition. AFAICT. |
Yeah all operations are necessary. What I meant is every time Actually this is not affects to performance so much, thus it is possible to leave it as normal property. |
I think that |
@sinhrks otherwise this looks ok. It just changes a lot of code so trying to review. |
OK, modified to normal |
seems, |
value = result.value | ||
result = Timestamp(value + nano) | ||
|
||
if tz is not None and result.tzinfo is None: |
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.
shouldn't this be result= tslib._localize_pydatetime(result, tz)
as well here?
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.
Because this is a flow for Timestamp
, no need to care for datetime
here.
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.
hmm, maybe add a note (or you can simply use the other routine). I found it confusing?
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.
OK. Modified to use tslib._localize_pydatetime(result, tz)
to avoid any confusion.
|
ok, ping when green |
@jreback now green. |
BUG/PERF: offsets.apply doesnt preserve nanosecond
@sinhrks thanks for this...cleans up a large amount of code..... |
Main Fix is to preserve nanosecond info which can lost during
offset.apply
, but it also includes:NOTE: This caches
Tick.delta
because it was calculated 3 times repeatedly, but does it cause any side effect?Before
After the fix