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 1 commit
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
22 changes: 9 additions & 13 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 @@ -977,18 +976,6 @@ def test_timestamp_nanoseconds(self, pa):
def test_timezone_aware_index(self, request, 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,15 @@ 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
import pytz
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import pytz
pytz = pytest.importorskip("pytz")

I suppose your prior import was safe since having pyarrow installed would require pytz to also be installed here? IMO would be nice to extra safe with importorskip in case that ever changes :)

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 actually first wrote it like that, but then intentionally did a plain import. Because otherwise, if we would for some reason no longer have pytz in the test builds that have pyarrow, we would silently never run this test. I would rather be notified at that point that we need pytz.

Now, while writing that, if the env doesn't have pytz, then pyarrow would actually fall back to another tz implementation. We could also write the test more generically so it does not only work with pytz. But I think at the moment we install pytz in almost all test envs?

Copy link
Member

Choose a reason for hiding this comment

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

But I think at the moment we install pytz in almost all test envs?

Yeah tests envs where we install optional dependencies will have pyarrow and pytz. Sure I'm OK then skipping the importorskip

Copy link
Member

Choose a reason for hiding this comment

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

Actually looks like we need to install pytz for the pyarrow nightly build i.e. add pyarrow to actions-311-pyarrownightly.yaml https://github.com/pandas-dev/pandas/actions/runs/11595223185/job/32283356899?pr=60143

(I guess my above comment didn't really apply to our one-off builds like the pyarrow nightly)

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, made the test robust with both with and without pytz; seems fine to test both cases


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