Skip to content

TST: Add tests to ensure proper conversion of datetime64/timedelta64/timestamp/duration to and from pyarrow #54356

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

Merged
merged 16 commits into from
Aug 9, 2023
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pandas/tests/frame/methods/test_convert_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,18 @@ def test_convert_dtypes_pyarrow_to_np_nullable(self):
result = ser.convert_dtypes(dtype_backend="numpy_nullable")
expected = pd.DataFrame(range(2), dtype="Int32")
tm.assert_frame_equal(result, expected)

def test_convert_dtypes_timestamp_and_duration(self):
# GH 54191
pytest.importorskip("pyarrow")
timestamp_series = pd.Series(
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 mirror the exact code snippet in #54191 (comment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what you're referencing right?
s = pd.Series(pd.date_range("2020-01-01", "2020-01-02", freq="1min"))
s = s.astype("timestamp[ms][pyarrow]")
t = s.convert_dtypes(dtype_backend="pyarrow")
pd.testing.assert_series_equal(s, t)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

pd.date_range("2020-01-01", "2020-01-02", freq="1440min")
).astype("timestamp[ms][pyarrow]")
duration_series = pd.Series(pd.timedelta_range("1s", "2s", freq="1s")).astype(
"duration[ms][pyarrow]"
)

expected = pd.concat([timestamp_series, duration_series], axis=1)
result = expected.convert_dtypes(dtype_backend="pyarrow")

tm.assert_frame_equal(expected, result)