Skip to content

Commit 00993d6

Browse files
committed
BUG: Pandas can't restore index from parquet with offset-specified timezone #35997
1 parent 1a576eb commit 00993d6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pandas/_libs/tslibs/timezones.pyx

+17
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ cpdef inline tzinfo maybe_get_tz(object tz):
103103
if isinstance(tz, _dateutil_tzfile) and '.tar.gz' in tz._filename:
104104
tz._filename = zone
105105
else:
106+
if tz[0] == '-':
107+
hours = int(tz[1:3])
108+
minutes = int(tz[4:6])
109+
return pytz.FixedOffset(-60 * hours + minutes)
110+
if tz[0] == '+':
111+
hours = int(tz[1:3])
112+
minutes = int(tz[4:6])
113+
return pytz.FixedOffset(60 * hours + minutes)
114+
if tz[0:4] == 'UTC-':
115+
hours = int(tz[4:6])
116+
minutes = int(tz[7:9])
117+
return pytz.FixedOffset(-60 * hours + minutes)
118+
if tz[0:4] == 'UTC+':
119+
hours = int(tz[4:6])
120+
minutes = int(tz[7:9])
121+
return pytz.FixedOffset(60 * hours + minutes)
122+
106123
tz = pytz.timezone(tz)
107124
elif is_integer_object(tz):
108125
tz = pytz.FixedOffset(tz / 60)

pandas/tests/io/test_parquet.py

+15
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ def test_timestamp_nanoseconds(self, pa):
712712
df = pd.DataFrame({"a": pd.date_range("2017-01-01", freq="1n", periods=10)})
713713
check_round_trip(df, pa, write_kwargs={"version": "2.0"})
714714

715+
@td.skip_if_no("pyarrow", min_version="0.14")
716+
def test_timezone_aware_index(self, pa):
717+
idx = [datetime.datetime.now(datetime.timezone.utc)]
718+
df = pd.DataFrame(index=idx)
719+
check_round_trip(df, pa, write_kwargs={"version": "2.0"})
720+
715721
@td.skip_if_no("pyarrow", min_version="0.17")
716722
def test_filter_row_groups(self, pa):
717723
# https://github.com/pandas-dev/pandas/issues/26551
@@ -850,3 +856,12 @@ def test_empty_dataframe(self, fp):
850856
expected = df.copy()
851857
expected.index.name = "index"
852858
check_round_trip(df, fp, expected=expected)
859+
860+
def test_timezone_aware_index(self, fp):
861+
idx = [
862+
datetime.datetime.strptime(
863+
"2019-01-04T16:41:24+0200", "%Y-%m-%dT%H:%M:%S%z"
864+
)
865+
]
866+
df = pd.DataFrame(index=idx)
867+
check_round_trip(df, fp)

0 commit comments

Comments
 (0)