Skip to content

BUG: PeriodIndex in pytables #44314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 6, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
mypy fixup
  • Loading branch information
jbrockmendel committed Nov 5, 2021
commit 9ad340fe1fd31388b5d3cb8804fa40e3ca1fc4e4
9 changes: 7 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2071,12 +2071,17 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str):
if self.freq is not None:
kwargs["freq"] = _ensure_decoded(self.freq)

factory: type[Index] | type[DatetimeIndex] | type[PeriodIndex] = Index
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
factory = lambda x, **kwds: PeriodIndex(ordinal=x, **kwds)
# 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