Skip to content

Fix concat failure with pandas StringDtype indexes (#11317)#11322

Open
SAY-5 wants to merge 1 commit intopydata:mainfrom
SAY-5:fix/concat-stringdtype-11317
Open

Fix concat failure with pandas StringDtype indexes (#11317)#11322
SAY-5 wants to merge 1 commit intopydata:mainfrom
SAY-5:fix/concat-stringdtype-11317

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 5, 2026

Description

Fixes #11317. When pandas returns a StringDtype-backed Index (e.g. with future.infer_string enabled or pandas 3.x defaults), passing it as the new concat dim caused _calc_concat_dim_index to store the StringDtype as the resulting PandasIndex.coord_dtype. A subsequent concat against another input with a numpy <U* coord then failed in np.result_type with TypeError: Cannot interpret '<StringDtype...>' as a data type. PandasIndex.__init__ already coerces non-allowed extension dtypes via get_valid_numpy_dtype when coord_dtype is None; this PR reuses that path for StringDtype so the resulting coord ends up as object and concat succeeds. Regression test added.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Claude. I directed the agent to localize the failure to _calc_concat_dim_index in xarray/structure/concat.py, evaluated alternative fix sites (PandasIndex.concat vs the dim-index helper), reviewed and tested the resulting patch, and confirmed the regression test fails on main and passes here.

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@welcome
Copy link
Copy Markdown

welcome Bot commented May 5, 2026

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

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.

concat fails due to StringDtype introduced by pd.Index

1 participant