Skip to content

Commit d22b90a

Browse files
committed
Tested that merge collects metadata from only its left argument.
1 parent a12bdbd commit d22b90a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pandas/tests/generic/test_finalize.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,19 +699,24 @@ def test_merge_sets_duplication_allowance_flag(allow_duplication_on_left, allow_
699699
expected_duplication_allowance = allow_duplication_on_left and allow_duplication_on_right
700700
assert result.flags.allows_duplicate_labels == expected_duplication_allowance
701701

702-
def test_merge_collects_metadata_from_both_inputs():
702+
def test_merge_collects_metadata_from_only_its_left_input():
703703
"""
704-
Check that pandas.merge sets the metadata of its result by merging the metadata from both
705-
of its inputs.
704+
Check that pandas.merge sets the metadata of its result to a copy of the metadata from its
705+
left input.
706706
"""
707707
# Arrange
708708
left = pd.DataFrame({"test": [1]})
709-
left.attrs = {"a": 2}
709+
metadata = {"a": 2}
710+
left.attrs = metadata
711+
710712
right = pd.DataFrame({"test": [1]})
711713
right.attrs = {"b": 3}
712714

713715
# Act
714716
result = left.merge(right, how="inner", on="test")
715717

716718
# Assert
717-
assert result.attrs == {"a": 2, "b": 3}
719+
assert result.attrs == metadata
720+
# Check that the metadata from the left argument is copied, rather than shared.
721+
left.attrs = {"c": 4}
722+
assert result.attrs == metadata

0 commit comments

Comments
 (0)