Skip to content

Commit

Permalink
Backport PR #56922 on branch 2.2.x (REGR: DatetimeTZDtype __from_arro…
Browse files Browse the repository at this point in the history
…w__ interprets UTC values as wall time) (#56962)

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

Co-authored-by: Thomas Li <[email protected]>
  • Loading branch information
meeseeksmachine and lithomas1 authored Jan 19, 2024
1 parent cc37a13 commit 859c030
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
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
7 changes: 3 additions & 4 deletions pandas/tests/arrays/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,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 @@ -233,9 +233,8 @@ 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"M8[{pa_unit}, UTC]").astype(
dtype, copy=False
)
tm.assert_extension_array_equal(result, expected)

Expand Down

0 comments on commit 859c030

Please sign in to comment.