Skip to content

CI/TST: fix parquet tz test returning pytz fixed offset (pyarrow 18) #60143

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 2 commits into from
Oct 30, 2024
Merged
Changes from all 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
27 changes: 13 additions & 14 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
pa_version_under13p0,
pa_version_under15p0,
pa_version_under17p0,
pa_version_under18p0,
)

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

def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
def test_timezone_aware_index(self, pa, timezone_aware_date_list):
pytest.importorskip("pyarrow", "11.0.0")

if (
timezone_aware_date_list.tzinfo != datetime.timezone.utc
and pa_version_under18p0
Copy link
Member Author

Choose a reason for hiding this comment

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

This was added in the PR removing our default usage of pytz. @mroeschke you were assuming that pyarrow would have fixed this in time for 18.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

(I changed the test to test the actual (although undesired) behaviour, just to ensure we are still testing the behaviour in general, and then this should also start failing once pyarrow fixes it, just like with the xfail)

Copy link
Member

Choose a reason for hiding this comment

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

you were assuming that pyarrow would have fixed this in time for 18.0?

I don't recall anymore; this might been an unnecessary "is pyarrow installed" check.

):
request.applymarker(
pytest.mark.xfail(
reason=(
"pyarrow returns pytz.FixedOffset while pandas "
"constructs datetime.timezone https://github.com/pandas-dev/pandas/issues/37286"
)
)
)
idx = 5 * [timezone_aware_date_list]
df = pd.DataFrame(index=idx, data={"index_as_col": idx})

Expand All @@ -1005,6 +992,18 @@ def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
expected = df[:]
if pa_version_under11p0:
expected.index = expected.index.as_unit("ns")
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
# pyarrow returns pytz.FixedOffset while pandas constructs datetime.timezone
# https://github.com/pandas-dev/pandas/issues/37286
try:
import pytz
except ImportError:
pass
else:
offset = df.index.tz.utcoffset(timezone_aware_date_list)
tz = pytz.FixedOffset(offset.total_seconds() / 60)
expected.index = expected.index.tz_convert(tz)
expected["index_as_col"] = expected["index_as_col"].dt.tz_convert(tz)
check_round_trip(df, pa, check_dtype=False, expected=expected)

def test_filter_row_groups(self, pa):
Expand Down
Loading