Skip to content

Commit

Permalink
FIX-modin-project#5232: Stop changing original series names during bi…
Browse files Browse the repository at this point in the history
…nary ops. (modin-project#5249)

Signed-off-by: mvashishtha <mahesh@ponder.io>
Co-authored-by: Anatoly Myachev <anatoliimyachev@mail.com>
  • Loading branch information
mvashishtha and anmyachev committed Nov 24, 2022
1 parent 317bd75 commit 6d5545f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 9 additions & 6 deletions modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2409,12 +2409,15 @@ def _prepare_inter_op(self, other):
Prepared `other`.
"""
if isinstance(other, Series):
# NB: deep=False is important for performance bc it retains obj.index._id
new_self = self.copy(deep=False)
new_other = other.copy(deep=False)
if self.name == other.name:
new_self.name = new_other.name = self.name
else:
names_different = self.name != other.name
# NB: if we don't need a rename, do the interaction with shallow
# copies so that we preserve obj.index._id. It's fine to work
# with shallow copies because we'll discard the copies but keep
# the result after the interaction opreation. We can't do a rename
# on shallow copies because we'll mutate the original objects.
new_self = self.copy(deep=names_different)
new_other = other.copy(deep=names_different)
if names_different:
new_self.name = new_other.name = MODIN_UNNAMED_SERIES_LABEL
else:
new_self = self
Expand Down
11 changes: 11 additions & 0 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,17 @@ def test_add(data):
inter_df_math_helper(modin_series, pandas_series, "add")


def test_add_does_not_change_original_series_name():
# See https://github.com/modin-project/modin/issues/5232
s1 = pd.Series(1, name=1)
s2 = pd.Series(2, name=2)
original_s1 = s1.copy(deep=True)
original_s2 = s2.copy(deep=True)
_ = s1 + s2
df_equals(s1, original_s1)
df_equals(s2, original_s2)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_add_prefix(data):
modin_series, pandas_series = create_test_series(data)
Expand Down

0 comments on commit 6d5545f

Please sign in to comment.