Skip to content

Conversation

iabhi4
Copy link
Contributor

@iabhi4 iabhi4 commented May 17, 2025

BUG: Fix DataFrame constructor misclassification of array-like with 'name' attribute

Previously, any object with a .name attribute (like some vtkArray-like objects) was assumed to be a Series or Index, causing the DataFrame constructor to misinterpret the input and raise errors when passed valid 2D array-likes.

This fix ensures we only apply the named-Series/Index logic when the input is actually an instance of ABCSeries or ABCIndex, and the name is not None.

A new test was added to ensure array-like subclasses with .name are handled correctly.


iabhi4 added 2 commits May 17, 2025 15:24
…name' attribute

Previously, any object with a .name attribute (like some vtkArray-like objects) was assumed to be a Series or Index, causing the constructor to misinterpret the input.

This fix ensures we only apply the named-Index/Series logic when the input is actually an instance of ABCSeries or ABCIndex *and* has a non-None name.

Closes pandas-dev#61443.
@iabhi4
Copy link
Contributor Author

iabhi4 commented May 18, 2025

Note: One unrelated pre-commit check failed:

Check for strings with misplaced spaces.................................................................Failed
- hook id: unwanted-patterns-strings-with-misplaced-whitespace

pandas/_libs/tslibs/offsets.pyx:5112: String has a space at the beginning instead of the end of the previous string.
pandas/_libs/tslibs/offsets.pyx:5126: String has a space at the beginning instead of the end of the previous string.

One of the flagged lines includes:

f" instead.",

This has a space at the start of the string rather than the end of the previous one, which violates the unwanted-patterns-strings-with-misplaced-whitespace pre-commit rule.

Since this file wasn't touched in this PR and is unrelated to the fix, I’ve left it as-is. Let me know if you'd like me to patch it.

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.

Thanks for the PR! Can you add a line in the whatsnew for 3.0 under the Other section in bugfixes.

One unrelated pre-commit check failed

As this isn't happening on the CI, I don't think it's of concern.

@iabhi4 iabhi4 requested a review from rhshadrach May 18, 2025 21:15
@iabhi4
Copy link
Contributor Author

iabhi4 commented May 18, 2025

Thanks for the PR! Can you add a line in the whatsnew for 3.0 under the Other section in bugfixes.

Thanks for the review @rhshadrach!
Added the whatsnew entry and the GH#61443 comment in the test

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.

lgtm

@rhshadrach rhshadrach requested a review from mroeschke May 19, 2025 02:21
@rhshadrach rhshadrach added Bug Constructors Series/DataFrame/Index/pd.array Constructors labels May 19, 2025
@rhshadrach rhshadrach added this to the 3.0 milestone May 19, 2025
@mroeschke mroeschke merged commit ae8ea3e into pandas-dev:main May 19, 2025
51 of 52 checks passed
@mroeschke
Copy link
Member

Thanks @iabhi4

xaris96 pushed a commit to xaris96/pandas that referenced this pull request May 30, 2025
…name' attribute (pandas-dev#61443) (pandas-dev#61451)

* BUG: Fix DataFrame constructor misclassification of array-like with 'name' attribute

Previously, any object with a .name attribute (like some vtkArray-like objects) was assumed to be a Series or Index, causing the constructor to misinterpret the input.

This fix ensures we only apply the named-Index/Series logic when the input is actually an instance of ABCSeries or ABCIndex *and* has a non-None name.

Closes pandas-dev#61443.

* Apply pre-commit fixes: isort and remove unused type ignore

* TST/CLN: Add issue reference in test and update whatsnew for GH#61443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame constructor not compatible with array-like classes that have a 'name' attribute
3 participants