Skip to content

REGR: DatetimeTZDtype __from_arrow__ interprets UTC values as wall time #56922

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 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ def __from_arrow__(self, array: pa.Array | pa.ChunkedArray) -> DatetimeArray:
else:
np_arr = array.to_numpy()

return DatetimeArray._from_sequence(np_arr, dtype=self, copy=False)
return DatetimeArray._simple_new(np_arr, dtype=self)

def __setstate__(self, state) -> None:
# for pickle compat. __get_state__ is defined in the
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/arrays/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_2d(self, order):
("s", "ns", "US/Central", "Asia/Kolkata", COARSE_TO_FINE_SAFE),
],
)
def test_from_arrowtest_from_arrow_with_different_units_and_timezones_with_(
def test_from_arrow_with_different_units_and_timezones_with(
pa_unit, pd_unit, pa_tz, pd_tz, data
):
pa = pytest.importorskip("pyarrow")
Expand All @@ -232,9 +232,10 @@ def test_from_arrowtest_from_arrow_with_different_units_and_timezones_with_(
dtype = DatetimeTZDtype(unit=pd_unit, tz=pd_tz)

result = dtype.__from_arrow__(arr)
expected = DatetimeArray._from_sequence(
np.array(data, dtype=f"datetime64[{pa_unit}]").astype(f"datetime64[{pd_unit}]"),
dtype=dtype,
expected = (
DatetimeArray._from_sequence(data, dtype=f"datetime64[{pa_unit}]")
.tz_localize("UTC")
Copy link
Member

Choose a reason for hiding this comment

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

  1. we can actually do better than my previous suggestion: _from_sequence(int64_data, dtype="M8[unit, UTC]").astype(...) avoids a copy in tz_localize.
  2. better to do this construction in the non-test place and use simple_new in the test.

Copy link
Member

Choose a reason for hiding this comment

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

With "in the non-test place", you mean in __from_arrow__? But there is tz_localize in there to avoid?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. we can actually do better than my previous suggestion: _from_sequence(int64_data, dtype="M8[unit, UTC]").astype(...) avoids a copy in tz_localize.

Done

  1. better to do this construction in the non-test place and use simple_new in the test.

Not sure what you mean here either. Is it OK for me to do this in a followup?

(I'd really like to release tomorrow.)

.astype(dtype, copy=False)
)
tm.assert_extension_array_equal(result, expected)

Expand Down