Skip to content

Commit fa7c87b

Browse files
[backport 2.3.x] CI/TST: fix parquet tz test returning pytz fixed offset (pyarrow 18) (#60143) (#60151)
CI/TST: fix parquet tz test returning pytz fixed offset (pyarrow 18) (#60143) * CI/TST: fix parquet tz test returning pytz fixed offset (pyarrow 18) * only convert to pytz if installed (cherry picked from commit 9cd4a28)
1 parent 409837a commit fa7c87b

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

pandas/tests/io/test_parquet.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -993,16 +993,9 @@ def test_timestamp_nanoseconds(self, pa):
993993
df = pd.DataFrame({"a": pd.date_range("2017-01-01", freq="1ns", periods=10)})
994994
check_round_trip(df, pa, write_kwargs={"version": ver})
995995

996-
def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
996+
def test_timezone_aware_index(self, pa, timezone_aware_date_list):
997997
pytest.importorskip("pyarrow", "11.0.0")
998998

999-
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
1000-
request.applymarker(
1001-
pytest.mark.xfail(
1002-
reason="temporary skip this test until it is properly resolved: "
1003-
"https://github.com/pandas-dev/pandas/issues/37286"
1004-
)
1005-
)
1006999
idx = 5 * [timezone_aware_date_list]
10071000
df = pd.DataFrame(index=idx, data={"index_as_col": idx})
10081001

@@ -1015,7 +1008,23 @@ def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
10151008
# they both implement datetime.tzinfo
10161009
# they both wrap datetime.timedelta()
10171010
# this use-case sets the resolution to 1 minute
1018-
check_round_trip(df, pa, check_dtype=False)
1011+
1012+
expected = df[:]
1013+
if pa_version_under11p0:
1014+
expected.index = expected.index.as_unit("ns")
1015+
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
1016+
# pyarrow returns pytz.FixedOffset while pandas constructs datetime.timezone
1017+
# https://github.com/pandas-dev/pandas/issues/37286
1018+
try:
1019+
import pytz
1020+
except ImportError:
1021+
pass
1022+
else:
1023+
offset = df.index.tz.utcoffset(timezone_aware_date_list)
1024+
tz = pytz.FixedOffset(offset.total_seconds() / 60)
1025+
expected.index = expected.index.tz_convert(tz)
1026+
expected["index_as_col"] = expected["index_as_col"].dt.tz_convert(tz)
1027+
check_round_trip(df, pa, check_dtype=False, expected=expected)
10191028

10201029
def test_filter_row_groups(self, pa):
10211030
# https://github.com/pandas-dev/pandas/issues/26551

0 commit comments

Comments
 (0)