BUG: Passing original properties of DataFrame and Series subclasses to their constructors
#61101
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.
No new arguments, methods nor functions.
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.While implementing a subclass of
Dataframe, I found that in some operations, objects that subclass'sDataFrameandSeriesforget their original properties.This functionality is critical for my project so I decided to fix it. I had the following considerations:
__init__parameters in both parent classes weren't modified._namestays inSeries._metadataand their children because @540db96b. It is removed right before the calling the constructor and added again in__init__of parent class.DataFramechild must come with their respectiveSerieschild (and vice versa). Both children must contain and handle the same_metadataparameters.data=None. The example with(self, data=None, **_metadata, *args, **kwargs)was the cleanest I was able to think without having to clean*argsand**kwargs(like the old unit test in pandas/tests/frame/test_subclass.py:MySubclassWithMetadata). Not enforcingdataas the first parameter and having to clean up*argsand**kwargsfelt as wrong as adding*argsand**kwargsto__init__in both parents.My environment consist on SUSE 15.6 and Python 3.11.11
Edit: Removed WIP comments about tests and code checks.