diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index f85128ea0ca4a..8c8e9b9feeb80 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2074,6 +2074,14 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str): factory: type[Index] | type[DatetimeIndex] = Index if is_datetime64_dtype(values.dtype) or is_datetime64tz_dtype(values.dtype): factory = DatetimeIndex + elif values.dtype == "i8" and "freq" in kwargs: + # PeriodIndex data is stored as i8 + # error: Incompatible types in assignment (expression has type + # "Callable[[Any, KwArg(Any)], PeriodIndex]", variable has type + # "Union[Type[Index], Type[DatetimeIndex]]") + factory = lambda x, **kwds: PeriodIndex( # type: ignore[assignment] + ordinal=x, **kwds + ) # making an Index instance could throw a number of different errors try: diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index 3707079d03d64..f4b70bc6f238a 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -243,10 +243,8 @@ def check(format, index): check("table", index) check("fixed", index) - # period index currently broken for table - # seee GH7796 FIXME check("fixed", tm.makePeriodIndex) - # check('table',tm.makePeriodIndex) + check("table", tm.makePeriodIndex) # GH#7796 # unicode index = tm.makeUnicodeIndex