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

API (string dtype): implement hierarchy (NA > NaN, pyarrow > python) for consistent comparisons between different string dtypes #61138

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Mar 17, 2025

Closes #60639

This does not yet handle the case of comparison to object dtype.

  • Tests added and passed if fixing a bug or adding a new feature
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

…for consistent comparisons between different string dtypes
@jorisvandenbossche jorisvandenbossche added the Strings String extension data type and string data label Mar 17, 2025
@jorisvandenbossche jorisvandenbossche added this to the 2.3 milestone Mar 17, 2025
@jorisvandenbossche jorisvandenbossche marked this pull request as ready for review March 19, 2025 16:07
expected = pd.array([None, None, None], dtype=expected_dtype)
tm.assert_extension_array_equal(result, expected)
# # with list
# other = [None, None, "c"]
Copy link
Member

Choose a reason for hiding this comment

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

Did you want to implement testing this in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was already implemented, just need to add this case back to the test. The original "array" test was actually testing with a list. I updated the test to now actually use an array (parametrized with all the different dtypes, to get all combinations of dtypes in both operands), and added a separate test with just the list.

@jorisvandenbossche jorisvandenbossche force-pushed the string-dtype-comparison-methods-priority branch from 9a0c382 to 4ebd93b Compare March 19, 2025 18:31
@rhshadrach rhshadrach added the Numeric Operations Arithmetic, Comparison, and Logical operations label Mar 23, 2025
Comment on lines -350 to -352
result = getattr(a, op_name)(pd.NA)
expected = pd.array([None, None, None], dtype=expected_dtype)
tm.assert_extension_array_equal(result, expected)
Copy link
Member Author

Choose a reason for hiding this comment

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

For this case of comparing with NA, we already have a dedicated test just above, so removing it here

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

Needs a whatsnew?

Comment on lines 241 to 246
using_infer_string
and all_arithmetic_operators == "__radd__"
and (
(dtype.na_value is pd.NA) or (dtype.storage == "python" and HAS_PYARROW)
dtype.na_value is pd.NA
and not (not HAS_PYARROW and dtype.storage == "python")
)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This would be a bit cleaner as

using_infer_string
and all_arithmetic_operators == "__radd__"
and dtype.na_value is pd.NA
and (HAS_PYARROW or dtype.storage == "pyarrow")

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

Successfully merging this pull request may close these issues.

API (string dtype): comparisons between different string classes
3 participants