Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

sukriti1
Copy link
Contributor

@@ -997,6 +997,8 @@ def _make_na_block(
dtype = interleaved_dtype([blk.dtype for blk in self.blocks])
if dtype is not None and np.issubdtype(dtype.type, np.floating):
fill_value = dtype.type(fill_value)
if dtype is not None and np.issubdtype(dtype.type, np.datetime64):
fill_value = np.datetime64("NaT")
Copy link
Member

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

Copy link
Contributor Author

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?

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):
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

@@ -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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants