[FEA] support DataFrameGroupBy.shift
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
**Is your feature request related to a problem? Please describe.**
working with `import cudf as pd`
**Describe the solution you'd like**
https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.shift.html
```
In [1]: import cudf as pd
In [2]: pd.__version__
Out[2]: '22.12.0'
In [3]: df = pd.DataFrame({'salary': [30000,40000,50000,85000,75000], 'gender': list('MFMFM')})
In [9]: df.groupby('gender')['salary'].transform(lambda x: x.shift(-1))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [9], line 1
----> 1 df.groupby('gender')['salary'].transform(lambda x: x.shift(-1))
File ~/.local/lib/python3.9/site-packages/cudf/core/groupby/groupby.py:1070, in GroupBy.transform(self, function)
1036 """Apply an aggregation, then broadcast the result to the group size.
1037
1038 Parameters
(...)
1067 agg
1068 """
1069 try:
-> 1070 result = self.agg(function)
1071 except TypeError as e:
1072 raise NotImplementedError(
1073 "Currently, `transform()` supports only aggregations."
1074 ) from e
File ~/.local/lib/python3.9/site-packages/cudf/core/groupby/groupby.py:1749, in SeriesGroupBy.agg(self, func)
1748 def agg(self, func):
-> 1749 result = super().agg(func)
1751 # downcast the result to a Series:
1752 if len(result._data):
File ~/.local/lib/python3.9/site-packages/nvtx/nvtx.py:101, in annotate.__call__..inner(*args, **kwargs)
98 @wraps(func)
99 def inner(*args, **kwargs):
100 libnvtx_push_range(self.attributes, self.domain.handle)
--> 101 result = func(*args, **kwargs)
102 libnvtx_pop_range(self.domain.handle)
103 return result
File ~/.local/lib/python3.9/site-packages/cudf/core/groupby/groupby.py:460, in GroupBy.agg(self, func)
451 column_names, columns, normalized_aggs = self._normalize_aggs(func)
453 # Note: When there are no key columns, the below produces
454 # a Float64Index, while Pandas returns an Int64Index
455 # (GH: 6945)
456 (
457 result_columns,
458 grouped_key_cols,
459 included_aggregations,
--> 460 ) = self._groupby.aggregate(columns, normalized_aggs)
462 result_index = self.grouping.keys._from_columns_like_self(
463 grouped_key_cols,
464 )
466 multilevel = _is_multi_agg(func)
File groupby.pyx:309, in cudf._lib.groupby.GroupBy.aggregate()
File groupby.pyx:184, in cudf._lib.groupby.GroupBy.aggregate_internal()
File aggregation.pyx:866, in cudf._lib.aggregation.make_groupby_aggregation()
Cell In [9], line 1, in (x)
----> 1 df.groupby('gender')['salary'].transform(lambda x: x.shift(-1))
AttributeError: type object 'cudf._lib.aggregation.GroupbyAggregation' has no attribute 'shift'
In [10]: df.to_pandas().groupby('gender')['salary'].transform(lambda x: x.shift(-1))
Out[10]:
0 50000.0
1 85000.0
2 75000.0
3 NaN
4 NaN
Name: salary, dtype: float64
```
Contributor guide
Assessment
This issue has not been assessed yet.