Skip to content
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

Automatic PR for 453afc92-49d7-41d2-ab1b-303dc29ea744 #86

Open
wants to merge 1 commit into
base: 453afc92-49d7-41d2-ab1b-303dc29ea744-base
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def infer_freq(
>>> pd.infer_freq(idx)
'D'
"""
from pandas.core.api import DatetimeIndex
from pandas.core.api import (
DatetimeIndex,
Index,
)

if isinstance(index, ABCSeries):
values = index._values
Expand Down Expand Up @@ -169,10 +172,15 @@ def infer_freq(
inferer = _TimedeltaFrequencyInferer(index)
return inferer.get_freq()

elif is_numeric_dtype(index.dtype):
raise TypeError(
f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
)
if isinstance(index, Index) and not isinstance(index, DatetimeIndex):
if is_numeric_dtype(index.dtype):
raise TypeError(
f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
)
# error: Incompatible types in assignment (expression has type
# "Union[ExtensionArray, ndarray[Any, Any]]", variable has type
# "Union[DatetimeIndex, TimedeltaIndex, Series, DatetimeLikeArrayMixin]")
index = index._values # type: ignore[assignment]

if not isinstance(index, DatetimeIndex):
index = DatetimeIndex(index)
Expand Down Expand Up @@ -622,4 +630,4 @@ def _is_weekly(rule: str) -> bool:
"is_subperiod",
"is_superperiod",
"to_offset",
]
]