Skip to content

Fix C408 Errors in core/strings, core/arrays, core/dtypes... #38249

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

Closed
wants to merge 9 commits into from
Closed
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((), {"axis": axis})
ind = np.arange(len(self)).repeat(repeats)
return self.take(ind)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/floating.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ def astype(self, dtype, copy: bool = True) -> ArrayLike:
# coerce
if is_float_dtype(dtype):
# In astype, we consider dtype=float to also mean na_value=np.nan
kwargs = dict(na_value=np.nan)
kwargs = {"na_value": np.nan}
elif is_datetime64_dtype(dtype):
kwargs = dict(na_value=np.datetime64("NaT"))
kwargs = {"na_value": np.datetime64("NaT")}
else:
kwargs = {}

Expand Down
80 changes: 41 additions & 39 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@

_interval_shared_docs = {}

_shared_docs_kwargs = dict(
klass="IntervalArray", qualname="arrays.IntervalArray", name=""
)
_shared_docs_kwargs = {
"klass": "IntervalArray",
"qualname": "arrays.IntervalArray",
"name": "",
}


_interval_shared_docs[
Expand Down Expand Up @@ -127,14 +129,14 @@

@Appender(
_interval_shared_docs["class"]
% dict(
klass="IntervalArray",
summary="Pandas array for interval data that are closed on the same side.",
versionadded="0.24.0",
name="",
extra_attributes="",
extra_methods="",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"summary": "Pandas array for interval data that are closed on the same side.",
"versionadded": "0.24.0",
"name": "",
"extra_attributes": "",
"extra_methods": "",
"examples": textwrap.dedent(
"""\
Examples
--------
Expand All @@ -151,7 +153,7 @@
:meth:`IntervalArray.from_breaks`, and :meth:`IntervalArray.from_tuples`.
"""
),
)
}
)
class IntervalArray(IntervalMixin, ExtensionArray):
ndim = 1
Expand Down Expand Up @@ -319,9 +321,9 @@ def _from_factorized(cls, values, original):
@classmethod
@Appender(
_interval_shared_docs["from_breaks"]
% dict(
klass="IntervalArray",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
Examples
--------
Expand All @@ -331,7 +333,7 @@ def _from_factorized(cls, values, original):
Length: 3, closed: right, dtype: interval[int64]
"""
),
)
}
)
def from_breaks(cls, breaks, closed="right", copy=False, dtype=None):
breaks = maybe_convert_platform_interval(breaks)
Expand Down Expand Up @@ -390,17 +392,17 @@ def from_breaks(cls, breaks, closed="right", copy=False, dtype=None):
@classmethod
@Appender(
_interval_shared_docs["from_arrays"]
% dict(
klass="IntervalArray",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
>>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3])
<IntervalArray>
[(0, 1], (1, 2], (2, 3]]
Length: 3, closed: right, dtype: interval[int64]
"""
),
)
}
)
def from_arrays(cls, left, right, closed="right", copy=False, dtype=None):
left = maybe_convert_platform_interval(left)
Expand Down Expand Up @@ -445,9 +447,9 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None):
@classmethod
@Appender(
_interval_shared_docs["from_tuples"]
% dict(
klass="IntervalArray",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
Examples
--------
Expand All @@ -457,7 +459,7 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None):
Length: 2, closed: right, dtype: interval[int64]
"""
),
)
}
)
def from_tuples(cls, data, closed="right", copy=False, dtype=None):
if len(data):
Expand Down Expand Up @@ -904,7 +906,7 @@ def take(self, indices, *, allow_fill=False, fill_value=None, axis=None, **kwarg
When `indices` contains negative values other than ``-1``
and `allow_fill` is True.
"""
nv.validate_take(tuple(), kwargs)
nv.validate_take((), kwargs)

fill_left = fill_right = fill_value
if allow_fill:
Expand Down Expand Up @@ -1144,9 +1146,9 @@ def mid(self):

@Appender(
_interval_shared_docs["overlaps"]
% dict(
klass="IntervalArray",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
>>> data = [(0, 1), (1, 3), (2, 4)]
>>> intervals = pd.arrays.IntervalArray.from_tuples(data)
Expand All @@ -1156,7 +1158,7 @@ def mid(self):
Length: 3, closed: right, dtype: interval[int64]
"""
),
)
}
)
def overlaps(self, other):
if isinstance(other, (IntervalArray, ABCIntervalIndex)):
Expand Down Expand Up @@ -1207,9 +1209,9 @@ def closed(self):

@Appender(
_interval_shared_docs["set_closed"]
% dict(
klass="IntervalArray",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
Examples
--------
Expand All @@ -1224,7 +1226,7 @@ def closed(self):
Length: 3, closed: both, dtype: interval[int64]
"""
),
)
}
)
def set_closed(self, closed):
if closed not in VALID_CLOSED:
Expand Down Expand Up @@ -1360,7 +1362,7 @@ def __arrow_array__(self, type=None):
"""

@Appender(
_interval_shared_docs["to_tuples"] % dict(return_type="ndarray", examples="")
_interval_shared_docs["to_tuples"] % {"return_type": "ndarray", "examples": ""}
)
def to_tuples(self, na_tuple=True):
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
Expand All @@ -1373,7 +1375,7 @@ def to_tuples(self, na_tuple=True):

@Appender(_extension_array_shared_docs["repeat"] % _shared_docs_kwargs)
def repeat(self, repeats, axis=None):
nv.validate_repeat(tuple(), dict(axis=axis))
nv.validate_repeat((), {"axis": axis})
left_repeat = self.left.repeat(repeats)
right_repeat = self.right.repeat(repeats)
return self._shallow_copy(left=left_repeat, right=right_repeat)
Expand Down Expand Up @@ -1412,9 +1414,9 @@ def repeat(self, repeats, axis=None):

@Appender(
_interval_shared_docs["contains"]
% dict(
klass="IntervalArray",
examples=textwrap.dedent(
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
>>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)])
>>> intervals
Expand All @@ -1423,7 +1425,7 @@ def repeat(self, repeats, axis=None):
Length: 3, closed: right, dtype: interval[int64]
"""
),
)
}
)
def contains(self, other):
if isinstance(other, Interval):
Expand Down
18 changes: 9 additions & 9 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ def _values_for_factorize(self) -> Tuple[np.ndarray, int]:
# Reductions

def any(self, *, axis=None, out=None, keepdims=False, skipna=True):
nv.validate_any((), dict(out=out, keepdims=keepdims))
nv.validate_any((), {"out": out, "keepdims": keepdims})
result = nanops.nanany(self._ndarray, axis=axis, skipna=skipna)
return self._wrap_reduction_result(axis, result)

def all(self, *, axis=None, out=None, keepdims=False, skipna=True):
nv.validate_all((), dict(out=out, keepdims=keepdims))
nv.validate_all((), {"out": out, "keepdims": keepdims})
result = nanops.nanall(self._ndarray, axis=axis, skipna=skipna)
return self._wrap_reduction_result(axis, result)

Expand Down Expand Up @@ -311,15 +311,15 @@ def prod(self, *, axis=None, skipna=True, min_count=0, **kwargs) -> Scalar:
return self._wrap_reduction_result(axis, result)

def mean(self, *, axis=None, dtype=None, out=None, keepdims=False, skipna=True):
nv.validate_mean((), dict(dtype=dtype, out=out, keepdims=keepdims))
nv.validate_mean((), {"dtype": dtype, "out": out, "keepdims": keepdims})
result = nanops.nanmean(self._ndarray, axis=axis, skipna=skipna)
return self._wrap_reduction_result(axis, result)

def median(
self, *, axis=None, out=None, overwrite_input=False, keepdims=False, skipna=True
):
nv.validate_median(
(), dict(out=out, overwrite_input=overwrite_input, keepdims=keepdims)
(), {"out": out, "overwrite_input": overwrite_input, "keepdims": keepdims}
)
result = nanops.nanmedian(self._ndarray, axis=axis, skipna=skipna)
return self._wrap_reduction_result(axis, result)
Expand All @@ -328,7 +328,7 @@ def std(
self, *, axis=None, dtype=None, out=None, ddof=1, keepdims=False, skipna=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)
return self._wrap_reduction_result(axis, result)
Expand All @@ -337,7 +337,7 @@ def var(
self, *, axis=None, dtype=None, out=None, ddof=1, keepdims=False, skipna=True
):
nv.validate_stat_ddof_func(
(), dict(dtype=dtype, out=out, keepdims=keepdims), fname="var"
(), {"dtype": dtype, "out": out, "keepdims": keepdims}, fname="var"
)
result = nanops.nanvar(self._ndarray, axis=axis, skipna=skipna, ddof=ddof)
return self._wrap_reduction_result(axis, result)
Expand All @@ -346,21 +346,21 @@ def sem(
self, *, axis=None, dtype=None, out=None, ddof=1, keepdims=False, skipna=True
):
nv.validate_stat_ddof_func(
(), dict(dtype=dtype, out=out, keepdims=keepdims), fname="sem"
(), {"dtype": dtype, "out": out, "keepdims": keepdims}, fname="sem"
)
result = nanops.nansem(self._ndarray, axis=axis, skipna=skipna, ddof=ddof)
return self._wrap_reduction_result(axis, result)

def kurt(self, *, axis=None, dtype=None, out=None, keepdims=False, skipna=True):
nv.validate_stat_ddof_func(
(), dict(dtype=dtype, out=out, keepdims=keepdims), fname="kurt"
(), {"dtype": dtype, "out": out, "keepdims": keepdims}, fname="kurt"
)
result = nanops.nankurt(self._ndarray, axis=axis, skipna=skipna)
return self._wrap_reduction_result(axis, result)

def skew(self, *, axis=None, dtype=None, out=None, keepdims=False, skipna=True):
nv.validate_stat_ddof_func(
(), dict(dtype=dtype, out=out, keepdims=keepdims), fname="skew"
(), {"dtype": dtype, "out": out, "keepdims": keepdims}, fname="skew"
)
result = nanops.nanskew(self._ndarray, axis=axis, skipna=skipna)
return self._wrap_reduction_result(axis, result)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numexpr as ne

_TEST_MODE = None
_TEST_RESULT: List[bool] = list()
_TEST_RESULT: List[bool] = []
USE_NUMEXPR = NUMEXPR_INSTALLED
_evaluate = None
_where = None
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
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PandasExtensionDtype(ExtensionDtype):
subdtype = None
str: str_type
num = 100
shape: Tuple[int, ...] = tuple()
shape: Tuple[int, ...] = ()
itemsize = 8
base = None
isbuiltin = 0
Expand Down
24 changes: 12 additions & 12 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,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 @@ -743,7 +743,7 @@ def astype(self, dtype, copy=True):
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
if kwargs:
nv.validate_take(tuple(), kwargs)
nv.validate_take((), kwargs)
indices = ensure_platform_int(indices)
allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices)

Expand Down Expand Up @@ -818,7 +818,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((), {"axis": axis})
return self._shallow_copy(self._values.repeat(repeats))

# --------------------------------------------------------------------
Expand Down Expand Up @@ -2156,7 +2156,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
Loading