Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1234,12 +1234,12 @@ Other
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
- Deprecated the keyword ``check_datetimelike_compat`` in :meth:`testing.assert_frame_equal` and :meth:`testing.assert_series_equal` (:issue:`55638`)
- Fixed bug in :meth:`DataFrame.combine` with non-unique columns (:issue:`51340`)
- Fixed bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when trying to replace :class:`NA` values in a :class:`Float64Dtype` object with ``np.nan``; this now works with ``pd.set_option("mode.nan_is_na", False)`` and is irrelevant otherwise (:issue:`55127`)
- Fixed bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when trying to replace :class:`np.nan` values in a :class:`Int64Dtype` object with :class:`NA`; this is now a no-op with ``pd.set_option("mode.nan_is_na", False)`` and is irrelevant otherwise (:issue:`51237`)
- Fixed bug in the :meth:`Series.rank` with object dtype and extremely small float values (:issue:`62036`)
- Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`)
- Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`)

.. ***DO NOT USE THIS SECTION***

-
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9041,9 +9041,9 @@ def combine(
new_columns = self.columns.union(other_columns, sort=False)
do_fill = fill_value is not None
result = {}
for col in new_columns:
series = this[col]
other_series = other[col]
for i, col in enumerate(new_columns):
series = this.iloc[:, i]
other_series = other.iloc[:, i]

this_dtype = series.dtype
other_dtype = other_series.dtype
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/frame/methods/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ def test_combine_generic(self, float_frame):
)
tm.assert_frame_equal(chunk, exp)
tm.assert_frame_equal(chunk2, exp)

def test_combine_non_unique_columns(self):
# GH#51340
df = pd.DataFrame({"A": range(5), "B": range(5)})
df.columns = ["A", "A"]

other = df.copy()
df.iloc[1, :] = 11

def combiner(a, b):
return b

result = df.combine(other, combiner)
tm.assert_frame_equal(result, other)
Loading