Skip to content

Commit 25846e9

Browse files
authored
CLN: fix flake8 C408 part 2 (#38116)
1 parent 1c26b1c commit 25846e9

File tree

76 files changed

+271
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+271
-255
lines changed

pandas/_testing.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2167,15 +2167,15 @@ def makeCustomIndex(
21672167
names = [names]
21682168

21692169
# specific 1D index type requested?
2170-
idx_func = dict(
2171-
i=makeIntIndex,
2172-
f=makeFloatIndex,
2173-
s=makeStringIndex,
2174-
u=makeUnicodeIndex,
2175-
dt=makeDateIndex,
2176-
td=makeTimedeltaIndex,
2177-
p=makePeriodIndex,
2178-
).get(idx_type)
2170+
idx_func = {
2171+
"i": makeIntIndex,
2172+
"f": makeFloatIndex,
2173+
"s": makeStringIndex,
2174+
"u": makeUnicodeIndex,
2175+
"dt": makeDateIndex,
2176+
"td": makeTimedeltaIndex,
2177+
"p": makePeriodIndex,
2178+
}.get(idx_type)
21792179
if idx_func:
21802180
# pandas\_testing.py:2120: error: Cannot call function of unknown type
21812181
idx = idx_func(nentries) # type: ignore[operator]

pandas/compat/numpy/function.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __call__(
7171
raise ValueError(f"invalid validation method '{method}'")
7272

7373

74-
ARGMINMAX_DEFAULTS = dict(out=None)
74+
ARGMINMAX_DEFAULTS = {"out": None}
7575
validate_argmin = CompatValidator(
7676
ARGMINMAX_DEFAULTS, fname="argmin", method="both", max_fname_arg_count=1
7777
)
@@ -151,7 +151,7 @@ def validate_argsort_with_ascending(ascending, args, kwargs):
151151
return ascending
152152

153153

154-
CLIP_DEFAULTS: Dict[str, Any] = dict(out=None)
154+
CLIP_DEFAULTS: Dict[str, Any] = {"out": None}
155155
validate_clip = CompatValidator(
156156
CLIP_DEFAULTS, fname="clip", method="both", max_fname_arg_count=3
157157
)
@@ -208,28 +208,28 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
208208
ALLANY_DEFAULTS, fname="any", method="both", max_fname_arg_count=1
209209
)
210210

211-
LOGICAL_FUNC_DEFAULTS = dict(out=None, keepdims=False)
211+
LOGICAL_FUNC_DEFAULTS = {"out": None, "keepdims": False}
212212
validate_logical_func = CompatValidator(LOGICAL_FUNC_DEFAULTS, method="kwargs")
213213

214-
MINMAX_DEFAULTS = dict(axis=None, out=None, keepdims=False)
214+
MINMAX_DEFAULTS = {"axis": None, "out": None, "keepdims": False}
215215
validate_min = CompatValidator(
216216
MINMAX_DEFAULTS, fname="min", method="both", max_fname_arg_count=1
217217
)
218218
validate_max = CompatValidator(
219219
MINMAX_DEFAULTS, fname="max", method="both", max_fname_arg_count=1
220220
)
221221

222-
RESHAPE_DEFAULTS: Dict[str, str] = dict(order="C")
222+
RESHAPE_DEFAULTS: Dict[str, str] = {"order": "C"}
223223
validate_reshape = CompatValidator(
224224
RESHAPE_DEFAULTS, fname="reshape", method="both", max_fname_arg_count=1
225225
)
226226

227-
REPEAT_DEFAULTS: Dict[str, Any] = dict(axis=None)
227+
REPEAT_DEFAULTS: Dict[str, Any] = {"axis": None}
228228
validate_repeat = CompatValidator(
229229
REPEAT_DEFAULTS, fname="repeat", method="both", max_fname_arg_count=1
230230
)
231231

232-
ROUND_DEFAULTS: Dict[str, Any] = dict(out=None)
232+
ROUND_DEFAULTS: Dict[str, Any] = {"out": None}
233233
validate_round = CompatValidator(
234234
ROUND_DEFAULTS, fname="round", method="both", max_fname_arg_count=1
235235
)
@@ -300,7 +300,7 @@ def validate_take_with_convert(convert, args, kwargs):
300300
return convert
301301

302302

303-
TRANSPOSE_DEFAULTS = dict(axes=None)
303+
TRANSPOSE_DEFAULTS = {"axes": None}
304304
validate_transpose = CompatValidator(
305305
TRANSPOSE_DEFAULTS, fname="transpose", method="both", max_fname_arg_count=0
306306
)

pandas/core/arrays/_mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def repeat(
162162
--------
163163
numpy.ndarray.repeat
164164
"""
165-
nv.validate_repeat(tuple(), dict(axis=axis))
165+
nv.validate_repeat((), {"axis": axis})
166166
new_data = self._ndarray.repeat(repeats, axis=axis)
167167
return self._from_backing_data(new_data)
168168

pandas/core/arrays/sparse/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
SparseArrayT = TypeVar("SparseArrayT", bound="SparseArray")
6060

61-
_sparray_doc_kwargs = dict(klass="SparseArray")
61+
_sparray_doc_kwargs = {"klass": "SparseArray"}
6262

6363

6464
def _get_fill(arr: "SparseArray") -> np.ndarray:

pandas/core/arrays/timedeltas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def sum(
373373
min_count: int = 0,
374374
):
375375
nv.validate_sum(
376-
(), dict(dtype=dtype, out=out, keepdims=keepdims, initial=initial)
376+
(), {"dtype": dtype, "out": out, "keepdims": keepdims, "initial": initial}
377377
)
378378

379379
result = nanops.nansum(
@@ -391,7 +391,7 @@ def std(
391391
skipna: bool = True,
392392
):
393393
nv.validate_stat_ddof_func(
394-
(), dict(dtype=dtype, out=out, keepdims=keepdims), fname="std"
394+
(), {"dtype": dtype, "out": out, "keepdims": keepdims}, fname="std"
395395
)
396396

397397
result = nanops.nanstd(self._ndarray, axis=axis, skipna=skipna, ddof=ddof)

pandas/core/base.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
if TYPE_CHECKING:
4747
from pandas import Categorical
4848

49-
_shared_docs: Dict[str, str] = dict()
50-
_indexops_doc_kwargs = dict(
51-
klass="IndexOpsMixin",
52-
inplace="",
53-
unique="IndexOpsMixin",
54-
duplicated="IndexOpsMixin",
55-
)
49+
_shared_docs: Dict[str, str] = {}
50+
_indexops_doc_kwargs = {
51+
"klass": "IndexOpsMixin",
52+
"inplace": "",
53+
"unique": "IndexOpsMixin",
54+
"duplicated": "IndexOpsMixin",
55+
}
5656

5757
_T = TypeVar("_T", bound="IndexOpsMixin")
5858

pandas/core/dtypes/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def create_pandas_abc_type(name, attr, comp):
1818
def _check(cls, inst) -> bool:
1919
return getattr(inst, attr, "_typ") in comp
2020

21-
dct = dict(__instancecheck__=_check, __subclasscheck__=_check)
21+
dct = {"__instancecheck__": _check, "__subclasscheck__": _check}
2222
meta = type("ABCBase", (type,), dct)
23-
return meta(name, tuple(), dct)
23+
return meta(name, (), dct)
2424

2525

2626
ABCInt64Index = create_pandas_abc_type("ABCInt64Index", "_typ", ("int64index",))

pandas/core/groupby/groupby.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class providing the base-class of operations.
8585
to each row or column of a DataFrame.
8686
"""
8787

88-
_apply_docs = dict(
89-
template="""
88+
_apply_docs = {
89+
"template": """
9090
Apply function `func` group-wise and combine the results together.
9191
9292
The function passed to `apply` must take a {input} as its first
@@ -123,7 +123,7 @@ class providing the base-class of operations.
123123
Series.apply : Apply a function to a Series.
124124
DataFrame.apply : Apply a function to each row or column of a DataFrame.
125125
""",
126-
dataframe_examples="""
126+
"dataframe_examples": """
127127
>>> df = pd.DataFrame({'A': 'a a b'.split(),
128128
'B': [1,2,3],
129129
'C': [4,6, 5]})
@@ -163,7 +163,7 @@ class providing the base-class of operations.
163163
b 2
164164
dtype: int64
165165
""",
166-
series_examples="""
166+
"series_examples": """
167167
>>> s = pd.Series([0, 1, 2], index='a a b'.split())
168168
>>> g = s.groupby(s.index)
169169
@@ -202,7 +202,7 @@ class providing the base-class of operations.
202202
--------
203203
{examples}
204204
""",
205-
)
205+
}
206206

207207
_groupby_agg_method_template = """
208208
Compute {fname} of group values.

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import pandas.core.missing as missing
2828

2929
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
30-
_index_doc_kwargs.update(dict(target_klass="CategoricalIndex"))
30+
_index_doc_kwargs.update({"target_klass": "CategoricalIndex"})
3131

3232

3333
@inherit_names(

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def __contains__(self, key: Any) -> bool:
200200

201201
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
202202
def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
203-
nv.validate_take(tuple(), kwargs)
203+
nv.validate_take((), kwargs)
204204
indices = np.asarray(indices, dtype=np.intp)
205205

206206
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def __reduce__(self):
337337
# we use a special reduce here because we need
338338
# to simply set the .tz (and not reinterpret it)
339339

340-
d = dict(data=self._data)
340+
d = {"data": self._data}
341341
d.update(self._get_attributes_dict())
342342
return _new_DatetimeIndex, (type(self), d), None
343343

pandas/core/indexes/extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _get_engine_target(self) -> np.ndarray:
273273
return np.asarray(self._data)
274274

275275
def repeat(self, repeats, axis=None):
276-
nv.validate_repeat(tuple(), dict(axis=axis))
276+
nv.validate_repeat((), {"axis": axis})
277277
result = self._data.repeat(repeats, axis=axis)
278278
return type(self)._simple_new(result, name=self.name)
279279

pandas/core/indexes/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from pandas.core.ops import get_op_result_name
4444

4545
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
46-
_index_doc_kwargs.update(dict(target_klass="PeriodIndex or list of Periods"))
46+
_index_doc_kwargs.update({"target_klass": "PeriodIndex or list of Periods"})
4747

4848
# --- Period index sketch
4949

pandas/core/internals/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def __getstate__(self):
267267
"0.14.1": {
268268
"axes": axes_array,
269269
"blocks": [
270-
dict(values=b.values, mgr_locs=b.mgr_locs.indexer)
270+
{"values": b.values, "mgr_locs": b.mgr_locs.indexer}
271271
for b in self.blocks
272272
],
273273
}

pandas/core/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from pandas.tseries.frequencies import is_subperiod, is_superperiod
4444
from pandas.tseries.offsets import DateOffset, Day, Nano, Tick
4545

46-
_shared_docs_kwargs: Dict[str, str] = dict()
46+
_shared_docs_kwargs: Dict[str, str] = {}
4747

4848

4949
class Resampler(BaseGroupBy, ShallowMixin):

pandas/core/reshape/melt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pandas import DataFrame, Series
2323

2424

25-
@Appender(_shared_docs["melt"] % dict(caller="pd.melt(df, ", other="DataFrame.melt"))
25+
@Appender(_shared_docs["melt"] % {"caller": "pd.melt(df, ", "other": "DataFrame.melt"})
2626
def melt(
2727
frame: "DataFrame",
2828
id_vars=None,

pandas/core/shared_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict
22

3-
_shared_docs: Dict[str, str] = dict()
3+
_shared_docs: Dict[str, str] = {}
44

55
_shared_docs[
66
"aggregate"

pandas/core/util/numba_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas.errors import NumbaUtilError
1010

1111
GLOBAL_USE_NUMBA: bool = False
12-
NUMBA_FUNC_CACHE: Dict[Tuple[Callable, str], Callable] = dict()
12+
NUMBA_FUNC_CACHE: Dict[Tuple[Callable, str], Callable] = {}
1313

1414

1515
def maybe_use_numba(engine: Optional[str]) -> bool:

pandas/io/formats/csvs.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ def _initialize_chunksize(self, chunksize: Optional[int]) -> int:
159159
@property
160160
def _number_format(self) -> Dict[str, Any]:
161161
"""Dictionary used for storing number formatting settings."""
162-
return dict(
163-
na_rep=self.na_rep,
164-
float_format=self.float_format,
165-
date_format=self.date_format,
166-
quoting=self.quoting,
167-
decimal=self.decimal,
168-
)
162+
return {
163+
"na_rep": self.na_rep,
164+
"float_format": self.float_format,
165+
"date_format": self.date_format,
166+
"quoting": self.quoting,
167+
"decimal": self.decimal,
168+
}
169169

170170
@property
171171
def data_index(self) -> Index:

pandas/io/formats/printing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def as_escaped_string(
206206
translate = escape_chars
207207
escape_chars = list(escape_chars.keys())
208208
else:
209-
escape_chars = escape_chars or tuple()
209+
escape_chars = escape_chars or ()
210210

211211
result = str(thing)
212212
for c in escape_chars:

pandas/io/formats/style.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,16 @@ def format_attr(pair):
433433
else:
434434
table_attr += ' class="tex2jax_ignore"'
435435

436-
return dict(
437-
head=head,
438-
cellstyle=cellstyle,
439-
body=body,
440-
uuid=uuid,
441-
precision=precision,
442-
table_styles=table_styles,
443-
caption=caption,
444-
table_attributes=table_attr,
445-
)
436+
return {
437+
"head": head,
438+
"cellstyle": cellstyle,
439+
"body": body,
440+
"uuid": uuid,
441+
"precision": precision,
442+
"table_styles": table_styles,
443+
"caption": caption,
444+
"table_attributes": table_attr,
445+
}
446446

447447
def format(self, formatter, subset=None, na_rep: Optional[str] = None) -> "Styler":
448448
"""

pandas/io/json/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def _process_converter(self, f, filt=None):
10981098
assert obj is not None # for mypy
10991099

11001100
needs_new_obj = False
1101-
new_obj = dict()
1101+
new_obj = {}
11021102
for i, (col, c) in enumerate(obj.items()):
11031103
if filt(col, c):
11041104
new_data, result = f(col, c)

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ def _read_value_labels(self) -> None:
14641464
off = off[ii]
14651465
val = val[ii]
14661466
txt = self.path_or_buf.read(txtlen)
1467-
self.value_label_dict[labname] = dict()
1467+
self.value_label_dict[labname] = {}
14681468
for i in range(n):
14691469
end = off[i + 1] if i < n - 1 else txtlen
14701470
self.value_label_dict[labname][val[i]] = self._decode(txt[off[i] : end])

pandas/tests/arithmetic/test_timedelta64.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def test_operators_timedelta64(self):
822822
tm.assert_series_equal(rs, xp)
823823
assert rs.dtype == "timedelta64[ns]"
824824

825-
df = DataFrame(dict(A=v1))
825+
df = DataFrame({"A": v1})
826826
td = Series([timedelta(days=i) for i in range(3)])
827827
assert td.dtype == "timedelta64[ns]"
828828

pandas/tests/arrays/categorical/test_missing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ def test_set_item_nan(self):
6262
"fillna_kwargs, msg",
6363
[
6464
(
65-
dict(value=1, method="ffill"),
65+
{"value": 1, "method": "ffill"},
6666
"Cannot specify both 'value' and 'method'.",
6767
),
68-
(dict(), "Must specify a fill 'value' or 'method'."),
69-
(dict(method="bad"), "Invalid fill method. Expecting .* bad"),
68+
({}, "Must specify a fill 'value' or 'method'."),
69+
({"method": "bad"}, "Invalid fill method. Expecting .* bad"),
7070
(
71-
dict(value=Series([1, 2, 3, 4, "a"])),
71+
{"value": Series([1, 2, 3, 4, "a"])},
7272
"Cannot setitem on a Categorical with a new category",
7373
),
7474
],

0 commit comments

Comments
 (0)