[FEA] support numeric_only parameter for groupby.mean()
- 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**
`pandas` has deprecated dropping invalid columns during aggregation, e.g. `mean(numeric_only=None)`
`cudf` does not support automatic dropping and does not support `numeric_only`
```
In [1]: import cudf as pd
In [2]: pd.__version__
Out[2]: '22.12.0'
In [3]: df = pd.DataFrame({'a': ['apple', 'orange'], 'b': [['one', 'two', 'three'], ['four', 'five']]})
In [4]: df.to_pandas().explode('b').groupby('a').mean()
:1: FutureWarning: Dropping invalid columns in DataFrameGroupBy.mean is deprecated. In a future version, a TypeError will be raised. Before calling .mean, select only columns which should be valid for the function.
df.to_pandas().explode('b').groupby('a').mean()
Out[4]:
Empty DataFrame
Columns: []
Index: [apple, orange]
In [5]: df.explode('b').groupby('a').mean()
---------------------------------------------------------------------------
DataError Traceback (most recent call last)
Cell In [5], line 1
----> 1 df.explode('b').groupby('a').mean()
File ~/.local/lib/python3.9/site-packages/cudf/core/mixins/mixin_factory.py:11, in _partialmethod..wrapper(self, *args2, **kwargs2)
10 def wrapper(self, *args2, **kwargs2):
---> 11 return method(self, *args1, *args2, **kwargs1, **kwargs2)
File ~/.local/lib/python3.9/site-packages/cudf/core/groupby/groupby.py:532, in GroupBy._reduce(self, op, numeric_only, min_count, *args, **kwargs)
528 if min_count != 0:
529 raise NotImplementedError(
530 "min_count parameter is not implemented yet"
531 )
--> 532 return self.agg(op)
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:199, in cudf._lib.groupby.GroupBy.aggregate_internal()
DataError: All requested aggregations are unsupported.
In [6]: df.explode('b').groupby('a').mean(numeric_only=True)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In [6], line 1
----> 1 df.explode('b').groupby('a').mean(numeric_only=True)
File ~/.local/lib/python3.9/site-packages/cudf/core/mixins/mixin_factory.py:11, in _partialmethod..wrapper(self, *args2, **kwargs2)
10 def wrapper(self, *args2, **kwargs2):
---> 11 return method(self, *args1, *args2, **kwargs1, **kwargs2)
File ~/.local/lib/python3.9/site-packages/cudf/core/groupby/groupby.py:525, in GroupBy._reduce(self, op, numeric_only, min_count, *args, **kwargs)
502 """Compute {op} of group values.
503
504 Parameters
(...)
522 * Not supporting: numeric_only, min_count
523 """
524 if numeric_only:
--> 525 raise NotImplementedError(
526 "numeric_only parameter is not implemented yet"
527 )
528 if min_count != 0:
529 raise NotImplementedError(
530 "min_count parameter is not implemented yet"
531 )
NotImplementedError: numeric_only parameter is not implemented yet
```
Contributor guide
Assessment
This issue has not been assessed yet.