Skip to content

CLN: fix flake8 C408 part 2 #38116

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
Nov 28, 2020
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
18 changes: 9 additions & 9 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,15 +2167,15 @@ def makeCustomIndex(
names = [names]

# specific 1D index type requested?
idx_func = dict(
i=makeIntIndex,
f=makeFloatIndex,
s=makeStringIndex,
u=makeUnicodeIndex,
dt=makeDateIndex,
td=makeTimedeltaIndex,
p=makePeriodIndex,
).get(idx_type)
idx_func = {
"i": makeIntIndex,
"f": makeFloatIndex,
"s": makeStringIndex,
"u": makeUnicodeIndex,
"dt": makeDateIndex,
"td": makeTimedeltaIndex,
"p": makePeriodIndex,
}.get(idx_type)
if idx_func:
# pandas\_testing.py:2120: error: Cannot call function of unknown type
idx = idx_func(nentries) # type: ignore[operator]
Expand Down
16 changes: 8 additions & 8 deletions pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __call__(
raise ValueError(f"invalid validation method '{method}'")


ARGMINMAX_DEFAULTS = dict(out=None)
ARGMINMAX_DEFAULTS = {"out": None}
validate_argmin = CompatValidator(
ARGMINMAX_DEFAULTS, fname="argmin", method="both", max_fname_arg_count=1
)
Expand Down Expand Up @@ -151,7 +151,7 @@ def validate_argsort_with_ascending(ascending, args, kwargs):
return ascending


CLIP_DEFAULTS: Dict[str, Any] = dict(out=None)
CLIP_DEFAULTS: Dict[str, Any] = {"out": None}
validate_clip = CompatValidator(
CLIP_DEFAULTS, fname="clip", method="both", max_fname_arg_count=3
)
Expand Down Expand Up @@ -208,28 +208,28 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
ALLANY_DEFAULTS, fname="any", method="both", max_fname_arg_count=1
)

LOGICAL_FUNC_DEFAULTS = dict(out=None, keepdims=False)
LOGICAL_FUNC_DEFAULTS = {"out": None, "keepdims": False}
validate_logical_func = CompatValidator(LOGICAL_FUNC_DEFAULTS, method="kwargs")

MINMAX_DEFAULTS = dict(axis=None, out=None, keepdims=False)
MINMAX_DEFAULTS = {"axis": None, "out": None, "keepdims": False}
validate_min = CompatValidator(
MINMAX_DEFAULTS, fname="min", method="both", max_fname_arg_count=1
)
validate_max = CompatValidator(
MINMAX_DEFAULTS, fname="max", method="both", max_fname_arg_count=1
)

RESHAPE_DEFAULTS: Dict[str, str] = dict(order="C")
RESHAPE_DEFAULTS: Dict[str, str] = {"order": "C"}
validate_reshape = CompatValidator(
RESHAPE_DEFAULTS, fname="reshape", method="both", max_fname_arg_count=1
)

REPEAT_DEFAULTS: Dict[str, Any] = dict(axis=None)
REPEAT_DEFAULTS: Dict[str, Any] = {"axis": None}
validate_repeat = CompatValidator(
REPEAT_DEFAULTS, fname="repeat", method="both", max_fname_arg_count=1
)

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


TRANSPOSE_DEFAULTS = dict(axes=None)
TRANSPOSE_DEFAULTS = {"axes": None}
validate_transpose = CompatValidator(
TRANSPOSE_DEFAULTS, fname="transpose", method="both", max_fname_arg_count=0
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def repeat(
--------
numpy.ndarray.repeat
"""
nv.validate_repeat(tuple(), dict(axis=axis))
nv.validate_repeat((), {"axis": axis})
new_data = self._ndarray.repeat(repeats, axis=axis)
return self._from_backing_data(new_data)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

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

_sparray_doc_kwargs = dict(klass="SparseArray")
_sparray_doc_kwargs = {"klass": "SparseArray"}


def _get_fill(arr: "SparseArray") -> np.ndarray:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def sum(
min_count: int = 0,
):
nv.validate_sum(
(), dict(dtype=dtype, out=out, keepdims=keepdims, initial=initial)
(), {"dtype": dtype, "out": out, "keepdims": keepdims, "initial": initial}
)

result = nanops.nansum(
Expand All @@ -391,7 +391,7 @@ def std(
skipna: bool = True,
):
nv.validate_stat_ddof_func(
(), dict(dtype=dtype, out=out, keepdims=keepdims), fname="std"
(), {"dtype": dtype, "out": out, "keepdims": keepdims}, fname="std"
)

result = nanops.nanstd(self._ndarray, axis=axis, skipna=skipna, ddof=ddof)
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
if TYPE_CHECKING:
from pandas import Categorical

_shared_docs: Dict[str, str] = dict()
_indexops_doc_kwargs = dict(
klass="IndexOpsMixin",
inplace="",
unique="IndexOpsMixin",
duplicated="IndexOpsMixin",
)
_shared_docs: Dict[str, str] = {}
_indexops_doc_kwargs = {
"klass": "IndexOpsMixin",
"inplace": "",
"unique": "IndexOpsMixin",
"duplicated": "IndexOpsMixin",
}

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def create_pandas_abc_type(name, attr, comp):
def _check(cls, inst) -> bool:
return getattr(inst, attr, "_typ") in comp

dct = dict(__instancecheck__=_check, __subclasscheck__=_check)
dct = {"__instancecheck__": _check, "__subclasscheck__": _check}
meta = type("ABCBase", (type,), dct)
return meta(name, tuple(), dct)
return meta(name, (), dct)


ABCInt64Index = create_pandas_abc_type("ABCInt64Index", "_typ", ("int64index",))
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class providing the base-class of operations.
to each row or column of a DataFrame.
"""

_apply_docs = dict(
template="""
_apply_docs = {
"template": """
Apply function `func` group-wise and combine the results together.

The function passed to `apply` must take a {input} as its first
Expand Down Expand Up @@ -123,7 +123,7 @@ class providing the base-class of operations.
Series.apply : Apply a function to a Series.
DataFrame.apply : Apply a function to each row or column of a DataFrame.
""",
dataframe_examples="""
"dataframe_examples": """
>>> df = pd.DataFrame({'A': 'a a b'.split(),
'B': [1,2,3],
'C': [4,6, 5]})
Expand Down Expand Up @@ -163,7 +163,7 @@ class providing the base-class of operations.
b 2
dtype: int64
""",
series_examples="""
"series_examples": """
>>> s = pd.Series([0, 1, 2], index='a a b'.split())
>>> g = s.groupby(s.index)

Expand Down Expand Up @@ -202,7 +202,7 @@ class providing the base-class of operations.
--------
{examples}
""",
)
}

_groupby_agg_method_template = """
Compute {fname} of group values.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import pandas.core.missing as missing

_index_doc_kwargs = dict(ibase._index_doc_kwargs)
_index_doc_kwargs.update(dict(target_klass="CategoricalIndex"))
_index_doc_kwargs.update({"target_klass": "CategoricalIndex"})


@inherit_names(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __contains__(self, key: Any) -> bool:

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

maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def __reduce__(self):
# we use a special reduce here because we need
# to simply set the .tz (and not reinterpret it)

d = dict(data=self._data)
d = {"data": self._data}
d.update(self._get_attributes_dict())
return _new_DatetimeIndex, (type(self), d), None

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _get_engine_target(self) -> np.ndarray:
return np.asarray(self._data)

def repeat(self, repeats, axis=None):
nv.validate_repeat(tuple(), dict(axis=axis))
nv.validate_repeat((), {"axis": axis})
result = self._data.repeat(repeats, axis=axis)
return type(self)._simple_new(result, name=self.name)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from pandas.core.ops import get_op_result_name

_index_doc_kwargs = dict(ibase._index_doc_kwargs)
_index_doc_kwargs.update(dict(target_klass="PeriodIndex or list of Periods"))
_index_doc_kwargs.update({"target_klass": "PeriodIndex or list of Periods"})

# --- Period index sketch

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __getstate__(self):
"0.14.1": {
"axes": axes_array,
"blocks": [
dict(values=b.values, mgr_locs=b.mgr_locs.indexer)
{"values": b.values, "mgr_locs": b.mgr_locs.indexer}
for b in self.blocks
],
}
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from pandas.tseries.frequencies import is_subperiod, is_superperiod
from pandas.tseries.offsets import DateOffset, Day, Nano, Tick

_shared_docs_kwargs: Dict[str, str] = dict()
_shared_docs_kwargs: Dict[str, str] = {}


class Resampler(BaseGroupBy, ShallowMixin):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pandas import DataFrame, Series


@Appender(_shared_docs["melt"] % dict(caller="pd.melt(df, ", other="DataFrame.melt"))
@Appender(_shared_docs["melt"] % {"caller": "pd.melt(df, ", "other": "DataFrame.melt"})
def melt(
frame: "DataFrame",
id_vars=None,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/shared_docs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict

_shared_docs: Dict[str, str] = dict()
_shared_docs: Dict[str, str] = {}

_shared_docs[
"aggregate"
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/util/numba_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pandas.errors import NumbaUtilError

GLOBAL_USE_NUMBA: bool = False
NUMBA_FUNC_CACHE: Dict[Tuple[Callable, str], Callable] = dict()
NUMBA_FUNC_CACHE: Dict[Tuple[Callable, str], Callable] = {}


def maybe_use_numba(engine: Optional[str]) -> bool:
Expand Down
14 changes: 7 additions & 7 deletions pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def _initialize_chunksize(self, chunksize: Optional[int]) -> int:
@property
def _number_format(self) -> Dict[str, Any]:
"""Dictionary used for storing number formatting settings."""
return dict(
na_rep=self.na_rep,
float_format=self.float_format,
date_format=self.date_format,
quoting=self.quoting,
decimal=self.decimal,
)
return {
"na_rep": self.na_rep,
"float_format": self.float_format,
"date_format": self.date_format,
"quoting": self.quoting,
"decimal": self.decimal,
}

@property
def data_index(self) -> Index:
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def as_escaped_string(
translate = escape_chars
escape_chars = list(escape_chars.keys())
else:
escape_chars = escape_chars or tuple()
escape_chars = escape_chars or ()

result = str(thing)
for c in escape_chars:
Expand Down
20 changes: 10 additions & 10 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,16 @@ def format_attr(pair):
else:
table_attr += ' class="tex2jax_ignore"'

return dict(
head=head,
cellstyle=cellstyle,
body=body,
uuid=uuid,
precision=precision,
table_styles=table_styles,
caption=caption,
table_attributes=table_attr,
)
return {
"head": head,
"cellstyle": cellstyle,
"body": body,
"uuid": uuid,
"precision": precision,
"table_styles": table_styles,
"caption": caption,
"table_attributes": table_attr,
}

def format(self, formatter, subset=None, na_rep: Optional[str] = None) -> "Styler":
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ def _process_converter(self, f, filt=None):
assert obj is not None # for mypy

needs_new_obj = False
new_obj = dict()
new_obj = {}
for i, (col, c) in enumerate(obj.items()):
if filt(col, c):
new_data, result = f(col, c)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ def _read_value_labels(self) -> None:
off = off[ii]
val = val[ii]
txt = self.path_or_buf.read(txtlen)
self.value_label_dict[labname] = dict()
self.value_label_dict[labname] = {}
for i in range(n):
end = off[i + 1] if i < n - 1 else txtlen
self.value_label_dict[labname][val[i]] = self._decode(txt[off[i] : end])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def test_operators_timedelta64(self):
tm.assert_series_equal(rs, xp)
assert rs.dtype == "timedelta64[ns]"

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

Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/arrays/categorical/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def test_set_item_nan(self):
"fillna_kwargs, msg",
[
(
dict(value=1, method="ffill"),
{"value": 1, "method": "ffill"},
"Cannot specify both 'value' and 'method'.",
),
(dict(), "Must specify a fill 'value' or 'method'."),
(dict(method="bad"), "Invalid fill method. Expecting .* bad"),
({}, "Must specify a fill 'value' or 'method'."),
({"method": "bad"}, "Invalid fill method. Expecting .* bad"),
(
dict(value=Series([1, 2, 3, 4, "a"])),
{"value": Series([1, 2, 3, 4, "a"])},
"Cannot setitem on a Categorical with a new category",
),
],
Expand Down
Loading