Skip to content

Commit

Permalink
TO-DO: implem. diff method for dataframes - separate PR
Browse files Browse the repository at this point in the history
  • Loading branch information
skirui-source committed Dec 2, 2021
1 parent c4fba3f commit b0f6ba3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6329,7 +6329,9 @@ def explode(self, column, ignore_index=False):

return super()._explode(column, ignore_index)

def pct_change(self):
def pct_change(
self, periods=1, fill_method="ffill", limit=None, freq=None
):
"""
Calculates the percent change between sequential elements
in the DataFrame.
Expand All @@ -6351,7 +6353,20 @@ def pct_change(self):
-------
DataFrame
"""
pass
if limit is not None:
raise NotImplementedError("limit parameter not supported yet.")
if freq is not None:
raise NotImplementedError("freq parameter not supported yet.")
elif fill_method not in {"ffill", "pad", "bfill", "backfill"}:
raise ValueError(
"fill_method must be one of 'ffill', 'pad', "
"'bfill', or 'backfill'."
)

data = self.fillna(method=fill_method, limit=limit)
data_diff = data.diff(periods=periods) # need to implem. diff method
change = data_diff / data.shift(periods=periods, freq=freq)
return change

def __dataframe__(
self, nan_as_null: bool = False, allow_copy: bool = True
Expand Down

0 comments on commit b0f6ba3

Please sign in to comment.