Skip to content

Commit 4929e81

Browse files
alimcmaster1AlexKirko
authored andcommitted
CLN: OrderedDict -> Dict (pandas-dev#30471)
1 parent 00c13a6 commit 4929e81

File tree

3 files changed

+47
-54
lines changed

3 files changed

+47
-54
lines changed

pandas/core/base.py

+33-38
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Base and utility classes for pandas objects.
33
"""
44
import builtins
5-
from collections import OrderedDict
65
import textwrap
76
from typing import Dict, FrozenSet, List, Optional
87

@@ -141,39 +140,35 @@ class SelectionMixin:
141140
_internal_names = ["_cache", "__setstate__"]
142141
_internal_names_set = set(_internal_names)
143142

144-
_builtin_table = OrderedDict(
145-
((builtins.sum, np.sum), (builtins.max, np.max), (builtins.min, np.min))
146-
)
147-
148-
_cython_table = OrderedDict(
149-
(
150-
(builtins.sum, "sum"),
151-
(builtins.max, "max"),
152-
(builtins.min, "min"),
153-
(np.all, "all"),
154-
(np.any, "any"),
155-
(np.sum, "sum"),
156-
(np.nansum, "sum"),
157-
(np.mean, "mean"),
158-
(np.nanmean, "mean"),
159-
(np.prod, "prod"),
160-
(np.nanprod, "prod"),
161-
(np.std, "std"),
162-
(np.nanstd, "std"),
163-
(np.var, "var"),
164-
(np.nanvar, "var"),
165-
(np.median, "median"),
166-
(np.nanmedian, "median"),
167-
(np.max, "max"),
168-
(np.nanmax, "max"),
169-
(np.min, "min"),
170-
(np.nanmin, "min"),
171-
(np.cumprod, "cumprod"),
172-
(np.nancumprod, "cumprod"),
173-
(np.cumsum, "cumsum"),
174-
(np.nancumsum, "cumsum"),
175-
)
176-
)
143+
_builtin_table = {builtins.sum: np.sum, builtins.max: np.max, builtins.min: np.min}
144+
145+
_cython_table = {
146+
builtins.sum: "sum",
147+
builtins.max: "max",
148+
builtins.min: "min",
149+
np.all: "all",
150+
np.any: "any",
151+
np.sum: "sum",
152+
np.nansum: "sum",
153+
np.mean: "mean",
154+
np.nanmean: "mean",
155+
np.prod: "prod",
156+
np.nanprod: "prod",
157+
np.std: "std",
158+
np.nanstd: "std",
159+
np.var: "var",
160+
np.nanvar: "var",
161+
np.median: "median",
162+
np.nanmedian: "median",
163+
np.max: "max",
164+
np.nanmax: "max",
165+
np.min: "min",
166+
np.nanmin: "min",
167+
np.cumprod: "cumprod",
168+
np.nancumprod: "cumprod",
169+
np.cumsum: "cumsum",
170+
np.nancumsum: "cumsum",
171+
}
177172

178173
@property
179174
def _selection_name(self):
@@ -328,7 +323,7 @@ def _aggregate(self, arg, *args, **kwargs):
328323
# eg. {'A' : ['mean']}, normalize all to
329324
# be list-likes
330325
if any(is_aggregator(x) for x in arg.values()):
331-
new_arg = OrderedDict()
326+
new_arg = {}
332327
for k, v in arg.items():
333328
if not isinstance(v, (tuple, list, dict)):
334329
new_arg[k] = [v]
@@ -386,16 +381,16 @@ def _agg_2dim(name, how):
386381
def _agg(arg, func):
387382
"""
388383
run the aggregations over the arg with func
389-
return an OrderedDict
384+
return a dict
390385
"""
391-
result = OrderedDict()
386+
result = {}
392387
for fname, agg_how in arg.items():
393388
result[fname] = func(fname, agg_how)
394389
return result
395390

396391
# set the final keys
397392
keys = list(arg.keys())
398-
result = OrderedDict()
393+
result = {}
399394

400395
if self._selection is not None:
401396

pandas/io/json/_json.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import OrderedDict, abc
1+
from collections import abc
22
import functools
33
from io import StringIO
44
from itertools import islice
@@ -331,7 +331,7 @@ def _write(
331331
default_handler,
332332
indent,
333333
):
334-
table_obj = OrderedDict((("schema", self.schema), ("data", obj)))
334+
table_obj = {"schema": self.schema, "data": obj}
335335
serialized = super()._write(
336336
table_obj,
337337
orient,

pandas/tests/series/test_apply.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import Counter, OrderedDict, defaultdict
1+
from collections import Counter, defaultdict
22
from itertools import chain
33

44
import numpy as np
@@ -297,18 +297,16 @@ def test_replicate_describe(self, string_series):
297297
# this also tests a result set that is all scalars
298298
expected = string_series.describe()
299299
result = string_series.apply(
300-
OrderedDict(
301-
[
302-
("count", "count"),
303-
("mean", "mean"),
304-
("std", "std"),
305-
("min", "min"),
306-
("25%", lambda x: x.quantile(0.25)),
307-
("50%", "median"),
308-
("75%", lambda x: x.quantile(0.75)),
309-
("max", "max"),
310-
]
311-
)
300+
{
301+
"count": "count",
302+
"mean": "mean",
303+
"std": "std",
304+
"min": "min",
305+
"25%": lambda x: x.quantile(0.25),
306+
"50%": "median",
307+
"75%": lambda x: x.quantile(0.75),
308+
"max": "max",
309+
}
312310
)
313311
tm.assert_series_equal(result, expected)
314312

@@ -333,7 +331,7 @@ def test_non_callable_aggregates(self):
333331

334332
# test when mixed w/ callable reducers
335333
result = s.agg(["size", "count", "mean"])
336-
expected = Series(OrderedDict([("size", 3.0), ("count", 2.0), ("mean", 1.5)]))
334+
expected = Series({"size": 3.0, "count": 2.0, "mean": 1.5})
337335
tm.assert_series_equal(result[expected.index], expected)
338336

339337
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)