-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: infer_freq has stateful behavior #55794
Comments
Perhaps this was introduced in #51738? A call to times = pd.date_range(start="2018-08-11 20:00", end="2018-08-12 04:00", freq="H")
times = times.tz_localize(tz="America/Santiago", ambiguous='infer',
nonexistent='shift_forward')
print(pd.infer_freq(times[:3])) # H
pd.infer_freq(times)
print(pd.infer_freq(times[:3])) # None
times._engine.clear_mapping()
print(pd.infer_freq(times[:3])) # H Here is a related example: times = pd.date_range(start="2018-08-11 20:00", end="2018-08-12 04:00", freq="H")
times = times.tz_localize(tz="America/Santiago", ambiguous='infer', nonexistent='shift_forward')
print(times[:3]._is_unique) # True
times._is_unique
print(times[:3]._is_unique) # False
times._engine.clear_mapping()
print(times[:3]._is_unique) # True This |
A slightly more minimal reproducer: # last datetime is a duplicate
times = pd.to_datetime(['2019-01-01', '2019-01-02', '2019-01-03', '2019-01-03'])
print(pd.infer_freq(times[:3])) # D
pd.infer_freq(times)
print(pd.infer_freq(times[:3])) # None
times._engine.clear_mapping()
print(pd.infer_freq(times[:3])) # D |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Initially,
infer_freq
on the first 10 items of the index returnsH
, after attempting it on the full index, it returnsNone
on the first 10 items of the index. Confirmed expected behavior in version 2.0.3.Expected Behavior
Return
H
in both instances ofpd.infer_freq(times[:10])
in the example.Installed Versions
INSTALLED VERSIONS
commit : a60ad39
python : 3.10.13.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Wed Oct 4 23:56:02 PDT 2023; root:xnu-8020.240.18.704.15~1/RELEASE_ARM64_T6000
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.1.2
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.3
Cython : None
pytest : 7.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None
The text was updated successfully, but these errors were encountered: