Skip to content

BUG: comparing None and Datetime throws error in pandas 2.1.0 #54870

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

Closed
2 of 3 tasks
htulipe opened this issue Aug 30, 2023 · 1 comment · Fixed by #54880
Closed
2 of 3 tasks

BUG: comparing None and Datetime throws error in pandas 2.1.0 #54870

htulipe opened this issue Aug 30, 2023 · 1 comment · Fixed by #54880
Labels
Bug Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@htulipe
Copy link

htulipe commented Aug 30, 2023

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

import pandas as pd

# A dataframe with a datetime column
df = pd.DataFrame({"dates": ["2020-01-01", "2020-01-02", "2020-01-03"]})
df["dates"] = pd.to_datetime(df["dates"])

# A series with None values
date_series = pd.Series([None, None, None])

# This works in pandas 2.0.3 (empty dataframe) but raise in pandas 2.1.0
df = df[(date_series > df["dates"])]

Issue Description

I have some code similar to above code sample where I filter a dataframe by comparing a series of datetime to one of its datetime columns. For some reasons irrelevant to this issue, the series can contain None values.

By updating to pandas 2.1.0, my code breaks in such conditions with following error:

TypeError: '<' not supported between instances of 'Timestamp' and 'NoneType'

Expected Behavior

I'd expect to work as in 2.0.3 where I would get an empty dataframe

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.10.1.final.0
python-bits : 64
OS : Darwin
OS-release : 22.3.0
Version : Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8

pandas : 2.0.3
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 58.1.0
pip : 23.2.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 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : 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
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
None

@htulipe htulipe added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 30, 2023
@phofl phofl added this to the 2.1.1 milestone Aug 30, 2023
@phofl phofl added Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 30, 2023
@htulipe
Copy link
Author

htulipe commented Sep 4, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants