Closed
Description
Actual behaviour
Given a RangeIndex
, the function returns 'N'
, indicating a nanosecond frequency. The function doc clearly states that a DatetimeIndex
or TimedeltaIndex
is required as an argument
>> import pandas as pd
>> pd.infer_freq((pd.RangeIndex(1, 10, 1)))
'N'
Expected behavior
A TypeError
should be raised, probably.
Possible fix
I believe the issue is in [this code block(https://github.com/pandas-dev/pandas/blob/v1.4.4/pandas/tseries/frequencies.py#L193) -> If we have an non-datetime index, we only raise an error if it's a Int64Index
or a Float64Index
Output of pd.show_versions()
Here
INSTALLED VERSIONS
------------------
commit : ca60aab7340d9989d9428e11a51467658190bb6b
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-125-generic
Version : #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.4
numpy : 1.23.2
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 44.0.0
pip : 20.0.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None