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] == or != between incomparable types raises TypeError instead of returning an object with True/False #18202

Open
mroeschke opened this issue Mar 7, 2025 · 0 comments
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@mroeschke
Copy link
Contributor

Describe the bug

In [1]: import pandas as pd, cudf

In [2]: cudf.Series(["s", "b"]) == cudf.Series([1, 2])
...
    113 elif isinstance(data, abc.MutableMapping):
    114     # This code path is performance-critical for copies and should be
    115     # modified with care.
    116     if data and verify:
    117         # Faster than next(iter(data.values()))
--> 118         column_length = len(data[next(iter(data))])
    119         # TODO: we should validate the keys of `data`
    120         for col in data.values():

TypeError: object of type 'bool' has no len()

In [3]: pd.Series(["s", "b"]) == pd.Series([1, 2])
Out[3]: 
0    False
1    False
dtype: bool

Expected behavior
Same as Out[3]

Additional context
Column._binarop does return NotImplemented when encountering an incomparable type to dispatch to the reflected's implementation, but if the other side return NotImplemented then we get a scalar boolean which we are not expecting.

Generally if we can narrow the inputs to _binarop to a Column (scalars get broadcast to len of the column), then we should be more aggressively raise TypeError instead of return NotImplemented for invalid type comparisons.

@mroeschke mroeschke added bug Something isn't working Python Affects Python cuDF API. labels Mar 7, 2025
@mroeschke mroeschke changed the title [BUG] == or != between incomparable types raises TypeError insted of returning an object with True/False [BUG] == or != between incomparable types raises TypeError instead of returning an object with True/False Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Affects Python cuDF API.
Projects
Status: Todo
Development

No branches or pull requests

1 participant