diff --git a/modin/pandas/base.py b/modin/pandas/base.py index 740da1b6801..0e9135cec80 100644 --- a/modin/pandas/base.py +++ b/modin/pandas/base.py @@ -1686,65 +1686,28 @@ def rank( def reindex( self, - labels=None, index=None, columns=None, - axis=None, - method=None, copy=True, - level=None, - fill_value=np.nan, - limit=None, - tolerance=None, + **kwargs, ): - axis = self._get_axis_number(axis) - if (columns is not None and self._query_compiler.has_multiindex(axis=1)) or ( - index is not None and self._query_compiler.has_multiindex() - ): - return self._default_to_pandas( - "reindex", - labels=labels, - index=index, - columns=columns, - method=method, - copy=copy, - level=level, - fill_value=fill_value, - limit=limit, - tolerance=tolerance, - ) if ( - level is not None - or (axis == 1 and self._query_compiler.has_multiindex(axis=1)) - or (axis == 0 and self._query_compiler.has_multiindex()) + kwargs.get("level") is not None + or (index is not None and self._query_compiler.has_multiindex()) + or (columns is not None and self._query_compiler.has_multiindex(axis=1)) ): - return self._default_to_pandas( - "reindex", - labels=labels, - level=level, - method=method, - copy=copy, - axis=axis, - fill_value=fill_value, - limit=limit, - tolerance=tolerance, - ) - if axis == 0 and labels is not None: - index = labels - elif labels is not None: - columns = labels + if index is not None: + kwargs["index"] = index + if columns is not None: + kwargs["columns"] = columns + return self._default_to_pandas("reindex", copy=copy, **kwargs) new_query_compiler = None if index is not None: if not isinstance(index, pandas.Index): index = pandas.Index(index) if not index.equals(self.index): new_query_compiler = self._query_compiler.reindex( - axis=0, - labels=index, - method=method, - fill_value=fill_value, - limit=limit, - tolerance=tolerance, + axis=0, labels=index, **kwargs ) if new_query_compiler is None: new_query_compiler = self._query_compiler @@ -1754,12 +1717,7 @@ def reindex( columns = pandas.Index(columns) if not columns.equals(self.columns): final_query_compiler = new_query_compiler.reindex( - axis=1, - labels=columns, - method=method, - fill_value=fill_value, - limit=limit, - tolerance=tolerance, + axis=1, labels=columns, **kwargs ) if final_query_compiler is None: final_query_compiler = new_query_compiler diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py index fca9dcd2bc2..831f38f8e5f 100644 --- a/modin/pandas/dataframe.py +++ b/modin/pandas/dataframe.py @@ -1396,6 +1396,35 @@ def query(self, expr, inplace=False, **kwargs): new_query_compiler = self._query_compiler.query(expr, **kwargs) return self._create_or_update_from_compiler(new_query_compiler, inplace) + def reindex( + self, + labels=None, + index=None, + columns=None, + axis=None, + method=None, + copy=True, + level=None, + fill_value=np.nan, + limit=None, + tolerance=None, + ): + axis = self._get_axis_number(axis) + if axis == 0 and labels is not None: + index = labels + elif labels is not None: + columns = labels + return super(DataFrame, self).reindex( + index=index, + columns=columns, + method=method, + copy=copy, + level=level, + fill_value=fill_value, + limit=limit, + tolerance=tolerance, + ) + def rename( self, mapper=None, diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py index 4dccd3bc5fd..0a5a34c48ab 100644 --- a/modin/pandas/test/test_series.py +++ b/modin/pandas/test/test_series.py @@ -2466,6 +2466,15 @@ def test_reindex(data): pandas_series.reindex(index=[0, 1, 5]), ) + # MultiIndex + modin_series, pandas_series = create_test_series(data) + modin_series.index, pandas_series.index = [ + generate_multiindex(len(pandas_series)) + ] * 2 + pandas_result = pandas_series.reindex(list(reversed(pandas_series.index))) + modin_result = modin_series.reindex(list(reversed(modin_series.index))) + df_equals(pandas_result, modin_result) + def test_reindex_like(): df1 = pd.DataFrame(