Skip to content

Commit 9200c7f

Browse files
natmokvalYi Wei
authored and
Yi Wei
committed
TYP: remove ignore from pandas/tseries/frequencies.py II (pandas-dev#53120)
* remove mypy ignore[assignment] and cast index to TimedeltaArray * remove check index.dtype is an object * remove cast to TimedeltaArray
1 parent 160f968 commit 9200c7f

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

pandas/tseries/frequencies.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ def infer_freq(
140140
>>> pd.infer_freq(idx)
141141
'D'
142142
"""
143-
from pandas.core.api import (
144-
DatetimeIndex,
145-
Index,
146-
)
143+
from pandas.core.api import DatetimeIndex
147144

148145
if isinstance(index, ABCSeries):
149146
values = index._values
@@ -172,15 +169,10 @@ def infer_freq(
172169
inferer = _TimedeltaFrequencyInferer(index)
173170
return inferer.get_freq()
174171

175-
if isinstance(index, Index) and not isinstance(index, DatetimeIndex):
176-
if is_numeric_dtype(index.dtype):
177-
raise TypeError(
178-
f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
179-
)
180-
# error: Incompatible types in assignment (expression has type
181-
# "Union[ExtensionArray, ndarray[Any, Any]]", variable has type
182-
# "Union[DatetimeIndex, TimedeltaIndex, Series, DatetimeLikeArrayMixin]")
183-
index = index._values # type: ignore[assignment]
172+
elif is_numeric_dtype(index.dtype):
173+
raise TypeError(
174+
f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
175+
)
184176

185177
if not isinstance(index, DatetimeIndex):
186178
index = DatetimeIndex(index)

0 commit comments

Comments
 (0)