Skip to content

Conversation

cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Aug 25, 2025

This was inspired by #62063 (comment) and will relax the philosophical tension that caused the closure of pandas-dev/pandas-stubs#1288.

@jbrockmendel
Copy link
Member

Anything can be an element of a series.

@cmp0xff
Copy link
Contributor Author

cmp0xff commented Aug 25, 2025

Hi @jbrockmendel, thank you for the quick review.

The original docs can potentially imply that only scalars recognised by Pandas can be accepted as arguments in .eq, .ge, etc. And scalars recognised by Pandas means variables passing the is_scalar test.

This is not true. An Enum, for example, fails the is_scalar test, but it can be the elements of a Pandas Series, and series.eq(some_enum) works fine at runtime.

This PR aims to remove the potential misinterpretation of the original documentation.

@@ -6072,7 +6072,7 @@ def eq(

Parameters
----------
other : Series or scalar value
other : Series or scalar value (that can be the element of a Series)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parentheses added here do not help the issue since any Python object can be an element of a Series (even a Series itself can be an element of a Series!). We want to indicate that this method treats lists, tuples, ndarrays, and Series differently from any other Python object. Namely, these types will be evaluated element-by-element whereas every other Python object will be evaluated as a whole against each element of the caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

288f06e does it look better?

@cmp0xff cmp0xff requested a review from rhshadrach August 26, 2025 13:24
@rhshadrach
Copy link
Member

@cmp0xff - see #62063 (comment)

@cmp0xff
Copy link
Contributor Author

cmp0xff commented Aug 27, 2025

@cmp0xff - see #62063 (comment)

Hi, I adapted the new idea and added a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: is_scalar(Enum) gives False
3 participants