|
5 | 5 | These are user facing as the result of the ``df.groupby(...)`` operations,
|
6 | 6 | which here returns a DataFrameGroupBy object.
|
7 | 7 | """
|
8 |
| -from collections import OrderedDict, abc, namedtuple |
| 8 | +from collections import OrderedDict, abc, defaultdict, namedtuple |
9 | 9 | import copy
|
10 | 10 | from functools import partial
|
11 | 11 | from textwrap import dedent
|
@@ -1896,20 +1896,15 @@ def _normalize_keyword_aggregation(kwargs):
|
1896 | 1896 | """
|
1897 | 1897 | # Normalize the aggregation functions as Mapping[column, List[func]],
|
1898 | 1898 | # process normally, then fixup the names.
|
1899 |
| - # TODO(Py35): When we drop python 3.5, change this to |
1900 |
| - # defaultdict(list) |
1901 | 1899 | # TODO: aggspec type: typing.OrderedDict[str, List[AggScalar]]
|
1902 | 1900 | # May be hitting https://github.com/python/mypy/issues/5958
|
1903 | 1901 | # saying it doesn't have an attribute __name__
|
1904 |
| - aggspec = OrderedDict() |
| 1902 | + aggspec = defaultdict(list) |
1905 | 1903 | order = []
|
1906 | 1904 | columns, pairs = list(zip(*kwargs.items()))
|
1907 | 1905 |
|
1908 | 1906 | for name, (column, aggfunc) in zip(columns, pairs):
|
1909 |
| - if column in aggspec: |
1910 |
| - aggspec[column].append(aggfunc) |
1911 |
| - else: |
1912 |
| - aggspec[column] = [aggfunc] |
| 1907 | + aggspec[column].append(aggfunc) |
1913 | 1908 | order.append((column, com.get_callable_name(aggfunc) or aggfunc))
|
1914 | 1909 |
|
1915 | 1910 | # uniquify aggfunc name if duplicated in order list
|
|
0 commit comments