From b0f6ba347a1b50087f15755e21b5d638ebba9790 Mon Sep 17 00:00:00 2001 From: Sheilah Date: Wed, 1 Dec 2021 17:48:29 -0800 Subject: [PATCH] TO-DO: implem. diff method for dataframes - separate PR --- python/cudf/cudf/core/dataframe.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 902a78f34d9..e534585205e 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -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. @@ -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