Skip to content

Commit 859c030

Browse files
Backport PR #56922 on branch 2.2.x (REGR: DatetimeTZDtype __from_arrow__ 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]>
1 parent cc37a13 commit 859c030

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def __from_arrow__(self, array: pa.Array | pa.ChunkedArray) -> DatetimeArray:
919919
else:
920920
np_arr = array.to_numpy()
921921

922-
return DatetimeArray._from_sequence(np_arr, dtype=self, copy=False)
922+
return DatetimeArray._simple_new(np_arr, dtype=self)
923923

924924
def __setstate__(self, state) -> None:
925925
# for pickle compat. __get_state__ is defined in the

pandas/tests/arrays/datetimes/test_constructors.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_2d(self, order):
223223
("s", "ns", "US/Central", "Asia/Kolkata", COARSE_TO_FINE_SAFE),
224224
],
225225
)
226-
def test_from_arrowtest_from_arrow_with_different_units_and_timezones_with_(
226+
def test_from_arrow_with_different_units_and_timezones_with(
227227
pa_unit, pd_unit, pa_tz, pd_tz, data
228228
):
229229
pa = pytest.importorskip("pyarrow")
@@ -233,9 +233,8 @@ def test_from_arrowtest_from_arrow_with_different_units_and_timezones_with_(
233233
dtype = DatetimeTZDtype(unit=pd_unit, tz=pd_tz)
234234

235235
result = dtype.__from_arrow__(arr)
236-
expected = DatetimeArray._from_sequence(
237-
np.array(data, dtype=f"datetime64[{pa_unit}]").astype(f"datetime64[{pd_unit}]"),
238-
dtype=dtype,
236+
expected = DatetimeArray._from_sequence(data, dtype=f"M8[{pa_unit}, UTC]").astype(
237+
dtype, copy=False
239238
)
240239
tm.assert_extension_array_equal(result, expected)
241240

0 commit comments

Comments
 (0)