Skip to content

BUG: DataFrame constructor with a list-like dataclass (GH#41682)#66003

Draft
jbrockmendel wants to merge 1 commit into
pandas-dev:mainfrom
jbrockmendel:bug-41682
Draft

BUG: DataFrame constructor with a list-like dataclass (GH#41682)#66003
jbrockmendel wants to merge 1 commit into
pandas-dev:mainfrom
jbrockmendel:bug-41682

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

closes #41682

The DataFrame constructor decided whether a list contained dataclasses by checking only the first element (is_dataclass(data[0])) and then ran dataclasses.asdict() over the whole list. A collections.UserList subclass that is also a @dataclass satisfies is_dataclass, so a list like [MyList([1, 2, 3]), [4, 5, 6]] tried to call asdict() on the plain [4, 5, 6] and raised TypeError: asdict() should be called on dataclass instances.

Now a dataclass that is also list-like is treated as a list-like row rather than a record of fields, so such elements flow through the normal nested-list path. Plain (non-list-like) dataclasses are unaffected, and the existing intentional TypeError for a dataclass followed by a dict (GH-21910) is preserved.

A dataclass that is also list-like (e.g. a collections.UserList
subclass) is now treated as a list-like row rather than being
converted to a dict of its fields, which previously raised
TypeError when later elements were not dataclasses.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jbrockmendel jbrockmendel added Bug Constructors Series/DataFrame/Index/pd.array Constructors labels Jun 23, 2026
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 with UserList dataclass broken by upgrade to 1.1.0

1 participant