Skip to content

Commit

Permalink
TYP: remove ignore from pandas/tseries/frequencies.py II (pandas-dev#…
Browse files Browse the repository at this point in the history
…53120)

* remove mypy ignore[assignment] and cast index to TimedeltaArray

* remove check index.dtype is an object

* remove cast to TimedeltaArray
  • Loading branch information
natmokval authored and im-vinicius committed Jul 8, 2023
1 parent 83ea3b4 commit 246a432
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ def infer_freq(
>>> pd.infer_freq(idx)
'D'
"""
from pandas.core.api import (
DatetimeIndex,
Index,
)
from pandas.core.api import DatetimeIndex

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

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]
elif is_numeric_dtype(index.dtype):
raise TypeError(
f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
)

if not isinstance(index, DatetimeIndex):
index = DatetimeIndex(index)
Expand Down

0 comments on commit 246a432

Please sign in to comment.