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

ENH: added finalize to binary operators on DataFrame, GH28283 #48551

Merged
merged 5 commits into from
Sep 19, 2022

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.

@@ -1236,6 +1236,7 @@ Metadata
^^^^^^^^
- 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