Skip to content

Commit

Permalink
[backport 2.3.x] CI/TST: fix parquet tz test returning pytz fixed off…
Browse files Browse the repository at this point in the history
…set (pyarrow 18) (pandas-dev#60143) (pandas-dev#60151)

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

(cherry picked from commit 9cd4a28)
  • Loading branch information
jorisvandenbossche authored Oct 31, 2024
1 parent 409837a commit fa7c87b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,16 +993,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:
request.applymarker(
pytest.mark.xfail(
reason="temporary skip this test until it is properly resolved: "
"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 @@ -1015,7 +1008,23 @@ def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
# they both implement datetime.tzinfo
# they both wrap datetime.timedelta()
# this use-case sets the resolution to 1 minute
check_round_trip(df, pa, check_dtype=False)

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):
# https://github.com/pandas-dev/pandas/issues/26551
Expand Down

0 comments on commit fa7c87b

Please sign in to comment.