Skip to content

Commit 9cd4a28

Browse files
CI/TST: fix parquet tz test returning pytz fixed offset (pyarrow 18) (pandas-dev#60143)
* CI/TST: fix parquet tz test returning pytz fixed offset (pyarrow 18) * only convert to pytz if installed
1 parent 2323b54 commit 9cd4a28

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

pandas/tests/io/test_parquet.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
pa_version_under13p0,
1818
pa_version_under15p0,
1919
pa_version_under17p0,
20-
pa_version_under18p0,
2120
)
2221

2322
import pandas as pd
@@ -974,21 +973,9 @@ def test_timestamp_nanoseconds(self, pa):
974973
df = pd.DataFrame({"a": pd.date_range("2017-01-01", freq="1ns", periods=10)})
975974
check_round_trip(df, pa, write_kwargs={"version": ver})
976975

977-
def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
976+
def test_timezone_aware_index(self, pa, timezone_aware_date_list):
978977
pytest.importorskip("pyarrow", "11.0.0")
979978

980-
if (
981-
timezone_aware_date_list.tzinfo != datetime.timezone.utc
982-
and pa_version_under18p0
983-
):
984-
request.applymarker(
985-
pytest.mark.xfail(
986-
reason=(
987-
"pyarrow returns pytz.FixedOffset while pandas "
988-
"constructs datetime.timezone https://github.com/pandas-dev/pandas/issues/37286"
989-
)
990-
)
991-
)
992979
idx = 5 * [timezone_aware_date_list]
993980
df = pd.DataFrame(index=idx, data={"index_as_col": idx})
994981

@@ -1005,6 +992,18 @@ def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
1005992
expected = df[:]
1006993
if pa_version_under11p0:
1007994
expected.index = expected.index.as_unit("ns")
995+
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
996+
# pyarrow returns pytz.FixedOffset while pandas constructs datetime.timezone
997+
# https://github.com/pandas-dev/pandas/issues/37286
998+
try:
999+
import pytz
1000+
except ImportError:
1001+
pass
1002+
else:
1003+
offset = df.index.tz.utcoffset(timezone_aware_date_list)
1004+
tz = pytz.FixedOffset(offset.total_seconds() / 60)
1005+
expected.index = expected.index.tz_convert(tz)
1006+
expected["index_as_col"] = expected["index_as_col"].dt.tz_convert(tz)
10081007
check_round_trip(df, pa, check_dtype=False, expected=expected)
10091008

10101009
def test_filter_row_groups(self, pa):

0 commit comments

Comments
 (0)