Repository: modin-project/modin

Issue:
BUG: series.name is set to None as sideeffect if series is used in an add or substract operation
### Modin version checks

- [X] I have checked that this issue has not already been reported.

- [X] I have confirmed this bug exists on the latest released version of Modin.

- [ ] I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow [this guide](https://modin.readthedocs.io/en/stable/getting_started/installation.html#installing-from-the-github-master-branch).)


### Reproducible Example

```python
# %%
import modin.pandas as pd  # 0.17.0
import pandas  # 1.5.1

# %% pandas
series_1 = pandas.Series([1, 2, 3], name="a")
series_2 = pandas.Series([3, 2, 1], name="b")
series_1 - series_2
print(series_1.name)  # "a"
print(series_2.name)  # "b"

# modin.pandas removes the series names
# %% modin.pandas - substract
series_1 = pd.Series([1, 2, 3], name="a")
series_2 = pd.Series([3, 2, 1], name="b")
series_1 - series_2
print(series_1.name)  # None instead of expected "a"
print(series_2.name)  # None instead of expected "b"


# Additional other tests which showed same results


# %% modin.pandas - substract
series_1 = pd.Series([1, 2, 3], name="a")
series_2 = pd.Series([3, 2, 1], name="b")
series_1.subtract(series_2)
print(series_1.name)  # None instead of expected "a"
print(series_2.name)  # None instead of expected "b"

# %% modin.pandas - add
series_1 = pd.Series([1, 2, 3], name="a")
series_2 = pd.Series([3, 2, 1], name="b")
series_1 + series_2
print(series_1.name)  # None instead of expected "a"
print(series_2.name)  # None instead of expected "b"

# Still correct for DataFrame
# %%
df = pandas.DataFrame({"a": [1, 2, 3]})
df - df
print(df.columns.to_list())
# %%
df = pd.DataFrame({"a": [1, 2, 3]})
df - df
print(df.columns.to_list())

```


### Issue Description

If a series is used within an add or substract operation `series + other_series`, the series and other_series get modified in a way that their name is removed.



### Expected Behavior

The expected behaviour is the one from pandas, where the name of each series in an operation stays preserved.

```python
import modin.pandas as pd
series_1 = pd.Series([1, 2, 3], name="a")
series_2 = pd.Series([3, 2, 1], name="b")
series_1 - series_2
print(series_1.name)  # "a"
print(series_2.name)  # "b"
```

### Error Logs

<details>

```python-traceback

Replace this line with the error backtrace (if applicable).

```

</details>


### Installed Versions


INSTALLED VERSIONS
------------------
commit           : e50cec12655b4a2a3decf342ab45433080d3c023
python           : 3.8.10.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.15.0-10052-tuxedo
Version          : #58~20.04.1tux1 SMP Mon Oct 24 12:05:31 UTC 2022
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

Modin dependencies
------------------
modin            : 0.17.0
ray              : 1.12.1
dask             : None
distributed      : None
hdk              : None

pandas dependencies
-------------------
pandas           : 1.5.1
numpy            : 1.23.4
pytz             : 2022.6
dateutil         : 2.8.2
setuptools       : 65.5.0
pip              : 21.1.3
Cython           : None
pytest           : 7.2.0
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.1.2
IPython          : 8.6.0
pandas_datareader: None
bs4              : 4.11.1
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : 2022.11.0
gcsfs            : None
matplotlib       : 3.5.3
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : 1.9.3
snappy           : None
sqlalchemy       : 1.3.24
tables           : None
tabulate         : 0.9.0
xarray           : None
xlrd             : None
xlwt             : None
zstandard        : None
tzdata           : None



Discussion:
@ahallermed thanks for opening the issue! I was able to reproduce the issue on the latest Modin commit. We'll take a closer look at the problem and open a fix soon!

Resolving patch:
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -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


Test patch:
diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py
--- a/modin/pandas/test/test_series.py
+++ b/modin/pandas/test/test_series.py
@@ -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)