Skip to content
Closed
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
7 changes: 4 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3740,7 +3740,7 @@ def lookup(self, row_labels, col_labels):
# ----------------------------------------------------------------------
# Reindexing and alignment

def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy):
def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy, allow_dups):
frame = self

columns = axes["columns"]
Expand All @@ -3752,7 +3752,7 @@ def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
index = axes["index"]
if index is not None:
frame = frame._reindex_index(
index, method, copy, level, fill_value, limit, tolerance
index, method, copy, level, fill_value, limit, tolerance, allow_dups
)

return frame
Expand All @@ -3766,6 +3766,7 @@ def _reindex_index(
fill_value=np.nan,
limit=None,
tolerance=None,
allow_dups=False
):
new_index, indexer = self.index.reindex(
new_index, method=method, level=level, limit=limit, tolerance=tolerance
Expand All @@ -3774,7 +3775,7 @@ def _reindex_index(
{0: [new_index, indexer]},
copy=copy,
fill_value=fill_value,
allow_dups=False,
allow_dups=allow_dups
)

def _reindex_columns(
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3829,7 +3829,7 @@ def _is_view(self):
"""Return boolean indicating if self is view of another array """
return self._data.is_view

def reindex_like(self, other, method=None, copy=True, limit=None, tolerance=None):
def reindex_like(self, other, method=None, copy=True, limit=None, tolerance=None, allow_dups=False):
"""
Return an object with matching indices as other object.

Expand Down Expand Up @@ -3930,6 +3930,7 @@ def reindex_like(self, other, method=None, copy=True, limit=None, tolerance=None
copy=copy,
limit=limit,
tolerance=tolerance,
allow_dups=allow_dups
)

return self.reindex(**d)
Expand Down Expand Up @@ -4528,6 +4529,7 @@ def reindex(self, *args, **kwargs):
limit = kwargs.pop("limit", None)
tolerance = kwargs.pop("tolerance", None)
fill_value = kwargs.pop("fill_value", None)
allow_dups = kwargs.pop("allow_dups", False)

# Series.reindex doesn't use / need the axis kwarg
# We pop and ignore it here, to make writing Series/Frame generic code
Expand Down Expand Up @@ -4562,7 +4564,7 @@ def reindex(self, *args, **kwargs):

# perform the reindex on the axes
return self._reindex_axes(
axes, level, limit, tolerance, method, fill_value, copy
axes, level, limit, tolerance, method, fill_value, copy, allow_dups
).__finalize__(self)

def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy):
Expand All @@ -4583,7 +4585,7 @@ def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
{axis: [new_index, indexer]},
fill_value=fill_value,
copy=copy,
allow_dups=False,
allow_dups=allow_dups,
)

return obj
Expand Down
3 changes: 2 additions & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ def assert_frame_equal(
check_datetimelike_compat=False,
check_categorical=True,
check_like=False,
check_dups_index=False,
obj="DataFrame",
):
"""
Expand Down Expand Up @@ -1344,7 +1345,7 @@ def assert_frame_equal(
)

if check_like:
left, right = left.reindex_like(right), right
left, right = left.reindex_like(right,allow_dups=check_dups_index), right

# index comparison
assert_index_equal(
Expand Down