|
62 | 62 | )
|
63 | 63 | import pandas.core.common as com
|
64 | 64 | from pandas.core.frame import DataFrame
|
65 |
| -from pandas.core.groupby import ( |
66 |
| - base, |
67 |
| - ops, |
68 |
| -) |
| 65 | +from pandas.core.groupby import base |
69 | 66 | from pandas.core.groupby.groupby import (
|
70 | 67 | GroupBy,
|
71 | 68 | GroupByPlot,
|
@@ -373,32 +370,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
|
373 | 370 | index=self._grouper.result_index,
|
374 | 371 | dtype=obj.dtype,
|
375 | 372 | )
|
376 |
| - |
377 |
| - if self._grouper.nkeys > 1: |
378 |
| - return self._python_agg_general(func, *args, **kwargs) |
379 |
| - |
380 |
| - try: |
381 |
| - return self._python_agg_general(func, *args, **kwargs) |
382 |
| - except KeyError: |
383 |
| - # KeyError raised in test_groupby.test_basic is bc the func does |
384 |
| - # a dictionary lookup on group.name, but group name is not |
385 |
| - # pinned in _python_agg_general, only in _aggregate_named |
386 |
| - result = self._aggregate_named(func, *args, **kwargs) |
387 |
| - |
388 |
| - warnings.warn( |
389 |
| - "Pinning the groupby key to each group in " |
390 |
| - f"{type(self).__name__}.agg is deprecated, and cases that " |
391 |
| - "relied on it will raise in a future version. " |
392 |
| - "If your operation requires utilizing the groupby keys, " |
393 |
| - "iterate over the groupby object instead.", |
394 |
| - FutureWarning, |
395 |
| - stacklevel=find_stack_level(), |
396 |
| - ) |
397 |
| - |
398 |
| - # result is a dict whose keys are the elements of result_index |
399 |
| - result = Series(result, index=self._grouper.result_index) |
400 |
| - result = self._wrap_aggregated_output(result) |
401 |
| - return result |
| 373 | + return self._python_agg_general(func, *args, **kwargs) |
402 | 374 |
|
403 | 375 | agg = aggregate
|
404 | 376 |
|
@@ -527,26 +499,6 @@ def _wrap_applied_output(
|
527 | 499 | result.index = default_index(len(result))
|
528 | 500 | return result
|
529 | 501 |
|
530 |
| - def _aggregate_named(self, func, *args, **kwargs): |
531 |
| - # Note: this is very similar to _aggregate_series_pure_python, |
532 |
| - # but that does not pin group.name |
533 |
| - result = {} |
534 |
| - initialized = False |
535 |
| - |
536 |
| - for name, group in self._grouper.get_iterator(self._obj_with_exclusions): |
537 |
| - # needed for pandas/tests/groupby/test_groupby.py::test_basic_aggregations |
538 |
| - object.__setattr__(group, "name", name) |
539 |
| - |
540 |
| - output = func(group, *args, **kwargs) |
541 |
| - output = ops.extract_result(output) |
542 |
| - if not initialized: |
543 |
| - # We only do this validation on the first iteration |
544 |
| - ops.check_result_array(output, group.dtype) |
545 |
| - initialized = True |
546 |
| - result[name] = output |
547 |
| - |
548 |
| - return result |
549 |
| - |
550 | 502 | __examples_series_doc = dedent(
|
551 | 503 | """
|
552 | 504 | >>> ser = pd.Series([390.0, 350.0, 30.0, 20.0],
|
|
0 commit comments