Skip to content

BUG: Inconsistent equal comparison for datetime and string #45506

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
jeff-hernandez opened this issue Jan 20, 2022 · 1 comment
Closed
2 of 3 tasks

BUG: Inconsistent equal comparison for datetime and string #45506

jeff-hernandez opened this issue Jan 20, 2022 · 1 comment
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@jeff-hernandez
Copy link
Contributor

jeff-hernandez commented Jan 20, 2022

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

data = [
    {"f_0": "2015-07-01", "f_2": "08335394550"},
    {"f_0": "2015-07-02", "f_2": "+49 (0) 0345 300033"},
    {"f_0": "2015-07-03", "f_2": "+49(0)2598 04457"},
    {"f_0": "2015-07-04", "f_2": "0741470003"},
    {"f_0": "2015-07-05", "f_2": "04181 83668"},
]

dtypes = dict(f_0='datetime64[ns]', f_2='string')
df = pd.DataFrame(data=data).astype(dtypes)
df['f_0'].eq(df['f_2'])
OverflowError: signed integer is greater than maximum

Issue Description

Applying an equal comparison between datetime and string columns can result in different behaviors. In the example above, the comparison results in an overflow error, whereas in the example below, the comparison results in the expected boolean column. Both examples compare the same data types but yield different behaviors.

data = [
    {"f_0": "2015-07-01", "f_2": "a"},
    {"f_0": "2015-07-02", "f_2": "b"},
    {"f_0": "2015-07-03", "f_2": "c"},
    {"f_0": "2015-07-04", "f_2": "d"},
    {"f_0": "2015-07-05", "f_2": "e"},
]

dtypes = dict(f_0='datetime64[ns]', f_2='string')
df = pd.DataFrame(data=data).astype(dtypes)
df['f_0'].eq(df['f_2'])
0    False
1    False
2    False
3    False
4    False
dtype: bool

Expected Behavior

I'd expect the output to also be a boolean column.

import pandas as pd

data = [
    {"f_0": "2015-07-01", "f_2": "08335394550"},
    {"f_0": "2015-07-02", "f_2": "+49 (0) 0345 300033"},
    {"f_0": "2015-07-03", "f_2": "+49(0)2598 04457"},
    {"f_0": "2015-07-04", "f_2": "0741470003"},
    {"f_0": "2015-07-05", "f_2": "04181 83668"},
]

dtypes = dict(f_0='datetime64[ns]', f_2='string')
df = pd.DataFrame(data=data).astype(dtypes)
df['f_0'].eq(df['f_2'])
0    False
1    False
2    False
3    False
4    False
dtype: bool

Installed Versions

INSTALLED VERSIONS

commit : 66e3805
python : 3.8.12.final.0
python-bits : 64
OS : Darwin
OS-release : 21.2.0
Version : Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.5
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 58.0.4
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : 2021.11.1
fastparquet : 0.5.0
gcsfs : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 6.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.54.1

@Compro-Prasad
Copy link
Contributor

Catching OverflowError at

except ValueError as err:
would be helpful.

Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 21, 2022
Exception is raised when year is greater than 32 bit signed integer

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 21, 2022
Exception is raised when year is greater than 32 bit signed integer

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 21, 2022
Exception is raised when year is greater than 32 bit signed integer

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 22, 2022
Exception is raised when year is greater than 32 bit signed integer

Added tests for this issue

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 23, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 23, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 23, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 24, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 24, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 24, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 24, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 25, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 28, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 28, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/frame/methods/test_astype.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 28, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 28, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py

TODO: Remove this when its fixed in Python
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 29, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py

TODO: Remove this when its fixed in Python
@jreback jreback added this to the 1.5 milestone Jan 29, 2022
@jreback jreback added Datetime Datetime data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 29, 2022
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 30, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 30, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py

Added whatsnew entry for v1.5.0
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 31, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py

Added whatsnew entry for v1.5.0
Compro-Prasad added a commit to Compro-Prasad/pandas that referenced this issue Jan 31, 2022
Exception is raised when a part of the date like day, month or year is greater
than 32 bit signed integer.

Added tests for this issue in pandas/tests/series/methods/test_compare.py

Added whatsnew entry for v1.5.0
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this issue Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

3 participants