Skip to content

Comparison of categorical with tuple generates wrong results #18050

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
yakupberk-sbg opened this issue Oct 31, 2017 · 4 comments · Fixed by #44245
Closed

Comparison of categorical with tuple generates wrong results #18050

yakupberk-sbg opened this issue Oct 31, 2017 · 4 comments · Fixed by #44245
Labels
Categorical Categorical Data Type good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@yakupberk-sbg
Copy link

import pandas as pd
s = pd.Series([(0, 0), (0, 1), (0, 0), (1, 0), (1, 1)])
s == (0, 0)
0     True
1    False
2     True
3    False
4    False
dtype: bool
s.astype('category') == (0, 0)
0    False
1    False
2    False
3    False
4    False
dtype: bool

Problem description

Result of s == (0, 0) and s.astype('category') == (0, 0) should be same if (0, 0) is a category.

Expected Output

s.astype('category') == (0, 0)
0     True
1    False
2     True
3    False
4    False
dtype: bool

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 17.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.21.0
pytest: 3.2.3
pip: 9.0.1
setuptools: 36.5.0
Cython: 0.26
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 5.5.0
sphinx: 1.6.3
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@TomAugspurger
Copy link
Contributor

Can you have a look at Categorical.__eq__ in

def _cat_compare_op(op):
to see which branch it's taking?

@TomAugspurger TomAugspurger added the Categorical Categorical Data Type label Oct 31, 2017
@yakupberk-sbg
Copy link
Author

is_scalar returns False and it goes to else

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Nov 1, 2017 via email

@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Jul 23, 2019
@mroeschke mroeschke added the Bug label Jun 28, 2020
@jbrockmendel jbrockmendel added the Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). label Sep 22, 2020
@mroeschke
Copy link
Member

Looks to work on master now. Could use a test

In [11]: import pandas as pd
    ...:
    ...: s = pd.Series([(0, 0), (0, 1), (0, 0), (1, 0), (1, 1)])

In [12]: s == (0, 0)
Out[12]:
0     True
1    False
2     True
3    False
4    False
dtype: bool

In [13]: s.astype('category') == (0, 0)
Out[13]:
0     True
1    False
2     True
3    False
4    False
dtype: bool

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Categorical Categorical Data Type Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). Numeric Operations Arithmetic, Comparison, and Logical operations labels Jun 12, 2021
@mroeschke mroeschke mentioned this issue Oct 31, 2021
9 tasks
@jreback jreback added this to the 1.4 milestone Oct 31, 2021
@jreback jreback added the Categorical Categorical Data Type label Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants