BUG: pd.cut regression since version 1.4.0 when operating on datetime
See original GitHub issuePandas 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
pd.cut(
pd.Series([pd.Timestamp('2022-02-26')]),
bins=pd.interval_range(
pd.Timestamp('2022-02-25'),
pd.Timestamp('2022-02-27'),
freq='1D',
)
).value_counts()
Issue Description
Binning is not correct in Pandas 1.4.x.
(2022-02-25, 2022-02-26] 0
(2022-02-26, 2022-02-27] 0
Note that the same series gets processed correctly, when the dtype
is not datetime64[ns]
pd.cut(
pd.Series(['2022-02-26']),
bins=pd.interval_range(
pd.Timestamp('2022-02-25'),
pd.Timestamp('2022-02-27'),
freq='1D',
)
).value_counts()
Expected Behavior
The expected behavior is
(2022-02-25, 2022-02-26] 1
(2022-02-26, 2022-02-27] 0
Installed Versions
INSTALLED VERSIONS
commit : 06d230151e6f18fdb8139d09abf539867a8cd481 python : 3.8.10.final.0 python-bits : 64 OS : Linux OS-release : 5.10.60.1-microsoft-standard-WSL2 Version : #1 SMP Wed Aug 25 23:20:18 UTC 2021 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.4.1 numpy : 1.22.1 pytz : 2021.3 dateutil : 2.8.2 pip : 22.0.3 setuptools : 60.7.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.3 IPython : 8.0.1 pandas_datareader: None bs4 : None bottleneck : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.5.1 numba : None numexpr : None odfpy : None openpyxl : 3.0.9 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:18 (13 by maintainers)
Top GitHub Comments
@simonjayhawkins you never ping me on my good commits
I think you closed the wrong one.