Open lendres opened 9 months ago
Thanks for the report; attr propagation is only partially implemented currently. PRs to fix are welcome!
take
On main this type of Series.attr propagation is basically nonexistent. Practically, only DataFrame.attrs are accessible and get attached to the Series when the Series representation of a column is retrieved.
I would try to implement a solution that introduces hidden column_attrs to the DataFrame that would support this type of Series.attrs propagation. Solutions that only make use of the DataFrame.attrs by design either lack propagation functionality or lead to confusing behaviour.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Issue
The attrs dictionary of Series are not carried through when operations are performed on a DataFrame.
Example 1
The first series has an attr stored. However, after changing the data types, the attribute is lost.
Example 2
The first series has an attr stored. However, reassigning a column drops the attributes.
Expected Behavior
The attributes (attrs) should be maintained in the DataFrame when operations are performed on it.
Tested on 2.1.1 and 2.2.0
Installed Versions