-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
timedelta on datetime df, series arithmetic #59844
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1038,9 +1038,9 @@ def test_frame_with_frame_reindex(self): | |
[ | ||
(1, "i8"), | ||
(1.0, "f8"), | ||
(2**63, "f8"), | ||
(2 ** 63, "f8"), | ||
(1j, "complex128"), | ||
(2**63, "complex128"), | ||
(2 ** 63, "complex128"), | ||
(True, "bool"), | ||
(np.timedelta64(20, "ns"), "<m8[ns]"), | ||
(np.datetime64(20, "ns"), "<M8[ns]"), | ||
|
@@ -1147,6 +1147,33 @@ def test_arithmetic_midx_cols_different_dtypes_different_order(self): | |
expected = DataFrame([[-1, 1], [-1, 1]], columns=midx) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.xfail(reason="NaT op NaT results in datetime instead of timedelta") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbrockmendel in this test, the comparison fails because the result dtype value of NaT is datetime64 and expected dtype value of NaT is Timedelta. I would expect NaT - NaT to result in Timedelta. Is this behavior expected? |
||
def test_arithmetic_datetime_df_series(self): | ||
# GH#59529 | ||
df_datetime = DataFrame([[1, 2], [3, 4]]).astype("datetime64[ns]") | ||
ser_datetime = Series([5, 6, 7]).astype("datetime64[ns]") | ||
result = df_datetime - ser_datetime | ||
expected = DataFrame( | ||
[ | ||
[pd.Timedelta(-4), pd.Timedelta(-4), pd.Timedelta(pd.NaT)], | ||
[pd.Timedelta(-2), pd.Timedelta(-2), pd.Timedelta(pd.NaT)], | ||
] | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.xfail(reason="NaT op NaT results in datetime instead of timedelta") | ||
def test_arithmetic_timestamp_timedelta(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC these tests are mainly about the alignment behavior, so they belong in something like tests.frame.test_arithmetic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests are currently in pandas/tests/frame/test_arithmetic.py. Should they be moved somewhere else? |
||
# GH#59529 | ||
df_timestamp = DataFrame([pd.Timestamp(1)]) | ||
ser_timedelta = Series([pd.Timedelta(2), pd.Timedelta(3)]) | ||
result = df_timestamp - ser_timedelta | ||
expected = DataFrame( | ||
[ | ||
[pd.Timestamp(-1), pd.NaT], | ||
] | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_frame_with_zero_len_series_corner_cases(): | ||
# GH#28600 | ||
|
@@ -1913,7 +1940,7 @@ def test_pow_with_realignment(): | |
left = DataFrame({"A": [0, 1, 2]}) | ||
right = DataFrame(index=[0, 1, 2]) | ||
|
||
result = left**right | ||
result = left ** right | ||
expected = DataFrame({"A": [np.nan, 1.0, np.nan]}) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
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.
can you also pass an appropriate unit to np.datetime64
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 for the feedback! I was wondering what do you mean by unit?