From 60d682a2d9da8b2383f98ded58842c108bc5c809 Mon Sep 17 00:00:00 2001 From: Mahesh Vashishtha Date: Fri, 24 Feb 2023 21:37:45 -0600 Subject: [PATCH] FIX: Fix API layer implementation of reindex_like [upstream] (#75) [core] Note for upstream and rebase: Don't worry about the client query compiler change here as it's just deleting an unused method. Don't need to upstream or add into the next modin branch on the next rebase. Signed-off-by: mvashishtha --- modin/pandas/base.py | 8 -------- modin/pandas/dataframe.py | 24 ++++++++++++++++++++++++ modin/pandas/series.py | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/modin/pandas/base.py b/modin/pandas/base.py index 919410e4e37..36283fccbb5 100644 --- a/modin/pandas/base.py +++ b/modin/pandas/base.py @@ -2232,14 +2232,6 @@ def reindex( final_query_compiler, inplace=False if copy is None else not copy ) - def reindex_like( - self, other, method=None, copy=True, limit=None, tolerance=None - ): # noqa: PR01, RT01, D200 - """ - Return an object with matching indices as `other` object. - """ - return self._query_compiler.reindex_like(other, method, copy, limit, tolerance) - def rename_axis( self, mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False ): # noqa: PR01, RT01, D200 diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py index 3c1bc5bf336..2befd0741f0 100644 --- a/modin/pandas/dataframe.py +++ b/modin/pandas/dataframe.py @@ -2877,6 +2877,30 @@ def style(df): return self._default_to_pandas(style) + def reindex_like( + self: "DataFrame", + other, + method=None, + copy: bool = True, + limit=None, + tolerance=None, + ) -> "DataFrame": + # docs say "Same as calling .reindex(index=other.index, columns=other.columns,...).": + # https://pandas.pydata.org/pandas-docs/version/1.4/reference/api/pandas.DataFrame.reindex_like.html + return self.reindex( + index=other.index, + method=method, + copy=copy, + limit=limit, + tolerance=tolerance, + ).reindex( + columns=other.columns, + method=method, + copy=copy, + limit=limit, + tolerance=tolerance, + ) + def _create_or_update_from_compiler(self, new_query_compiler, inplace=False): """ Return or update a ``DataFrame`` with given `new_query_compiler`. diff --git a/modin/pandas/series.py b/modin/pandas/series.py index 44df1457655..c8d0c22c706 100644 --- a/modin/pandas/series.py +++ b/modin/pandas/series.py @@ -2202,6 +2202,24 @@ def str(self): # noqa: RT01, D200 return StringMethods(self) + def reindex_like( + self: "Series", + other, + method=None, + copy: bool = True, + limit=None, + tolerance=None, + ) -> "Series": + # docs say "Same as calling .reindex(index=other.index, columns=other.columns,...).": + # https://pandas.pydata.org/pandas-docs/version/1.4/reference/api/pandas.Series.reindex_like.html + return self.reindex( + index=other.index, + method=method, + copy=copy, + limit=limit, + tolerance=tolerance, + ) + def _to_pandas(self): """ Convert Modin Series to pandas Series.