Skip to content

Conversation

@seljaks
Copy link
Contributor

@seljaks seljaks commented Sep 14, 2022

Adds metadata propagation to binary operators on pd.DataFrame
Behavior is consistent with binary operators between two pd.Series i.e. if two DataFrames both have .attrs, result will have .attrs of left-hand operand.
Example:

import pandas as pd
left = pd.DataFrame({"A": [1]})
right = pd.DataFrame({"A": [2]})
left.attrs = {"a": 1}
right.attrs = {"b": 1}
result = left + right
assert result.attrs == left.attrs

If operands are a pd.DataFrame and a pd.Series then result.attrs == pd.DataFrame.attrs regardless of ordering.

^^^^^^^^
- Fixed metadata propagation in :meth:`DataFrame.melt` (:issue:`28283`)
- Fixed metadata propagation in :meth:`DataFrame.explode` (:issue:`28283`)
- Fixed metadata propagation for binary operators on :class:`DataFrame` (:issue:`28283`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to v1.6.0.rst?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to v1.6.0.rst. Wasn't exactly sure where to put it, please let me know if it's ok.

@mroeschke mroeschke added Numeric Operations Arithmetic, Comparison, and Logical operations metadata _metadata, .attrs labels Sep 15, 2022
@seljaks seljaks requested a review from mroeschke September 18, 2022 12:36
@mroeschke mroeschke added this to the 1.6 milestone Sep 19, 2022
@mroeschke mroeschke merged commit 3038c6e into pandas-dev:main Sep 19, 2022
@mroeschke
Copy link
Member

Thanks @seljaks

@mroeschke mroeschke modified the milestones: 1.6, 2.0 Oct 13, 2022
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
…-dev#48551)

* ENH/TST/DOC: Added finalize to DataFrame binary ops, GH28283

* ENH/TST/DOC: Added finalize to DataFrame binary ops, GH28283

* TST: fix not implemented tests

* DOC: moved mention to whatsnew 1.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metadata _metadata, .attrs Numeric Operations Arithmetic, Comparison, and Logical operations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants