Skip to content

Commit 8818407

Browse files
ShaharNavehjreback
authored andcommitted
CLN: Orderdict -> defaultdict(list) (#30468)
1 parent 0dc7b5c commit 8818407

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

pandas/core/groupby/generic.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
These are user facing as the result of the ``df.groupby(...)`` operations,
66
which here returns a DataFrameGroupBy object.
77
"""
8-
from collections import OrderedDict, abc, namedtuple
8+
from collections import OrderedDict, abc, defaultdict, namedtuple
99
import copy
1010
from functools import partial
1111
from textwrap import dedent
@@ -1896,20 +1896,15 @@ def _normalize_keyword_aggregation(kwargs):
18961896
"""
18971897
# Normalize the aggregation functions as Mapping[column, List[func]],
18981898
# process normally, then fixup the names.
1899-
# TODO(Py35): When we drop python 3.5, change this to
1900-
# defaultdict(list)
19011899
# TODO: aggspec type: typing.OrderedDict[str, List[AggScalar]]
19021900
# May be hitting https://github.com/python/mypy/issues/5958
19031901
# saying it doesn't have an attribute __name__
1904-
aggspec = OrderedDict()
1902+
aggspec = defaultdict(list)
19051903
order = []
19061904
columns, pairs = list(zip(*kwargs.items()))
19071905

19081906
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)
19131908
order.append((column, com.get_callable_name(aggfunc) or aggfunc))
19141909

19151910
# uniquify aggfunc name if duplicated in order list

0 commit comments

Comments
 (0)