Skip to content

New dict call fixings #38138 #38298

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 1 commit into from
Dec 4, 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
4 changes: 2 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from pandas.core.missing import get_fill_func
from pandas.core.sorting import nargminmax, nargsort

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

ExtensionArrayT = TypeVar("ExtensionArrayT", bound="ExtensionArray")

Expand Down Expand Up @@ -952,7 +952,7 @@ def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, ExtensionArray]:
@Substitution(klass="ExtensionArray")
@Appender(_extension_array_shared_docs["repeat"])
def repeat(self, repeats, axis=None):
nv.validate_repeat(tuple(), dict(axis=axis))
nv.validate_repeat(tuple(), {"axis": axis})
ind = np.arange(len(self)).repeat(repeats)
return self.take(ind)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
queryables: Optional[Dict[str, Any]] = None,
):
super().__init__(level + 1, global_dict=global_dict, local_dict=local_dict)
self.queryables = queryables or dict()
self.queryables = queryables or {}


class Term(ops.Term):
Expand Down
22 changes: 11 additions & 11 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@

_unsortable_types = frozenset(("mixed", "mixed-integer"))

_index_doc_kwargs = dict(
klass="Index",
inplace="",
target_klass="Index",
raises_section="",
unique="Index",
duplicated="np.ndarray",
)
_index_shared_docs = dict()
_index_doc_kwargs = {
"klass": "Index",
"inplace": "",
"target_klass": "Index",
"raises_section": "",
"unique": "Index",
"duplicated": "np.ndarray",
}
_index_shared_docs = {}
str_t = str


Expand Down Expand Up @@ -817,7 +817,7 @@ def _maybe_disallow_fill(self, allow_fill: bool, fill_value, indices) -> bool:
@Appender(_index_shared_docs["repeat"] % _index_doc_kwargs)
def repeat(self, repeats, axis=None):
repeats = ensure_platform_int(repeats)
nv.validate_repeat(tuple(), dict(axis=axis))
nv.validate_repeat(tuple(), {"axis": axis})
return self._shallow_copy(self._values.repeat(repeats))

# --------------------------------------------------------------------
Expand Down Expand Up @@ -2155,7 +2155,7 @@ def is_all_dates(self):
# Pickle Methods

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

Expand Down
58 changes: 29 additions & 29 deletions pandas/core/ops/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def add_flex_arithmetic_methods(cls):
flex_arith_method, flex_comp_method = _get_method_wrappers(cls)
new_methods = _create_methods(cls, flex_arith_method, flex_comp_method)
new_methods.update(
dict(
multiply=new_methods["mul"],
subtract=new_methods["sub"],
divide=new_methods["div"],
)
{
"multiply": new_methods["mul"],
"subtract": new_methods["sub"],
"divide": new_methods["div"],
}
)
# opt out of bool flex methods for now
assert not any(kname in new_methods for kname in ("ror_", "rxor", "rand_"))
Expand All @@ -84,22 +84,22 @@ def _create_methods(cls, arith_method, comp_method):
new_methods = {}

new_methods.update(
dict(
add=arith_method(operator.add),
radd=arith_method(radd),
sub=arith_method(operator.sub),
mul=arith_method(operator.mul),
truediv=arith_method(operator.truediv),
floordiv=arith_method(operator.floordiv),
mod=arith_method(operator.mod),
pow=arith_method(operator.pow),
rmul=arith_method(rmul),
rsub=arith_method(rsub),
rtruediv=arith_method(rtruediv),
rfloordiv=arith_method(rfloordiv),
rpow=arith_method(rpow),
rmod=arith_method(rmod),
)
{
"add": arith_method(operator.add),
"radd": arith_method(radd),
"sub": arith_method(operator.sub),
"mul": arith_method(operator.mul),
"truediv": arith_method(operator.truediv),
"floordiv": arith_method(operator.floordiv),
"mod": arith_method(operator.mod),
"pow": arith_method(operator.pow),
"rmul": arith_method(rmul),
"rsub": arith_method(rsub),
"rtruediv": arith_method(rtruediv),
"rfloordiv": arith_method(rfloordiv),
"rpow": arith_method(rpow),
"rmod": arith_method(rmod),
}
)
new_methods["div"] = new_methods["truediv"]
new_methods["rdiv"] = new_methods["rtruediv"]
Expand All @@ -109,14 +109,14 @@ def _create_methods(cls, arith_method, comp_method):
new_methods["rdivmod"] = arith_method(rdivmod)

new_methods.update(
dict(
eq=comp_method(operator.eq),
ne=comp_method(operator.ne),
lt=comp_method(operator.lt),
gt=comp_method(operator.gt),
le=comp_method(operator.le),
ge=comp_method(operator.ge),
)
{
"eq": comp_method(operator.eq),
"ne": comp_method(operator.ne),
"lt": comp_method(operator.lt),
"gt": comp_method(operator.gt),
"le": comp_method(operator.le),
"ge": comp_method(operator.ge),
}
)

new_methods = {k.strip("_"): v for k, v in new_methods.items()}
Expand Down
16 changes: 8 additions & 8 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str):
val_kind = _ensure_decoded(self.kind)
values = _maybe_convert(values, val_kind, encoding, errors)

kwargs = dict()
kwargs = {}
kwargs["name"] = _ensure_decoded(self.index_name)

if self.freq is not None:
Expand Down Expand Up @@ -3237,7 +3237,7 @@ def __init__(
self.non_index_axes = non_index_axes or []
self.values_axes = values_axes or []
self.data_columns = data_columns or []
self.info = info or dict()
self.info = info or {}
self.nan_rep = nan_rep

@property
Expand Down Expand Up @@ -3446,7 +3446,7 @@ def get_attrs(self):
""" retrieve our attributes """
self.non_index_axes = getattr(self.attrs, "non_index_axes", None) or []
self.data_columns = getattr(self.attrs, "data_columns", None) or []
self.info = getattr(self.attrs, "info", None) or dict()
self.info = getattr(self.attrs, "info", None) or {}
self.nan_rep = getattr(self.attrs, "nan_rep", None)
self.encoding = _ensure_encoding(getattr(self.attrs, "encoding", None))
self.errors = _ensure_decoded(getattr(self.attrs, "errors", "strict"))
Expand Down Expand Up @@ -3596,7 +3596,7 @@ def create_index(self, columns=None, optlevel=None, kind: Optional[str] = None):
if not isinstance(columns, (tuple, list)):
columns = [columns]

kw = dict()
kw = {}
if optlevel is not None:
kw["optlevel"] = optlevel
if kind is not None:
Expand Down Expand Up @@ -3689,7 +3689,7 @@ def validate_data_columns(self, data_columns, min_itemsize, non_index_axes):
return []

axis, axis_labels = non_index_axes[0]
info = self.info.get(axis, dict())
info = self.info.get(axis, {})
if info.get("type") == "MultiIndex" and data_columns:
raise ValueError(
f"cannot use a multi-index on axis [{axis}] with "
Expand Down Expand Up @@ -4071,7 +4071,7 @@ def create_description(
if expectedrows is None:
expectedrows = max(self.nrows_expected, 10000)

d = dict(name="table", expectedrows=expectedrows)
d = {"name": "table", "expectedrows": expectedrows}

# description from the axes & values
d["description"] = {a.cname: a.typ for a in self.axes}
Expand Down Expand Up @@ -4458,9 +4458,9 @@ def read(
result = self._read_axes(where=where, start=start, stop=stop)

info = (
self.info.get(self.non_index_axes[0][0], dict())
self.info.get(self.non_index_axes[0][0], {})
if len(self.non_index_axes)
else dict()
else {}
)

inds = [i for i, ax in enumerate(self.axes) if ax is self.index_axes[0]]
Expand Down