Skip to content
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: datetime64 can't be compared with pyarrow-backed variant #60937

Open
3 tasks done
MarcoGorelli opened this issue Feb 15, 2025 · 3 comments
Open
3 tasks done

BUG: datetime64 can't be compared with pyarrow-backed variant #60937

MarcoGorelli opened this issue Feb 15, 2025 · 3 comments
Assignees
Labels
Bug Datetime Datetime data dtype Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@MarcoGorelli
Copy link
Member

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

df = pd.DataFrame({'a': pd.to_datetime(pd.Series(['2020-01-01']))})
df['b'] = df['a'].convert_dtypes(dtype_backend='pyarrow')
print(df['b'] < df['a'])

Issue Description

Should the above be supported? it currently raises

Expected Behavior

i think

0    False
dtype: bool[pyarrow]

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.12.6
python-bits : 64
OS : Linux
OS-release : 5.15.167.4-microsoft-standard-WSL2
Version : #1 SMP Tue Nov 5 00:21:55 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8

pandas : 2.2.3
numpy : 2.2.3
pytz : 2025.1
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : 8.31.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.2.0
html5lib : None
hypothesis : 6.125.2
gcsfs : None
jinja2 : 3.1.5
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 19.0.0
pyreadstat : None
pytest : 8.3.4
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None

@MarcoGorelli MarcoGorelli added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 15, 2025
@abhigyan631
Copy link

I think this fix can be used

import pandas as pd

df = pd.DataFrame({'a': pd.to_datetime(pd.Series(['2020-01-01']))})

df['b'] = df['a'].convert_dtypes(dtype_backend='pyarrow')

df['b'] = df['b'].astype('datetime64[ns]') # Convert 'b' back to datetime64[ns]

print(df['b'] < df['a'])

We need to convert the PyArrow-backed column (df['b']) back to a NumPy-backed datetime64[ns] type before performing the comparison to get the expected result.

@rhshadrach
Copy link
Member

I think the discussion in #60639 implies that yes, this should be supported.

@rhshadrach rhshadrach added Datetime Datetime data dtype Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 16, 2025
@AshleySonny
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

4 participants