Skip to content

Speed up StringDtype arrow implementation for merge #54510

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

Merged
merged 5 commits into from
Aug 22, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,13 +2407,16 @@ def _factorize_keys(
or is_string_dtype(lk.dtype)
and not sort
)
or (is_string_dtype(lk.dtype) and lk.dtype.storage == "pyarrow") # type: ignore[attr-defined] # noqa: E501
Copy link
Member

Choose a reason for hiding this comment

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

would using isinstance(lk.dtype, StringDtype) fix the mypy complaint? (and possibly be more robust to object dtype cases?)

Copy link
Member Author

Choose a reason for hiding this comment

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

You still have to check the storage (python strings...)

Copy link
Member

Choose a reason for hiding this comment

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

yes but doing the isinstace check instead of is_string_dtype then makes the mypy complaint go away? (and excludes object dtype and is just better in general)

Copy link
Member Author

Choose a reason for hiding this comment

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

ah got you, done

):
lk, _ = lk._values_for_factorize()

# error: Item "ndarray" of "Union[Any, ndarray]" has no attribute
# "_values_for_factorize"
rk, _ = rk._values_for_factorize() # type: ignore[union-attr]
elif isinstance(lk.dtype, ArrowDtype) and is_string_dtype(lk.dtype):
elif (isinstance(lk.dtype, ArrowDtype) and is_string_dtype(lk.dtype)) or (
is_string_dtype(lk.dtype) and lk.dtype.storage == "pyarrow" # type: ignore[attr-defined] # noqa: E501
):
import pyarrow as pa
import pyarrow.compute as pc

Expand Down