Repository: modin-project/modin

Issue:
BUG: shift on named series cause  ValueError: Length mismatch
### 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.

- [X] 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


`shift(1)` works on Dataframe
```python
ser = pd.DataFrame(np.arange(16).reshape(-1,4), columns=list(range(4)), index=[0,1,2,0])
print(ser.shift(1))
```

However failed on Series:

```python
ser[0].shift(1)
```

relate to : https://github.com/modin-project/modin/issues/4255, https://github.com/modin-project/modin/issues/3292



### Issue Description

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
e:\Workspace\github_me\binance_quant\2. binance_quant.ipynb Cell 58 in <cell line: 1>()
----> 1 ser[0].shift(1)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\logging\logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
    113 """
    114 Compute function with logging if Modin logging is enabled.
    115 
   (...)
    125 Any
    126 """
    127 if LogMode.get() == "disable":
--> 128     return obj(*args, **kwargs)
    130 logger = get_logger()
    131 logger_level = getattr(logger, log_level)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\pandas\series.py:1354, in Series.shift(self, periods, freq, axis, fill_value)
   1348 def shift(
   1349     self, periods=1, freq=None, axis=0, fill_value=None
   1350 ):  # noqa: PR01, RT01, D200
   1351     """
   1352     Shift index by desired number of periods with an optional time `freq`.
   1353     """
-> 1354     return super(type(self), self).shift(
   1355         periods=periods, freq=freq, axis=axis, fill_value=fill_value
   1356     )

File c:\Users\ufo\anaconda3\lib\site-packages\modin\logging\logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
    113 """
    114 Compute function with logging if Modin logging is enabled.
    115 
   (...)
    125 Any
    126 """
    127 if LogMode.get() == "disable":
--> 128     return obj(*args, **kwargs)
    130 logger = get_logger()
    131 logger_level = getattr(logger, log_level)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\_compat\pandas_api\latest\base.py:390, in LatestCompatibleBasePandasDataset.shift(self, periods, freq, axis, fill_value)
    385         nan_values[name] = (
    386             pandas.NAT if is_datetime_or_timedelta_dtype(dtype) else pandas.NA
    387         )
    389     fill_value = nan_values
--> 390 return self._shift(periods=periods, freq=freq, axis=axis, fill_value=fill_value)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\logging\logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
    113 """
    114 Compute function with logging if Modin logging is enabled.
    115 
   (...)
    125 Any
    126 """
    127 if LogMode.get() == "disable":
--> 128     return obj(*args, **kwargs)
    130 logger = get_logger()
    131 logger_level = getattr(logger, log_level)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\pandas\base.py:2607, in BasePandasDataset._shift(self, periods, freq, axis, fill_value)
   2601 if axis == "index" or axis == 0:
   2602     new_frame = (
   2603         pd.concat([filled_df, self.iloc[:-periods]], ignore_index=True)
   2604         if periods > 0
   2605         else pd.concat([self.iloc[-periods:], filled_df], ignore_index=True)
   2606     )
-> 2607     new_frame.index = self.index.copy()
   2608     if isinstance(self, DataFrame):
   2609         new_frame.columns = self.columns.copy()

File c:\Users\ufo\anaconda3\lib\site-packages\modin\pandas\base.py:548, in BasePandasDataset._set_index(self, new_index)
    539 def _set_index(self, new_index):
    540     """
    541     Set the index for this DataFrame.
    542 
   (...)
    546         The new index to set this.
    547     """
--> 548     self._query_compiler.index = new_index

File c:\Users\ufo\anaconda3\lib\site-packages\modin\core\storage_formats\pandas\query_compiler.py:103, in _set_axis.<locals>.set_axis(self, idx)
    102 def set_axis(self, idx):
--> 103     self._modin_frame.index = idx

File c:\Users\ufo\anaconda3\lib\site-packages\modin\core\dataframe\pandas\dataframe\dataframe.py:400, in PandasDataframe._set_index(self, new_index)
    398     self._index_cache = ensure_index(new_index)
    399 else:
--> 400     new_index = self._validate_set_axis(new_index, self._index_cache)
    401     self._index_cache = new_index
    402 self.synchronize_labels(axis=0)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\logging\logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
    113 """
    114 Compute function with logging if Modin logging is enabled.
    115 
   (...)
    125 Any
    126 """
    127 if LogMode.get() == "disable":
--> 128     return obj(*args, **kwargs)
    130 logger = get_logger()
    131 logger_level = getattr(logger, log_level)

File c:\Users\ufo\anaconda3\lib\site-packages\modin\core\dataframe\pandas\dataframe\dataframe.py:350, in PandasDataframe._validate_set_axis(self, new_labels, old_labels)
    348 new_len = len(new_labels)
    349 if old_len != new_len:
--> 350     raise ValueError(
    351         f"Length mismatch: Expected axis has {old_len} elements, "
    352         + f"new values have {new_len} elements"
    353     )
    354 return new_labels

ValueError: Length mismatch: Expected axis has 2 elements, new values have 4 elements
```

### Expected Behavior

series shift 


### Error Logs

<details>

```python-traceback

Replace this line with the error backtrace (if applicable).

```

</details>


### Installed Versions

<details>

INSTALLED VERSIONS
------------------
commit           : 7f801adce1b204469bdf95fae82b110d6cf59299
python           : 3.8.8.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.19041
machine          : AMD64
processor        : AMD64 Family 25 Model 33 Stepping 0, AuthenticAMD
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : Chinese (Simplified)_China.936

Modin dependencies
------------------
modin            : 0.17.1
ray              : 2.0.0
dask             : 2022.01.1
distributed      : 2022.01.1
hdk              : None

pandas dependencies
-------------------
pandas           : 1.5.2
numpy            : 1.23.4
pytz             : 2021.1
dateutil         : 2.8.1
setuptools       : 65.5.0
pip              : 22.3.1
Cython           : 0.29.23
pytest           : 6.2.3
hypothesis       : None
sphinx           : 4.0.1
blosc            : None
feather          : 0.4.1
xlsxwriter       : 1.3.8
lxml.etree       : 4.6.3
html5lib         : 1.1
pymysql          : 1.0.2
psycopg2         : 2.9.3
jinja2           : 3.1.2
IPython          : 8.4.0
pandas_datareader: None
bs4              : 4.9.3
bottleneck       : 1.3.5
brotli           : 
fastparquet      : 2022.11.0
fsspec           : 2021.07.0
gcsfs            : None
matplotlib       : 3.5.3
numba            : 0.53.0
numexpr          : None
odfpy            : None
openpyxl         : 3.0.7
pandas_gbq       : None
pyarrow          : 7.0.0
pyreadstat       : None
pyxlsb           : None
s3fs             : 2021.07.0
scipy            : 1.9.3
snappy           : 
sqlalchemy       : 1.4.7
tables           : None
tabulate         : 0.8.10
xarray           : None
xlrd             : 2.0.1
xlwt             : 1.3.0
zstandard        : None
tzdata           : None

</details>



Discussion:
Hi @eromoe , thanks for opening this issue! I was able to reproduce the issue you're facing on the latest version of Modin. We'll take a look at the issue and come up with a fix ASAP!
Someone on StackOverflow bumped into this issue here - https://stackoverflow.com/questions/75803926/why-does-df-shift-not-work-when-using-modin
@vnlitvinov could you take a look into it and do an initial triage of what's causing the issue?

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -2811,7 +2811,7 @@ def shift(
         filled_df = (
             self.__constructor__(index=fill_index, columns=fill_columns)
             if isinstance(self, DataFrame)
-            else self.__constructor__(index=fill_index)
+            else self.__constructor__(index=fill_index, name=self.name)
         )
         if fill_value is not None:
             filled_df.fillna(fill_value, inplace=True)
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -1403,7 +1403,7 @@ def slice_shift(self, periods=1, axis=0):  # noqa: PR01, RT01, D200
 
         if axis == "index" or axis == 0:
             if abs(periods) >= len(self.index):
-                return self.__constructor__(dtype=self.dtype)
+                return self.__constructor__(dtype=self.dtype, name=self.name)
             else:
                 new_df = self.iloc[:-periods] if periods > 0 else self.iloc[-periods:]
                 new_df.index = (


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
@@ -3093,8 +3093,9 @@ def test_skew(data, skipna):
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
 @pytest.mark.parametrize("index", ["default", "ndarray", "has_duplicates"])
 @pytest.mark.parametrize("periods", [0, 1, -1, 10, -10, 1000000000, -1000000000])
-def test_shift_slice_shift(data, index, periods):
-    modin_series, pandas_series = create_test_series(data)
+@pytest.mark.parametrize("name", [None, "foo"])
+def test_shift_slice_shift(data, index, periods, name):
+    modin_series, pandas_series = create_test_series(data, name=name)
     if index == "ndarray":
         data_column_length = len(data[next(iter(data))])
         modin_series.index = pandas_series.index = np.arange(2, data_column_length + 2)