Skip to content

REF: make copy keyword non-stateful #48062

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

Merged
merged 1 commit into from
Aug 15, 2022
Merged
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
16 changes: 6 additions & 10 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ def merge(
right_index=right_index,
sort=sort,
suffixes=suffixes,
copy=copy,
indicator=indicator,
validate=validate,
)
return op.get_result()
return op.get_result(copy=copy)


if __debug__:
Expand Down Expand Up @@ -623,7 +622,6 @@ def __init__(
right_index: bool = False,
sort: bool = True,
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
indicator: bool = False,
validate: str | None = None,
) -> None:
Expand All @@ -642,7 +640,6 @@ def __init__(
self.left_on = com.maybe_make_list(left_on)
self.right_on = com.maybe_make_list(right_on)

self.copy = copy
self.suffixes = suffixes
self.sort = sort

Expand Down Expand Up @@ -713,7 +710,7 @@ def __init__(
if validate is not None:
self._validate(validate)

def get_result(self) -> DataFrame:
def get_result(self, copy: bool = True) -> DataFrame:
if self.indicator:
self.left, self.right = self._indicator_pre_merge(self.left, self.right)

Expand All @@ -730,7 +727,7 @@ def get_result(self) -> DataFrame:
[(self.left._mgr, lindexers), (self.right._mgr, rindexers)],
axes=[llabels.append(rlabels), join_index],
concat_axis=0,
copy=self.copy,
copy=copy,
)

typ = self.left._constructor
Expand Down Expand Up @@ -1100,7 +1097,7 @@ def _get_merge_keys(self):
else:
# work-around for merge_asof(right_index=True)
right_keys.append(right.index)
if lk is not None and lk == rk:
if lk is not None and lk == rk: # FIXME: what about other NAs?
# avoid key upcast in corner case (length-0)
if len(left) > 0:
right_drop.append(rk)
Expand Down Expand Up @@ -1637,7 +1634,6 @@ def __init__(
right_index: bool = False,
axis: int = 1,
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
fill_method: str | None = None,
how: str = "outer",
) -> None:
Expand All @@ -1658,7 +1654,7 @@ def __init__(
sort=True, # factorize sorts
)

def get_result(self) -> DataFrame:
def get_result(self, copy: bool = True) -> DataFrame:
join_index, left_indexer, right_indexer = self._get_join_info()

llabels, rlabels = _items_overlap_with_suffix(
Expand Down Expand Up @@ -1687,7 +1683,7 @@ def get_result(self) -> DataFrame:
[(self.left._mgr, lindexers), (self.right._mgr, rindexers)],
axes=[llabels.append(rlabels), join_index],
concat_axis=0,
copy=self.copy,
copy=copy,
)

typ = self.left._constructor
Expand Down