BUG: DataFrame constructor with a list-like dataclass (GH#41682)#66003
Draft
jbrockmendel wants to merge 1 commit into
Draft
BUG: DataFrame constructor with a list-like dataclass (GH#41682)#66003jbrockmendel wants to merge 1 commit into
jbrockmendel wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #41682
The
DataFrameconstructor decided whether a list contained dataclasses by checking only the first element (is_dataclass(data[0])) and then randataclasses.asdict()over the whole list. Acollections.UserListsubclass that is also a@dataclasssatisfiesis_dataclass, so a list like[MyList([1, 2, 3]), [4, 5, 6]]tried to callasdict()on the plain[4, 5, 6]and raisedTypeError: 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
TypeErrorfor a dataclass followed by a dict (GH-21910) is preserved.