Skip to content

Commit 969b07c

Browse files
authored
BUG: PeriodIndex in pytables (#44314)
1 parent 0861da6 commit 969b07c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pandas/io/pytables.py

+8
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,14 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str):
20742074
factory: type[Index] | type[DatetimeIndex] = Index
20752075
if is_datetime64_dtype(values.dtype) or is_datetime64tz_dtype(values.dtype):
20762076
factory = DatetimeIndex
2077+
elif values.dtype == "i8" and "freq" in kwargs:
2078+
# PeriodIndex data is stored as i8
2079+
# error: Incompatible types in assignment (expression has type
2080+
# "Callable[[Any, KwArg(Any)], PeriodIndex]", variable has type
2081+
# "Union[Type[Index], Type[DatetimeIndex]]")
2082+
factory = lambda x, **kwds: PeriodIndex( # type: ignore[assignment]
2083+
ordinal=x, **kwds
2084+
)
20772085

20782086
# making an Index instance could throw a number of different errors
20792087
try:

pandas/tests/io/pytables/test_put.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,8 @@ def check(format, index):
243243
check("table", index)
244244
check("fixed", index)
245245

246-
# period index currently broken for table
247-
# seee GH7796 FIXME
248246
check("fixed", tm.makePeriodIndex)
249-
# check('table',tm.makePeriodIndex)
247+
check("table", tm.makePeriodIndex) # GH#7796
250248

251249
# unicode
252250
index = tm.makeUnicodeIndex

0 commit comments

Comments
 (0)