Repository: modin-project/modin

Issue:
Support cases for operations when `Series` consist of one element
Signed-off-by: Yaroslav Igoshev yaroslav.igoshev@intel.com

<!--
Thank you for your contribution! 
Please review the contributing docs: https://modin.readthedocs.io/en/latest/contributing.html
if you have questions about contributing.
-->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

- [x] passes `flake8 modin`
- [x] passes `black --check modin`
- [x] signed commit with `git commit -s` <!-- you can amend your commit with a signature via `git commit -amend -s` -->
- [x] Resolves #1661 <!-- issue must be created for each patch -->
- [x] tests passing



Discussion:

Resolving patch:
diff --git a/modin/backends/pandas/query_compiler.py b/modin/backends/pandas/query_compiler.py
--- a/modin/backends/pandas/query_compiler.py
+++ b/modin/backends/pandas/query_compiler.py
@@ -55,7 +55,7 @@ def set_axis(self, cols):
 
 def _str_map(func_name):
     def str_op_builder(df, *args, **kwargs):
-        str_s = df.squeeze().str
+        str_s = df.squeeze(axis=1).str
         return getattr(pandas.Series.str, func_name)(str_s, *args, **kwargs).to_frame()
 
     return str_op_builder
@@ -80,7 +80,7 @@ def _dt_prop_map(property_name):
     """
 
     def dt_op_builder(df, *args, **kwargs):
-        prop_val = getattr(df.squeeze().dt, property_name)
+        prop_val = getattr(df.squeeze(axis=1).dt, property_name)
         if isinstance(prop_val, pandas.Series):
             return prop_val.to_frame()
         elif isinstance(prop_val, pandas.DataFrame):
@@ -110,7 +110,7 @@ def _dt_func_map(func_name):
     """
 
     def dt_op_builder(df, *args, **kwargs):
-        dt_s = df.squeeze().dt
+        dt_s = df.squeeze(axis=1).dt
         return pandas.DataFrame(
             getattr(pandas.Series.dt, func_name)(dt_s, *args, **kwargs)
         )
@@ -320,7 +320,9 @@ def to_numpy(self):
         copy_df_for_func(pandas.DataFrame.update), join_type="left"
     )
     series_update = BinaryFunction.register(
-        copy_df_for_func(lambda x, y: pandas.Series.update(x.squeeze(), y.squeeze())),
+        copy_df_for_func(
+            lambda x, y: pandas.Series.update(x.squeeze(axis=1), y.squeeze(axis=1))
+        ),
         join_type="left",
     )
 
@@ -461,11 +463,11 @@ def _is_monotonic(self, type=None):
         monotonic_fn = funcs.get(type, funcs["increasing"])
 
         def is_monotonic_map(df):
-            df = df.squeeze()
+            df = df.squeeze(axis=1)
             return [monotonic_fn(df), df.iloc[0], df.iloc[len(df) - 1]]
 
         def is_monotonic_reduce(df):
-            df = df.squeeze()
+            df = df.squeeze(axis=1)
 
             common_case = df[0].all()
             left_edges = df[1]
@@ -620,7 +622,9 @@ def sort_index_for_equal_values(result, ascending):
     quantile_for_single_value = ReductionFunction.register(pandas.DataFrame.quantile)
     mad = ReductionFunction.register(pandas.DataFrame.mad)
     to_datetime = ReductionFunction.register(
-        lambda df, *args, **kwargs: pandas.to_datetime(df.squeeze(), *args, **kwargs),
+        lambda df, *args, **kwargs: pandas.to_datetime(
+            df.squeeze(axis=1), *args, **kwargs
+        ),
         axis=1,
     )
 
@@ -640,17 +644,19 @@ def sort_index_for_equal_values(result, ascending):
     notna = MapFunction.register(pandas.DataFrame.notna, dtypes=np.bool)
     round = MapFunction.register(pandas.DataFrame.round)
     series_view = MapFunction.register(
-        lambda df, *args, **kwargs: pandas.DataFrame(df.squeeze().view(*args, **kwargs))
+        lambda df, *args, **kwargs: pandas.DataFrame(
+            df.squeeze(axis=1).view(*args, **kwargs)
+        )
     )
     to_numeric = MapFunction.register(
         lambda df, *args, **kwargs: pandas.DataFrame(
-            pandas.to_numeric(df.squeeze(), *args, **kwargs)
+            pandas.to_numeric(df.squeeze(axis=1), *args, **kwargs)
         )
     )
 
     def repeat(self, repeats):
         def map_fn(df):
-            return pandas.DataFrame(df.squeeze().repeat(repeats))
+            return pandas.DataFrame(df.squeeze(axis=1).repeat(repeats))
 
         if isinstance(repeats, int) or (is_list_like(repeats) and len(repeats) == 1):
             return MapFunction.register(map_fn, validate_index=True)(self)
@@ -719,7 +725,7 @@ def unique(self):
             The unique values returned as a NumPy array.
         """
         new_modin_frame = self._modin_frame._apply_full_axis(
-            0, lambda x: x.squeeze().unique(), new_columns=self.columns,
+            0, lambda x: x.squeeze(axis=1).unique(), new_columns=self.columns,
         )
         return self.__constructor__(new_modin_frame)
 
@@ -955,7 +961,7 @@ def nsmallest(self, n, columns=None, keep="first"):
         def map_func(df, n=n, keep=keep, columns=columns):
             if columns is None:
                 return pandas.DataFrame(
-                    pandas.Series.nsmallest(df.squeeze(), n=n, keep=keep)
+                    pandas.Series.nsmallest(df.squeeze(axis=1), n=n, keep=keep)
                 )
             return pandas.DataFrame.nsmallest(df, n=n, columns=columns, keep=keep)
 
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -1058,7 +1058,7 @@ def rename(
         else:
             from .dataframe import DataFrame
 
-            result = DataFrame(self.copy()).rename(index=index).squeeze()
+            result = DataFrame(self.copy()).rename(index=index).squeeze(axis=1)
             result.name = self.name
             return result
 
@@ -1724,7 +1724,7 @@ def total_seconds(self, *args, **kwargs):
 
     def to_pytimedelta(self):
         return self._query_compiler.default_to_pandas(
-            lambda df: pandas.Series.dt.to_pytimedelta(df.squeeze().dt)
+            lambda df: pandas.Series.dt.to_pytimedelta(df.squeeze(axis=1).dt)
         )
 
     @property


Test patch: