We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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 master branch of pandas.
import pandas as pd pd.Series( [1.0, 1.0], dtype='datetime64[ns]' ).clip( pd.Series( [None, 1.0], dtype='datetime64[ns]') )
Clipping with columns that contain NaT values raises "TypeError: '>=' not supported between instances of 'Timestamp' and 'float'".
This can be quite confusing, particularly if you're starting with float data and casting to datetime.
Ideally the error message would read: "TypeError: '>=' not supported between instances of 'Timestamp' and 'NaT'".
commit : 3e1cfc5 python : 3.9.7.final.0 python-bits : 64 OS : Darwin OS-release : 21.1.0 Version : Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8
pandas : 1.4.0.dev0+1294.g3e1cfc528c numpy : 1.21.2 pytz : 2021.3 dateutil : 2.8.2 pip : 21.2.4 setuptools : 58.0.4 Cython : 0.29.24 pytest : 6.2.5 hypothesis : 6.29.0 sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : 2.9.2 (dt dec pq3 ext lo64) jinja2 : 3.0.2 IPython : 7.28.0 pandas_datareader: None bs4 : None bottleneck : None fsspec : 2021.11.0 fastparquet : None gcsfs : None matplotlib : 3.5.0 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 5.0.0 pyxlsb : None s3fs : 2021.11.0 scipy : 1.7.3 sqlalchemy : None tables : None tabulate : None xarray : 0.19.0 xlrd : None xlwt : None numba : None
The text was updated successfully, but these errors were encountered:
Looks like this bug was introduced here: #40927 (comment)
It replaces missing values with np.inf which is not a compatible comparison with pd.Timestamp.
Until that is fixed, I'd suggest doing this:
pd.Series( [1.0, 1.0], dtype='datetime64[ns]' ).clip( pd.Series( [None, 1.0], dtype='datetime64[ns]').fillna(pd.Timestamp.min) # use pd.Timestamp.max for upper clip )
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
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 master branch of pandas.
Reproducible Example
Issue Description
Clipping with columns that contain NaT values raises "TypeError: '>=' not supported between instances of 'Timestamp' and 'float'".
This can be quite confusing, particularly if you're starting with float data and casting to datetime.
Expected Behavior
Ideally the error message would read: "TypeError: '>=' not supported between instances of 'Timestamp' and 'NaT'".
Installed Versions
INSTALLED VERSIONS
commit : 3e1cfc5
python : 3.9.7.final.0
python-bits : 64
OS : Darwin
OS-release : 21.1.0
Version : Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.4.0.dev0+1294.g3e1cfc528c
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 6.29.0
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.2 (dt dec pq3 ext lo64)
jinja2 : 3.0.2
IPython : 7.28.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.11.0
fastparquet : None
gcsfs : None
matplotlib : 3.5.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : 2021.11.0
scipy : 1.7.3
sqlalchemy : None
tables : None
tabulate : None
xarray : 0.19.0
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: