Description
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