Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
742a268
Activated test for metadata of merge operation.
aijams Sep 4, 2025
a12bdbd
Fixed error in test for merge result flags.
aijams Sep 4, 2025
d22b90a
Tested that merge collects metadata from only its left argument.
aijams Sep 4, 2025
41b3571
Added test to check whether merge_asof correctly sets the allow dupli…
aijams Sep 4, 2025
58b3c2a
Added bug fix description to documentation.
aijams Sep 5, 2025
11ebac8
Added test to check metadata handling for pandas.merge.
aijams Sep 9, 2025
24f4c8d
Added identifiers to test cases for pandas.merge.
aijams Sep 9, 2025
4381364
Modified tests for __finalize__ to respect documented merge behavior.
aijams Sep 11, 2025
bba9a13
Added type annotations to test method parameters.
aijams Sep 17, 2025
da1b0f4
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Sep 17, 2025
0d52fff
Fixed type issue for test_finalize. Added a little documentation.
aijams Sep 18, 2025
9c7b9ed
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Sep 18, 2025
9f68134
Ran ruff formatter to correct some issues.
aijams Sep 18, 2025
ff1aba5
Fixed some cosmetic issues with pre-commit hooks.
aijams Sep 19, 2025
8ece859
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Sep 19, 2025
6d216fe
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Oct 6, 2025
9b51d3e
Removed docstrings on tests.
aijams Oct 6, 2025
f2abf1f
Resolved several issues in test_finalize.
aijams Oct 7, 2025
eca7671
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Oct 7, 2025
dddc031
Fixed a couple nitpicks.
aijams Oct 7, 2025
7304a48
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Oct 8, 2025
15adcd7
Reformatted argument lists as required by ruff.
aijams Oct 8, 2025
1a8602d
Added note and removed potentially confusing docs from __fianlize__.
aijams Oct 8, 2025
c5f31ac
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Oct 9, 2025
d9b52f0
Removed trailing commas.
aijams Oct 9, 2025
47800f4
Merge remote-tracking branch 'upstream/main' into aijams-dataframe-me…
aijams Oct 14, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed docstrings on tests.
  • Loading branch information
aijams committed Oct 6, 2025
commit 9b51d3e298290fe10f09c4e1a8c206bb5b51503a
1 change: 0 additions & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,6 @@ Reshaping
- Bug in :meth:`DataFrame.unstack` producing incorrect results when manipulating empty :class:`DataFrame` with an :class:`ExtentionDtype` (:issue:`59123`)
- Bug in :meth:`concat` where concatenating DataFrame and Series with ``ignore_index = True`` drops the series name (:issue:`60723`, :issue:`56257`)
- Bug in :func:`melt` where calling with duplicate column names in ``id_vars`` raised a misleading ``AttributeError`` (:issue:`61475`)
- Bug in :meth:`DataFrame.merge` where the result of a merge does not contain any metadata or flag information from the inputs to the merge. (:issue:`28283`)
- Bug in :meth:`DataFrame.merge` where user-provided suffixes could result in duplicate column names if the resulting names matched existing columns. Now raises a :class:`MergeError` in such cases. (:issue:`61402`)
- Bug in :meth:`DataFrame.merge` with :class:`CategoricalDtype` columns incorrectly raising ``RecursionError`` (:issue:`56376`)
- Bug in :meth:`DataFrame.merge` with a ``float32`` index incorrectly casting the index to ``float64`` (:issue:`41626`)
Expand Down
11 changes: 1 addition & 10 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,21 +1139,13 @@ def get_result(self) -> DataFrame:

result = self._reindex_and_concat(join_index, left_indexer, right_indexer)

# Is this call to __finalize__ really necessary?
result = result.__finalize__(
types.SimpleNamespace(input_objs=[self.left, self.right]),
method=self._merge_type,
)

if self.indicator:
result = self._indicator_post_merge(result)

self._maybe_add_join_keys(result, left_indexer, right_indexer)

self._maybe_restore_index_levels(result)

# __finalize is responsible for copying the metadata from the inputs to merge
# to the result.
return result.__finalize__(
types.SimpleNamespace(input_objs=[self.left, self.right]), method="merge"
)
Expand All @@ -1175,8 +1167,7 @@ def _indicator_pre_merge(
self, left: DataFrame, right: DataFrame
) -> tuple[DataFrame, DataFrame]:
"""
Add one indicator column to each of the left and right inputs to a
merge operation.
Add one indicator column to each of the left and right inputs.

These columns are used to produce another column in the output of the
merge, indicating for each row of the output whether it was produced
Expand Down
45 changes: 3 additions & 42 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,30 +691,24 @@ def test_finalize_frame_series_name():
"cross",
],
)
def test_merge_sets_duplication_allowance_flag(
def test_merge_correctly_sets_duplication_allowance_flag(
how: MergeHow,
allow_on_left: bool,
allow_on_right: bool,
):
"""Check that DataFrame.merge correctly sets the allow_duplicate_labels flag
on its result.

The flag on the result should be set to true if and only if both arguments
to merge have their flags set to True.
"""
# Arrange
left = pd.DataFrame({"test": [1]}).set_flags(allows_duplicate_labels=allow_on_left)
right = pd.DataFrame({"test": [1]}).set_flags(
allows_duplicate_labels=allow_on_right,
)

# Act
if not how == "cross":
result = left.merge(right, how=how, on="test")
else:
result = left.merge(right, how=how)

# Assert
expected_duplication_allowance = allow_on_left and allow_on_right
assert result.flags.allows_duplicate_labels == expected_duplication_allowance

Expand All @@ -723,64 +717,44 @@ def test_merge_sets_duplication_allowance_flag(
["allow_on_left", "allow_on_right"],
[(False, False), (False, True), (True, False), (True, True)],
)
def test_merge_asof_sets_duplication_allowance_flag(
def test_merge_asof_correctly_sets_duplication_allowance_flag(
allow_on_left: bool,
allow_on_right: bool,
):
"""Check that pandas.merge_asof correctly sets the allow_duplicate_labels flag
on its result.

The flag on the result should be set to true if and only if both arguments
to merge_asof have their flags set to True.
"""
# Arrange
left = pd.DataFrame({"test": [1]}).set_flags(allows_duplicate_labels=allow_on_left)
right = pd.DataFrame({"test": [1]}).set_flags(
allows_duplicate_labels=allow_on_right,
)

# Act
result = pd.merge_asof(left, right)

# Assert
expected_duplication_allowance = allow_on_left and allow_on_right
assert result.flags.allows_duplicate_labels == expected_duplication_allowance


def test_merge_propagates_metadata_from_equal_input_metadata():
"""Check that pandas.merge sets the metadata of its result to a deep copy of
the metadata from its left input, if the metadata from both inputs are equal.
"""
# Arrange
metadata = {"a": 2}
left = pd.DataFrame({"test": [1]})
left.attrs = metadata
right = pd.DataFrame({"test": [1]})
right.attrs = metadata.copy()

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

# Assert
assert result.attrs == metadata
# Verify that merge deep-copies the attr dictionary.
left.attrs = {"b": 3}
assert result.attrs == metadata


def test_merge_does_not_propagate_metadata_from_unequal_input_metadata():
"""Check that the metadata for the result of pandas.merge is empty if the
metadata for both inputs to pandas.merge are not equal.
"""
# Arrange
left = pd.DataFrame({"test": [1]})
left.attrs = {"a": 2}
right = pd.DataFrame({"test": [1]})
right.attrs = {"b": 3}

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

# Assert
assert result.attrs == {}


Expand All @@ -804,19 +778,6 @@ def test_merge_does_not_propagate_metadata_if_one_input_has_no_metadata(
right: pd.DataFrame,
expected: dict,
):
"""Check that if the metadata for one input to pandas.merge is empty, the result
of merge has the same metadata as the other input.

(empty) (A) (A) (empty) (empty) (empty)
| | | | | |
--> merge <-- --> merge <-- --> merge <--
| | |
(empty) (empty) (empty)
"""
# Arrange

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

# Assert
assert result.attrs == expected