Skip to content

CLN: OrderedDict -> Dict #30471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 33 additions & 38 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Base and utility classes for pandas objects.
"""
import builtins
from collections import OrderedDict
import textwrap
from typing import Dict, FrozenSet, List, Optional

Expand Down Expand Up @@ -141,39 +140,35 @@ class SelectionMixin:
_internal_names = ["_cache", "__setstate__"]
_internal_names_set = set(_internal_names)

_builtin_table = OrderedDict(
((builtins.sum, np.sum), (builtins.max, np.max), (builtins.min, np.min))
)

_cython_table = OrderedDict(
(
(builtins.sum, "sum"),
(builtins.max, "max"),
(builtins.min, "min"),
(np.all, "all"),
(np.any, "any"),
(np.sum, "sum"),
(np.nansum, "sum"),
(np.mean, "mean"),
(np.nanmean, "mean"),
(np.prod, "prod"),
(np.nanprod, "prod"),
(np.std, "std"),
(np.nanstd, "std"),
(np.var, "var"),
(np.nanvar, "var"),
(np.median, "median"),
(np.nanmedian, "median"),
(np.max, "max"),
(np.nanmax, "max"),
(np.min, "min"),
(np.nanmin, "min"),
(np.cumprod, "cumprod"),
(np.nancumprod, "cumprod"),
(np.cumsum, "cumsum"),
(np.nancumsum, "cumsum"),
)
)
_builtin_table = {builtins.sum: np.sum, builtins.max: np.max, builtins.min: np.min}

_cython_table = {
builtins.sum: "sum",
builtins.max: "max",
builtins.min: "min",
np.all: "all",
np.any: "any",
np.sum: "sum",
np.nansum: "sum",
np.mean: "mean",
np.nanmean: "mean",
np.prod: "prod",
np.nanprod: "prod",
np.std: "std",
np.nanstd: "std",
np.var: "var",
np.nanvar: "var",
np.median: "median",
np.nanmedian: "median",
np.max: "max",
np.nanmax: "max",
np.min: "min",
np.nanmin: "min",
np.cumprod: "cumprod",
np.nancumprod: "cumprod",
np.cumsum: "cumsum",
np.nancumsum: "cumsum",
}

@property
def _selection_name(self):
Expand Down Expand Up @@ -328,7 +323,7 @@ def _aggregate(self, arg, *args, **kwargs):
# eg. {'A' : ['mean']}, normalize all to
# be list-likes
if any(is_aggregator(x) for x in arg.values()):
new_arg = OrderedDict()
new_arg = {}
for k, v in arg.items():
if not isinstance(v, (tuple, list, dict)):
new_arg[k] = [v]
Expand Down Expand Up @@ -386,16 +381,16 @@ def _agg_2dim(name, how):
def _agg(arg, func):
"""
run the aggregations over the arg with func
return an OrderedDict
return a dict
"""
result = OrderedDict()
result = {}
for fname, agg_how in arg.items():
result[fname] = func(fname, agg_how)
return result

# set the final keys
keys = list(arg.keys())
result = OrderedDict()
result = {}

if self._selection is not None:

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/json/_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import OrderedDict, abc
from collections import abc
import functools
from io import StringIO
from itertools import islice
Expand Down Expand Up @@ -331,7 +331,7 @@ def _write(
default_handler,
indent,
):
table_obj = OrderedDict((("schema", self.schema), ("data", obj)))
table_obj = {"schema": self.schema, "data": obj}
serialized = super()._write(
table_obj,
orient,
Expand Down
26 changes: 12 additions & 14 deletions pandas/tests/series/test_apply.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import Counter, OrderedDict, defaultdict
from collections import Counter, defaultdict
from itertools import chain

import numpy as np
Expand Down Expand Up @@ -297,18 +297,16 @@ def test_replicate_describe(self, string_series):
# this also tests a result set that is all scalars
expected = string_series.describe()
result = string_series.apply(
OrderedDict(
[
("count", "count"),
("mean", "mean"),
("std", "std"),
("min", "min"),
("25%", lambda x: x.quantile(0.25)),
("50%", "median"),
("75%", lambda x: x.quantile(0.75)),
("max", "max"),
]
)
{
"count": "count",
"mean": "mean",
"std": "std",
"min": "min",
"25%": lambda x: x.quantile(0.25),
"50%": "median",
"75%": lambda x: x.quantile(0.75),
"max": "max",
}
)
tm.assert_series_equal(result, expected)

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

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

@pytest.mark.parametrize(
Expand Down