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.rst
file if fixing a bug or adding a new feature.While implementing a subclass of
Dataframe
, I found that in some operations, objects that subclass'sDataFrame
andSeries
forget 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._name
stays inSeries._metadata
and their children because @540db96b. It is removed right before the calling the constructor and added again in__init__
of parent class.DataFrame
child must come with their respectiveSeries
child (and vice versa). Both children must contain and handle the same_metadata
parameters.data=None
. The example with(self, data=None, **_metadata, *args, **kwargs)
was the cleanest I was able to think without having to clean*args
and**kwargs
(like the old unit test in pandas/tests/frame/test_subclass.py:MySubclassWithMetadata). Not enforcingdata
as the first parameter and having to clean up*args
and**kwargs
felt as wrong as adding*args
and**kwargs
to__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.