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

REGR: DataFrame.from_records for subclasses no longer calls subclass constructor #57008

Open
jorisvandenbossche opened this issue Jan 22, 2024 · 0 comments
Labels
Regression Functionality that used to work in a prior pandas version Subclassing Subclassing pandas objects
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Jan 22, 2024

Example

In [16]: from pandas.tests.frame.test_subclass import MySubclassWithMetadata

In [17]: df = MySubclassWithMetadata.from_records([{'a': 1, 'b': 2}])

In [18]: type(df)
Out[18]: pandas.tests.frame.test_subclass.MySubclassWithMetadata

In [19]: df.my_metadata
...
AttributeError: 'MySubclassWithMetadata' object has no attribute 'my_metadata'

With pandas 2.1.4, this works fine.

The reason for this is because from_records was updated (#52419) to use

return cls._from_mgr(mgr, axes=mgr.axes)

instead of cls(mgr) for the final dataframe construction.

I think this should probably at least use _constructor_from_mgr instead of _from_mgr (and maybe even still call the class? because in this case there is not finalize that can be called to finalize the initialization)

@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version Subclassing Subclassing pandas objects labels Jan 22, 2024
@jorisvandenbossche jorisvandenbossche added this to the 2.2.1 milestone Jan 22, 2024
@lithomas1 lithomas1 modified the milestones: 2.2.1, 2.2.2 Feb 23, 2024
@lithomas1 lithomas1 modified the milestones: 2.2.2, 2.2.3 Apr 10, 2024
@lithomas1 lithomas1 modified the milestones: 2.2.3, 2.3 Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Subclassing Subclassing pandas objects
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants