Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FIX BUG: Timestamp __add__/__sub__ DateOffset with nanoseconds lost. #43968
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
FIX BUG: Timestamp __add__/__sub__ DateOffset with nanoseconds lost. #43968
Changes from 15 commits
2208507
ee19a4d
3e38ab2
5718e4f
e1ae149
326790b
83453da
ae4b133
a43030d
22cadbf
1c89c03
a2ad274
9bc6e97
c9ddf14
4780316
1fecfa6
e92c1a9
006c073
ab064b4
8e42c64
5ca3472
37d19b5
5acad37
9cda54a
0ee9a6f
860a62b
4600a64
8cf5746
a210baf
98646cd
e899fbe
906f546
24fe768
209ba9e
f56f52b
3f49876
b7297ef
5cbae96
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
nitpick: can you put this inside the
if is_offset_object
and make clear it is a RelativeDelta offset, not any DateOffsetThere 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.
These lines have been moved to
RelativeDelta.apply
method.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 in principle
Timestamp.__add__
shouldn't need to know anything about the RelativeDeltaOffset implementation. Could we changeRelativeDeltaOffset.apply
to handle nanoseconds correctly instead?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, let me read the
RelativeDeltaOffset
implementation to see how should I move the logic away from 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.
Now the
RelativeDeltaOffset.apply
can handle nanoseconds correctly.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.
are there any cases that go through the
hasattr(other, "nanoseconds")
and also through 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.
If a case go through the
hasattr(other, "nanoseconds")
, it must go through here. For example,Timestampe(0) + DateOffset(nanoseconds=1)
will go through both branches. Because line 289other = other._offset
converts other to atd_scalar
.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.
Doesn't it sometimes convert to a relativedelta object (which isnt a td_scalar)?
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.
@jbrockmendel According to the codes below, we can see self._offset is a relativedelta object only if there is no nanosecond / nanoseconds keyword parameter.
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.
if im reading RelativeDeltaOffset.apply right, i think this might be off with n!=1?
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.
Let me read the
RelativeDeltaOffset.apply
codes first, and make more test cases with n!=1 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.
I changed the codes, aslo add test case with n == 5, and it works.
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.
@jbrockmendel For the question "do we have any test cases with both nano !=0 and hasattr(self, "nanoseconds")?"
When the test case is
("nanoseconds", 1, Timestamp("1970-01-01 00:00:00.000000001"))
, running L816, thusTimestamp("1970-01-01 00:00:00.000000001")
-DateOffset(nanoseconds=1)
>>> nano == 1 and hasattr(self, "nanoseconds")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.
Thanks. The case I think is uncovered is where both have a nanosecond and the DateOffset has a relativedelta component:
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.
Thanks and I think the PR can pass this test and let me add a new test case for this.
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.
The test failed, maybe I need rebase my local branch in docker from master to see why.
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.
In DateOffset._apply we call _as_datetime which drops nanos, so we need to either a) not do that or b) add them back in at some point
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.
The building doc process failed maybe because it ran the command with flag
--warnings-are-errors
as below:doc/make.py --warnings-are-errors
,and there is a warning:
warning in /home/runner/work/pandas/pandas/doc/source/whatsnew/v0.10.0.rst at block ending on line 209
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.
I ran the checks again, 2 of them failed because of
Extension Array
, which seems to have nothing to do with current PR.I actually did not change anything, but the checks failed due to building doc first and then due to Extension Array.
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.
Rebased from master branch, the errors listed as below:
Extension Array
does not have_data
attribute.@jbrockmendel It seems that all the errors above are not related with my PR, could you take a look?