PeriodIndex given. Check the `freq` attribute instead of using infer_freq.
Package:
pandas
30911

Exception Class:
TypeError
Raise code
index = values
inferer: _FrequencyInferer
if not hasattr(index, "dtype"):
pass
elif is_period_dtype(index.dtype):
raise TypeError(
"PeriodIndex given. Check the `freq` attribute "
"instead of using infer_freq."
)
elif is_timedelta64_dtype(index.dtype):
# Allow TimedeltaIndex and TimedeltaArray
inferer = _TimedeltaFrequencyInferer(index, warn=warn)
return inferer.get_freq()
if
Links to the raise (1)
https://github.com/pandas-dev/pandas/blob/b3e335254f46a526ee3ce9bb757eac4011d9d1fe/pandas/tseries/frequencies.py#L176Ways to fix
Summary: use DatetimeIndex or TimedeltaIndex instead of PeriodIndex as the data type for the "index" function parameter
Code to reproduce (WRONG):
from pandas.tseries import frequencies
import pandas as pd
idx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3])
frequencies.infer_freq(idx)
Working version (Fixed)
from pandas.tseries import frequencies
import pandas as pd
idx = pd.date_range(start='2020/01/01', end='2020/08/30', periods=30) # <--- Fix this is an example from the frequencies.py. The date_range function return DatatimeIndex which is expected for the "index" parameter that is passed to infer_freq function
frequencies.infer_freq(idx)
Add a possible fix
Please authorize to post fix