Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/io/pytables/test_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down