Skip to content

Commit

Permalink
[SNOW-1524894]: Add support for reindex (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-rdurrani committed Jul 15, 2024
1 parent 1a734c9 commit d1f5e16
Show file tree
Hide file tree
Showing 11 changed files with 1,833 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Added support for `DataFrame.corr`.
- Added support for `limit` parameter when `method` parameter is used in `fillna`.
- Added support for `DataFrame.equals` and `Series.equals`.
- Added support for `DataFrame.reindex` and `Series.reindex`.

#### Bug Fixes
- Fixed an issue when using np.where and df.where when the scalar 'other' is the literal 0.
Expand Down
3 changes: 2 additions & 1 deletion docs/source/modin/supported/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``rdiv`` | P | ``level`` | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``reindex`` | N | | |
| ``reindex`` | P | | ``N`` if axis is MultiIndex or method is |
| | | | ``nearest``. |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``reindex_like`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
3 changes: 2 additions & 1 deletion docs/source/modin/supported/series_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``rdivmod`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``reindex`` | N | | |
| ``reindex`` | P | | ``N`` if the series has MultiIndex, or method |
| | | | is ``nearest``. |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``reindex_like`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
6 changes: 4 additions & 2 deletions src/snowflake/snowpark/modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2584,7 +2584,6 @@ def _ensure_index(self, index_like, axis=0): # noqa: PR01, RT01, D200
pass
return ensure_index(index_like)

@base_not_implemented()
def reindex(
self,
index=None,
Expand All @@ -2596,7 +2595,10 @@ def reindex(
Conform `BasePandasDataset` to new index with optional filling logic.
"""
# TODO: SNOW-1119855: Modin upgrade - modin.pandas.base.BasePandasDataset

if kwargs.get("limit", None) is not None and kwargs.get("method", None) is None:
raise ValueError(
"limit argument only valid if doing pad, backfill or nearest reindexing"
)
new_query_compiler = None
if index is not None:
if not isinstance(index, pandas.Index) or not index.equals(self.index):
Expand Down
1 change: 0 additions & 1 deletion src/snowflake/snowpark/modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,6 @@ def rename(
new_query_compiler=new_qc, inplace=inplace
)

@dataframe_not_implemented()
def reindex(
self,
labels=None,
Expand Down
11 changes: 7 additions & 4 deletions src/snowflake/snowpark/modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,10 +1672,12 @@ def ravel(self, order="C"): # noqa: PR01, RT01, D200
def reindex(self, *args, **kwargs):
if args:
if len(args) > 1:
raise TypeError("Only one positional argument ('index') is allowed")
raise TypeError(
"Series.reindex() takes from 1 to 2 positional arguments but 3 were given"
)
if "index" in kwargs:
raise TypeError(
"'index' passed as both positional and keyword argument"
"Series.reindex() got multiple values for argument 'index'"
)
kwargs.update({"index": args[0]})
index = kwargs.pop("index", None)
Expand All @@ -1685,10 +1687,11 @@ def reindex(self, *args, **kwargs):
limit = kwargs.pop("limit", None)
tolerance = kwargs.pop("tolerance", None)
fill_value = kwargs.pop("fill_value", None)
kwargs.pop("axis", None)
if kwargs:
raise TypeError(
"reindex() got an unexpected keyword "
+ f'argument "{list(kwargs.keys())[0]}"'
"Series.reindex() got an unexpected keyword "
+ f"argument '{list(kwargs.keys())[0]}'"
)
return super().reindex(
index=index,
Expand Down
Loading

0 comments on commit d1f5e16

Please sign in to comment.