Skip to content

Commit

Permalink
FEAT-modin-project#1222: Series.asof now uses Modin path as well.
Browse files Browse the repository at this point in the history
Signed-off-by: Itamar Turner-Trauring <itamar@itamarst.org>
  • Loading branch information
itamarst committed Sep 3, 2020
1 parent 17a847b commit 3da35dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/supported_apis/series_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ the related section on `Defaulting to pandas`_.
+-----------------------------+---------------------------------+
| ``asobject`` | D |
+-----------------------------+---------------------------------+
| ``asof`` | D |
| ``asof`` | Y |
+-----------------------------+---------------------------------+
| ``astype`` | Y |
+-----------------------------+---------------------------------+
Expand Down
24 changes: 23 additions & 1 deletion modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,29 @@ def asfreq(self, freq, method=None, how=None, normalize=False, fill_value=None):
)

def asof(self, where, subset=None):
return self._default_to_pandas("asof", where, subset=subset)
scalar = not is_list_like(where)
if isinstance(where, pandas.Index):
# Prevent accidental mutation of original:
where = where.copy()
else:
if scalar:
where = [where]
where = pandas.Index(where)

if subset is None:
data = self
else:
# Only relevant for DataFrames:
data = self[subset]
no_na_index = data.dropna().index
new_index = pandas.Index([no_na_index.asof(i) for i in where])
result = self.reindex(new_index)
result.index = where

if scalar:
# Need to return a Series:
result = result.squeeze()
return result

def astype(self, dtype, copy=True, errors="raise"):
col_dtypes = {}
Expand Down
23 changes: 0 additions & 23 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,29 +594,6 @@ def append(self, other, ignore_index=False, verify_integrity=False, sort=False):
)
return DataFrame(query_compiler=query_compiler)

def asof(self, where, subset=None):
scalar = not is_list_like(where)
if isinstance(where, pandas.Index):
# Prevent accidental mutation of original:
where = where.copy()
else:
if scalar:
where = [where]
where = pandas.Index(where)

df = self
if subset is not None:
df = self[subset]
no_na_index = df.dropna().index
new_index = pandas.Index([no_na_index.asof(i) for i in where])
result = self.reindex(new_index)
result.index = where

if scalar:
# Need to return a Series:
result = result.squeeze()
return result

def assign(self, **kwargs):
df = self.copy()
for k, v in kwargs.items():
Expand Down

0 comments on commit 3da35dc

Please sign in to comment.