diff --git a/pandas/conftest.py b/pandas/conftest.py index ea69db60fd2ba..aab6de1724677 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -637,9 +637,7 @@ def index_flat(request): key for key, value in indices_dict.items() if not ( - key.startswith("int") - or key.startswith("uint") - or key.startswith("float") + key.startswith(("int", "uint", "float")) or key in ["range", "empty", "repeats", "bool-dtype"] ) and not isinstance(value, MultiIndex) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 123e20d6258bf..2909b24840831 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -897,7 +897,7 @@ def freq(self): @classmethod def _parse_dtype_strict(cls, freq: str_type) -> BaseOffset: if isinstance(freq, str): # note: freq is already of type str! - if freq.startswith("period[") or freq.startswith("Period["): + if freq.startswith(("Period[", "period[")): m = cls._match.search(freq) if m is not None: freq = m.group("freq") @@ -916,7 +916,7 @@ def construct_from_string(cls, string: str_type) -> PeriodDtype: """ if ( isinstance(string, str) - and (string.startswith("period[") or string.startswith("Period[")) + and (string.startswith(("period[", "Period["))) or isinstance(string, BaseOffset) ): # do not parse string like U as period[U] @@ -980,7 +980,7 @@ def is_dtype(cls, dtype: object) -> bool: if isinstance(dtype, str): # PeriodDtype can be instantiated from freq string like "U", # but doesn't regard freq str like "U" as dtype. - if dtype.startswith("period[") or dtype.startswith("Period["): + if dtype.startswith(("period[", "Period[")): try: return cls._parse_dtype_strict(dtype) is not None except ValueError: diff --git a/pandas/core/series.py b/pandas/core/series.py index 1c5a4431b03f2..279af6737b333 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -836,8 +836,6 @@ def view(self, dtype: Dtype | None = None) -> Series: # ---------------------------------------------------------------------- # NDArray Compat - _HANDLED_TYPES = (Index, ExtensionArray, np.ndarray) - def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray: """ Return the values as a NumPy array. diff --git a/pandas/io/formats/css.py b/pandas/io/formats/css.py index f2f808a6e2081..c3a87e04c1158 100644 --- a/pandas/io/formats/css.py +++ b/pandas/io/formats/css.py @@ -208,10 +208,8 @@ class CSSResolver: f"border-{prop}": _side_expander(f"border-{{:s}}-{prop}") for prop in ["color", "style", "width"] }, - **{ - "margin": _side_expander("margin-{:s}"), - "padding": _side_expander("padding-{:s}"), - }, + "margin": _side_expander("margin-{:s}"), + "padding": _side_expander("padding-{:s}"), } def __call__( diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index bdc070d04bd69..335d510666a1f 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -1415,8 +1415,7 @@ def is_ok(col) -> bool: col_lower = col.lower() if ( - col_lower.endswith("_at") - or col_lower.endswith("_time") + col_lower.endswith(("_at", "_time")) or col_lower == "modified" or col_lower == "date" or col_lower == "datetime" diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 7461bad99462c..a813a0e285027 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -5123,13 +5123,13 @@ def _dtype_to_kind(dtype_str: str) -> str: """ dtype_str = _ensure_decoded(dtype_str) - if dtype_str.startswith("string") or dtype_str.startswith("bytes"): + if dtype_str.startswith(("string", "bytes")): kind = "string" elif dtype_str.startswith("float"): kind = "float" elif dtype_str.startswith("complex"): kind = "complex" - elif dtype_str.startswith("int") or dtype_str.startswith("uint"): + elif dtype_str.startswith(("int", "uint")): kind = "integer" elif dtype_str.startswith("datetime64"): kind = "datetime64" diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 155f989eb0634..3738a133cec0a 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -865,23 +865,23 @@ class StataMissingValue: MISSING_VALUES[i + b] = "." + chr(96 + i) float32_base: bytes = b"\x00\x00\x00\x7f" - increment: int = struct.unpack(" 0: MISSING_VALUES[key] += chr(96 + i) - int_value = struct.unpack(" 0: MISSING_VALUES[key] += chr(96 + i) - int_value = struct.unpack("q", struct.pack(" don't modify parent subset = method(df) diff --git a/pandas/tests/frame/methods/test_to_records.py b/pandas/tests/frame/methods/test_to_records.py index 393d304024bb6..f2eea452764a6 100644 --- a/pandas/tests/frame/methods/test_to_records.py +++ b/pandas/tests/frame/methods/test_to_records.py @@ -489,7 +489,7 @@ def keys(self): df = DataFrame({"A": [1, 2], "B": [0.2, 1.5], "C": ["a", "bc"]}) dtype_mappings = { - "column_dtypes": DictLike(**{"A": np.int8, "B": np.float32}), + "column_dtypes": DictLike(A=np.int8, B=np.float32), "index_dtypes": f"{tm.ENDIAN}U2", } diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 46fb614d96633..0387f317c5c0d 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -46,7 +46,7 @@ def mi_styler(mi_df): def mi_styler_comp(mi_styler): # comprehensively add features to mi_styler mi_styler = mi_styler._copy(deepcopy=True) - mi_styler.css = {**mi_styler.css, **{"row": "ROW", "col": "COL"}} + mi_styler.css = {**mi_styler.css, "row": "ROW", "col": "COL"} mi_styler.uuid_len = 5 mi_styler.uuid = "abcde" mi_styler.set_caption("capt") diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 34e0c111360fd..e1af8c0b48c2f 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -596,7 +596,7 @@ def _is_annual(rule: str) -> bool: def _is_quarterly(rule: str) -> bool: rule = rule.upper() - return rule == "Q" or rule.startswith("Q-") or rule.startswith("BQ") + return rule == "Q" or rule.startswith(("Q-", "BQ")) def _is_monthly(rule: str) -> bool: diff --git a/pyproject.toml b/pyproject.toml index 9d4166b033128..0de87ce9c0385 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -212,6 +212,8 @@ select = [ "Q", # pylint "PLE", "PLR", "PLW", + # misc lints + "PIE", # tidy imports "TID", ] diff --git a/scripts/validate_exception_location.py b/scripts/validate_exception_location.py index ebbe6c95a3ec9..7af5e749b4b96 100644 --- a/scripts/validate_exception_location.py +++ b/scripts/validate_exception_location.py @@ -51,11 +51,7 @@ def __init__(self, path: str, exception_set: set[str]) -> None: def visit_ClassDef(self, node) -> None: def is_an_exception_subclass(base_id: str) -> bool: - return ( - base_id == "Exception" - or base_id.endswith("Warning") - or base_id.endswith("Error") - ) + return base_id == "Exception" or base_id.endswith(("Warning", "Error")) exception_classes = []