Skip to content

Commit 946326a

Browse files
authored
CLN: OrderedDict->dict (#36693)
1 parent 8f26d87 commit 946326a

File tree

11 files changed

+27
-49
lines changed

11 files changed

+27
-49
lines changed

pandas/compat/numpy/function.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
and methods that are spread throughout the codebase. This module will make it
1818
easier to adjust to future upstream changes in the analogous numpy signatures.
1919
"""
20-
from collections import OrderedDict
2120
from distutils.version import LooseVersion
2221
from typing import Any, Dict, Optional, Union
2322

@@ -117,7 +116,7 @@ def validate_argmax_with_skipna(skipna, args, kwargs):
117116
return skipna
118117

119118

120-
ARGSORT_DEFAULTS: "OrderedDict[str, Optional[Union[int, str]]]" = OrderedDict()
119+
ARGSORT_DEFAULTS: Dict[str, Optional[Union[int, str]]] = {}
121120
ARGSORT_DEFAULTS["axis"] = -1
122121
ARGSORT_DEFAULTS["kind"] = "quicksort"
123122
ARGSORT_DEFAULTS["order"] = None
@@ -133,7 +132,7 @@ def validate_argmax_with_skipna(skipna, args, kwargs):
133132

134133
# two different signatures of argsort, this second validation
135134
# for when the `kind` param is supported
136-
ARGSORT_DEFAULTS_KIND: "OrderedDict[str, Optional[int]]" = OrderedDict()
135+
ARGSORT_DEFAULTS_KIND: Dict[str, Optional[int]] = {}
137136
ARGSORT_DEFAULTS_KIND["axis"] = -1
138137
ARGSORT_DEFAULTS_KIND["order"] = None
139138
validate_argsort_kind = CompatValidator(
@@ -178,7 +177,7 @@ def validate_clip_with_axis(axis, args, kwargs):
178177
return axis
179178

180179

181-
CUM_FUNC_DEFAULTS: "OrderedDict[str, Any]" = OrderedDict()
180+
CUM_FUNC_DEFAULTS: Dict[str, Any] = {}
182181
CUM_FUNC_DEFAULTS["dtype"] = None
183182
CUM_FUNC_DEFAULTS["out"] = None
184183
validate_cum_func = CompatValidator(
@@ -204,7 +203,7 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
204203
return skipna
205204

206205

207-
ALLANY_DEFAULTS: "OrderedDict[str, Optional[bool]]" = OrderedDict()
206+
ALLANY_DEFAULTS: Dict[str, Optional[bool]] = {}
208207
ALLANY_DEFAULTS["dtype"] = None
209208
ALLANY_DEFAULTS["out"] = None
210209
ALLANY_DEFAULTS["keepdims"] = False
@@ -241,13 +240,13 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
241240
ROUND_DEFAULTS, fname="round", method="both", max_fname_arg_count=1
242241
)
243242

244-
SORT_DEFAULTS: "OrderedDict[str, Optional[Union[int, str]]]" = OrderedDict()
243+
SORT_DEFAULTS: Dict[str, Optional[Union[int, str]]] = {}
245244
SORT_DEFAULTS["axis"] = -1
246245
SORT_DEFAULTS["kind"] = "quicksort"
247246
SORT_DEFAULTS["order"] = None
248247
validate_sort = CompatValidator(SORT_DEFAULTS, fname="sort", method="kwargs")
249248

250-
STAT_FUNC_DEFAULTS: "OrderedDict[str, Optional[Any]]" = OrderedDict()
249+
STAT_FUNC_DEFAULTS: Dict[str, Optional[Any]] = {}
251250
STAT_FUNC_DEFAULTS["dtype"] = None
252251
STAT_FUNC_DEFAULTS["out"] = None
253252

@@ -281,13 +280,13 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
281280
MEDIAN_DEFAULTS, fname="median", method="both", max_fname_arg_count=1
282281
)
283282

284-
STAT_DDOF_FUNC_DEFAULTS: "OrderedDict[str, Optional[bool]]" = OrderedDict()
283+
STAT_DDOF_FUNC_DEFAULTS: Dict[str, Optional[bool]] = {}
285284
STAT_DDOF_FUNC_DEFAULTS["dtype"] = None
286285
STAT_DDOF_FUNC_DEFAULTS["out"] = None
287286
STAT_DDOF_FUNC_DEFAULTS["keepdims"] = False
288287
validate_stat_ddof_func = CompatValidator(STAT_DDOF_FUNC_DEFAULTS, method="kwargs")
289288

290-
TAKE_DEFAULTS: "OrderedDict[str, Optional[str]]" = OrderedDict()
289+
TAKE_DEFAULTS: Dict[str, Optional[str]] = {}
291290
TAKE_DEFAULTS["out"] = None
292291
TAKE_DEFAULTS["mode"] = "raise"
293292
validate_take = CompatValidator(TAKE_DEFAULTS, fname="take", method="kwargs")

pandas/tests/frame/apply/test_frame_apply.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from datetime import datetime
32
from itertools import chain
43
import warnings
@@ -1225,7 +1224,7 @@ def test_agg_reduce(self, axis, float_frame):
12251224
tm.assert_frame_equal(result, expected)
12261225

12271226
# dict input with scalars
1228-
func = OrderedDict([(name1, "mean"), (name2, "sum")])
1227+
func = dict([(name1, "mean"), (name2, "sum")])
12291228
result = float_frame.agg(func, axis=axis)
12301229
expected = Series(
12311230
[
@@ -1237,7 +1236,7 @@ def test_agg_reduce(self, axis, float_frame):
12371236
tm.assert_series_equal(result, expected)
12381237

12391238
# dict input with lists
1240-
func = OrderedDict([(name1, ["mean"]), (name2, ["sum"])])
1239+
func = dict([(name1, ["mean"]), (name2, ["sum"])])
12411240
result = float_frame.agg(func, axis=axis)
12421241
expected = DataFrame(
12431242
{
@@ -1253,10 +1252,10 @@ def test_agg_reduce(self, axis, float_frame):
12531252
tm.assert_frame_equal(result, expected)
12541253

12551254
# dict input with lists with multiple
1256-
func = OrderedDict([(name1, ["mean", "sum"]), (name2, ["sum", "max"])])
1255+
func = dict([(name1, ["mean", "sum"]), (name2, ["sum", "max"])])
12571256
result = float_frame.agg(func, axis=axis)
12581257
expected = DataFrame(
1259-
OrderedDict(
1258+
dict(
12601259
[
12611260
(
12621261
name1,

pandas/tests/frame/methods/test_select_dtypes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from collections import OrderedDict
2-
31
import numpy as np
42
import pytest
53

@@ -202,9 +200,8 @@ def test_select_dtypes_include_exclude_mixed_scalars_lists(self):
202200

203201
def test_select_dtypes_duplicate_columns(self):
204202
# GH20839
205-
odict = OrderedDict
206203
df = DataFrame(
207-
odict(
204+
dict(
208205
[
209206
("a", list("abc")),
210207
("b", list(range(1, 4))),

pandas/tests/frame/test_dtypes.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from datetime import timedelta
32

43
import numpy as np
@@ -50,10 +49,9 @@ def test_empty_frame_dtypes(self):
5049
norows_int_df.dtypes, pd.Series(np.dtype("int32"), index=list("abc"))
5150
)
5251

53-
odict = OrderedDict
54-
df = pd.DataFrame(odict([("a", 1), ("b", True), ("c", 1.0)]), index=[1, 2, 3])
52+
df = pd.DataFrame(dict([("a", 1), ("b", True), ("c", 1.0)]), index=[1, 2, 3])
5553
ex_dtypes = pd.Series(
56-
odict([("a", np.int64), ("b", np.bool_), ("c", np.float64)])
54+
dict([("a", np.int64), ("b", np.bool_), ("c", np.float64)])
5755
)
5856
tm.assert_series_equal(df.dtypes, ex_dtypes)
5957

@@ -85,17 +83,16 @@ def test_datetime_with_tz_dtypes(self):
8583
def test_dtypes_are_correct_after_column_slice(self):
8684
# GH6525
8785
df = pd.DataFrame(index=range(5), columns=list("abc"), dtype=np.float_)
88-
odict = OrderedDict
8986
tm.assert_series_equal(
9087
df.dtypes,
91-
pd.Series(odict([("a", np.float_), ("b", np.float_), ("c", np.float_)])),
88+
pd.Series(dict([("a", np.float_), ("b", np.float_), ("c", np.float_)])),
9289
)
9390
tm.assert_series_equal(
94-
df.iloc[:, 2:].dtypes, pd.Series(odict([("c", np.float_)]))
91+
df.iloc[:, 2:].dtypes, pd.Series(dict([("c", np.float_)]))
9592
)
9693
tm.assert_series_equal(
9794
df.dtypes,
98-
pd.Series(odict([("a", np.float_), ("b", np.float_), ("c", np.float_)])),
95+
pd.Series(dict([("a", np.float_), ("b", np.float_), ("c", np.float_)])),
9996
)
10097

10198
def test_dtypes_gh8722(self, float_string_frame):

pandas/tests/internals/test_internals.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from datetime import date, datetime
32
import itertools
43
import operator
@@ -165,7 +164,7 @@ def create_mgr(descr, item_shape=None):
165164

166165
offset = 0
167166
mgr_items = []
168-
block_placements = OrderedDict()
167+
block_placements = {}
169168
for d in descr.split(";"):
170169
d = d.strip()
171170
if not len(d):

pandas/tests/io/json/test_pandas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
import datetime
32
from datetime import timedelta
43
from io import StringIO
@@ -470,7 +469,7 @@ def test_blocks_compat_GH9037(self):
470469
index = pd.DatetimeIndex(list(index), freq=None)
471470

472471
df_mixed = DataFrame(
473-
OrderedDict(
472+
dict(
474473
float_1=[
475474
-0.92077639,
476475
0.77434435,

pandas/tests/resample/test_resample_api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from datetime import datetime
32

43
import numpy as np
@@ -428,7 +427,7 @@ def test_agg_misc():
428427
msg = r"Column\(s\) \['result1', 'result2'\] do not exist"
429428
for t in cases:
430429
with pytest.raises(pd.core.base.SpecificationError, match=msg):
431-
t[["A", "B"]].agg(OrderedDict([("result1", np.sum), ("result2", np.mean)]))
430+
t[["A", "B"]].agg(dict([("result1", np.sum), ("result2", np.mean)]))
432431

433432
# agg with different hows
434433
expected = pd.concat(
@@ -438,7 +437,7 @@ def test_agg_misc():
438437
[("A", "sum"), ("A", "std"), ("B", "mean"), ("B", "std")]
439438
)
440439
for t in cases:
441-
result = t.agg(OrderedDict([("A", ["sum", "std"]), ("B", ["mean", "std"])]))
440+
result = t.agg(dict([("A", ["sum", "std"]), ("B", ["mean", "std"])]))
442441
tm.assert_frame_equal(result, expected, check_like=True)
443442

444443
# equivalent of using a selection list / or not

pandas/tests/reshape/merge/test_merge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from datetime import date, datetime, timedelta
32
import random
43
import re
@@ -1931,7 +1930,7 @@ def test_merge_index_types(index):
19311930
result = left.merge(right, on=["index_col"])
19321931

19331932
expected = DataFrame(
1934-
OrderedDict([("left_data", [1, 2]), ("right_data", [1.0, 2.0])]), index=index
1933+
dict([("left_data", [1, 2]), ("right_data", [1.0, 2.0])]), index=index
19351934
)
19361935
tm.assert_frame_equal(result, expected)
19371936

pandas/tests/reshape/test_concat.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import OrderedDict, abc, deque
1+
from collections import abc, deque
22
import datetime as dt
33
from datetime import datetime
44
from decimal import Decimal
@@ -2609,9 +2609,7 @@ def test_concat_odered_dict(self):
26092609
[pd.Series(range(3)), pd.Series(range(4))], keys=["First", "Another"]
26102610
)
26112611
result = pd.concat(
2612-
OrderedDict(
2613-
[("First", pd.Series(range(3))), ("Another", pd.Series(range(4)))]
2614-
)
2612+
dict([("First", pd.Series(range(3))), ("Another", pd.Series(range(4)))])
26152613
)
26162614
tm.assert_series_equal(result, expected)
26172615

pandas/tests/reshape/test_get_dummies.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from collections import OrderedDict
2-
31
import numpy as np
42
import pytest
53

@@ -569,9 +567,7 @@ def test_dataframe_dummies_preserve_categorical_dtype(self, dtype, ordered):
569567
@pytest.mark.parametrize("sparse", [True, False])
570568
def test_get_dummies_dont_sparsify_all_columns(self, sparse):
571569
# GH18914
572-
df = DataFrame.from_dict(
573-
OrderedDict([("GDP", [1, 2]), ("Nation", ["AB", "CD"])])
574-
)
570+
df = DataFrame.from_dict(dict([("GDP", [1, 2]), ("Nation", ["AB", "CD"])]))
575571
df = get_dummies(df, columns=["Nation"], sparse=sparse)
576572
df2 = df.reindex(columns=["GDP"])
577573

pandas/tests/window/test_api.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from collections import OrderedDict
2-
31
import numpy as np
42
import pytest
53

@@ -335,8 +333,6 @@ def test_multiple_agg_funcs(func, window_size, expected_vals):
335333
)
336334
expected = pd.DataFrame(expected_vals, index=index, columns=columns)
337335

338-
result = window.agg(
339-
OrderedDict((("low", ["mean", "max"]), ("high", ["mean", "min"])))
340-
)
336+
result = window.agg(dict((("low", ["mean", "max"]), ("high", ["mean", "min"]))))
341337

342338
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)