File tree 1 file changed +6
-7
lines changed
1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change 49
49
from pandas import (
50
50
DatetimeIndex ,
51
51
Series ,
52
+ TimedeltaArray ,
52
53
TimedeltaIndex ,
53
54
)
54
55
from pandas .core .arrays .datetimelike import DatetimeLikeArrayMixin
@@ -140,10 +141,7 @@ def infer_freq(
140
141
>>> pd.infer_freq(idx)
141
142
'D'
142
143
"""
143
- from pandas .core .api import (
144
- DatetimeIndex ,
145
- Index ,
146
- )
144
+ from pandas .core .api import DatetimeIndex
147
145
148
146
if isinstance (index , ABCSeries ):
149
147
values = index ._values
@@ -173,13 +171,14 @@ def infer_freq(
173
171
inferer = _TimedeltaFrequencyInferer (index )
174
172
return inferer .get_freq ()
175
173
176
- if isinstance (index , Index ) and not isinstance (index , DatetimeIndex ):
177
- values = index ._values
174
+ if not hasattr (index , "dtype" ):
175
+ pass
176
+ elif isinstance (index .dtype , object ):
178
177
if index .dtype .kind in "iufcb" :
179
178
raise TypeError (
180
179
f"cannot infer freq from a non-convertible index of dtype { index .dtype } "
181
180
)
182
- index = values
181
+ index : TimedeltaArray = index
183
182
184
183
if not isinstance (index , DatetimeIndex ):
185
184
index = DatetimeIndex (index )
You can’t perform that action at this time.
0 commit comments