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: Fix inconsistency of converting empty categorical with dtype_backend='pyarrow' #61131

Merged
merged 11 commits into from
Mar 17, 2025

Conversation

yuanx749
Copy link
Contributor

Follows up #59935

@@ -1143,6 +1143,7 @@ def convert_dtypes(
base_dtype.kind == "O" # type: ignore[union-attr]
and input_array.size > 0
and isna(input_array).all()
and not isinstance(input_array.dtype, CategoricalDtype)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could you put this check above the isna(...).all() check as it's less expensive?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, could you properly add an elif isinstance(inferred_dtype, CategoricalDtype) clause for this type in the above if/else branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to the outer if branch, to skip the arrow dtype conversion for CategoricalDtype.

As mentioned in #59934, the expected behavior of convert_dtypes for CategoricalDtype series essentially ignores the requested pyarrow backend conversion.

@mroeschke mroeschke added this to the 3.0 milestone Mar 17, 2025
@mroeschke mroeschke added Dtype Conversions Unexpected or buggy dtype conversions Categorical Categorical Data Type labels Mar 17, 2025
@mroeschke mroeschke merged commit 882fa9c into pandas-dev:main Mar 17, 2025
48 checks passed
@mroeschke
Copy link
Member

Thanks @yuanx749

@yuanx749 yuanx749 deleted the convert-dtype-pyarrow branch March 17, 2025 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
3 participants