Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DataFrame pct_change #9805

Merged
merged 19 commits into from
Feb 17, 2022
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c4fba3f
create new pr
skirui-source Dec 1, 2021
b0f6ba3
TO-DO: implem. diff method for dataframes - separate PR
skirui-source Dec 2, 2021
b841cd7
Merge branch 'branch-22.02' of https://github.com/rapidsai/cudf into …
skirui-source Dec 3, 2021
a941441
addressed review
skirui-source Dec 3, 2021
8054647
adding tests, WIP
skirui-source Dec 3, 2021
a8aa7aa
Merge branch 'branch-22.02' of https://github.com/rapidsai/cudf into …
skirui-source Dec 3, 2021
4408b61
fixed merge conflict in test_dataframe.py
skirui-source Dec 8, 2021
a13726b
fixed merge conflict in test_dataframe.py
skirui-source Feb 8, 2022
0f54e1c
Merge branch 'branch-22.04' of https://github.com/rapidsai/cudf into …
skirui-source Feb 9, 2022
57af469
Merge branch 'branch-22.04' of https://github.com/rapidsai/cudf into …
skirui-source Feb 9, 2022
e13b55b
Merge branch 'branch-22.04' of https://github.com/rapidsai/cudf into …
skirui-source Feb 10, 2022
76c30c1
use seed to generate random test data
skirui-source Feb 10, 2022
5e70840
Merge branch 'branch-22.04' of https://github.com/rapidsai/cudf into …
skirui-source Feb 15, 2022
0bdc17a
Merge branch 'branch-22.04' of https://github.com/rapidsai/cudf into …
skirui-source Feb 16, 2022
e1c5d85
Update python/cudf/cudf/tests/test_dataframe.py
skirui-source Feb 16, 2022
a4f1428
Merge branch 'pct_change' of github.com:skirui-source/cudf into pct_c…
skirui-source Feb 16, 2022
c264ea4
handles case when periods > len(df)
skirui-source Feb 17, 2022
0f68434
avoid check_dtype, reduce test cases for periods
skirui-source Feb 17, 2022
c3c36fb
added link to created bug-fix libcudf ticket
skirui-source Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6329,6 +6329,46 @@ def explode(self, column, ignore_index=False):

return super()._explode(column, ignore_index)

def pct_change(
self, periods=1, fill_method="ffill", limit=None, freq=None
):
"""
Calculates the percent change between sequential elements
in the DataFrame.

Parameters
----------
periods : int, default 1
Periods to shift for forming percent change.
fill_method : str, default 'ffill'
How to handle NAs before computing percent changes.
limit : int, optional
The number of consecutive NAs to fill before stopping.
Not yet implemented.
freq : str, optional
Increment to use from time series API.
Not yet implemented.

Returns
-------
DataFrame
"""
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)
skirui-source marked this conversation as resolved.
Show resolved Hide resolved

return data.diff(periods=periods) / data.shift(
skirui-source marked this conversation as resolved.
Show resolved Hide resolved
periods=periods, freq=freq
)

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