Skip to content

Commit 1b5370a

Browse files
authored
STYLE ruff: enable PIE (#51434)
* Ran pre-commit and fixed all errors * Formatted using black * Update .pre-commit-config.yaml Removed the fix arguments. * Update stata.py * revert changes to doc/source/user_guide/style.ipynb * Update test_indexing.py * Update test_to_records.py and css.py Changed dtype_mappings and CSS_EXPANSIONS respectively. * Update css.py Ran black pre-commit hook.
1 parent 2cf879d commit 1b5370a

File tree

13 files changed

+21
-30
lines changed

13 files changed

+21
-30
lines changed

pandas/conftest.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,7 @@ def index_flat(request):
637637
key
638638
for key, value in indices_dict.items()
639639
if not (
640-
key.startswith("int")
641-
or key.startswith("uint")
642-
or key.startswith("float")
640+
key.startswith(("int", "uint", "float"))
643641
or key in ["range", "empty", "repeats", "bool-dtype"]
644642
)
645643
and not isinstance(value, MultiIndex)

pandas/core/dtypes/dtypes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ def freq(self):
897897
@classmethod
898898
def _parse_dtype_strict(cls, freq: str_type) -> BaseOffset:
899899
if isinstance(freq, str): # note: freq is already of type str!
900-
if freq.startswith("period[") or freq.startswith("Period["):
900+
if freq.startswith(("Period[", "period[")):
901901
m = cls._match.search(freq)
902902
if m is not None:
903903
freq = m.group("freq")
@@ -916,7 +916,7 @@ def construct_from_string(cls, string: str_type) -> PeriodDtype:
916916
"""
917917
if (
918918
isinstance(string, str)
919-
and (string.startswith("period[") or string.startswith("Period["))
919+
and (string.startswith(("period[", "Period[")))
920920
or isinstance(string, BaseOffset)
921921
):
922922
# do not parse string like U as period[U]
@@ -980,7 +980,7 @@ def is_dtype(cls, dtype: object) -> bool:
980980
if isinstance(dtype, str):
981981
# PeriodDtype can be instantiated from freq string like "U",
982982
# but doesn't regard freq str like "U" as dtype.
983-
if dtype.startswith("period[") or dtype.startswith("Period["):
983+
if dtype.startswith(("period[", "Period[")):
984984
try:
985985
return cls._parse_dtype_strict(dtype) is not None
986986
except ValueError:

pandas/core/series.py

-2
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,6 @@ def view(self, dtype: Dtype | None = None) -> Series:
836836

837837
# ----------------------------------------------------------------------
838838
# NDArray Compat
839-
_HANDLED_TYPES = (Index, ExtensionArray, np.ndarray)
840-
841839
def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:
842840
"""
843841
Return the values as a NumPy array.

pandas/io/formats/css.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,8 @@ class CSSResolver:
208208
f"border-{prop}": _side_expander(f"border-{{:s}}-{prop}")
209209
for prop in ["color", "style", "width"]
210210
},
211-
**{
212-
"margin": _side_expander("margin-{:s}"),
213-
"padding": _side_expander("padding-{:s}"),
214-
},
211+
"margin": _side_expander("margin-{:s}"),
212+
"padding": _side_expander("padding-{:s}"),
215213
}
216214

217215
def __call__(

pandas/io/json/_json.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,7 @@ def is_ok(col) -> bool:
14151415

14161416
col_lower = col.lower()
14171417
if (
1418-
col_lower.endswith("_at")
1419-
or col_lower.endswith("_time")
1418+
col_lower.endswith(("_at", "_time"))
14201419
or col_lower == "modified"
14211420
or col_lower == "date"
14221421
or col_lower == "datetime"

pandas/io/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5123,13 +5123,13 @@ def _dtype_to_kind(dtype_str: str) -> str:
51235123
"""
51245124
dtype_str = _ensure_decoded(dtype_str)
51255125

5126-
if dtype_str.startswith("string") or dtype_str.startswith("bytes"):
5126+
if dtype_str.startswith(("string", "bytes")):
51275127
kind = "string"
51285128
elif dtype_str.startswith("float"):
51295129
kind = "float"
51305130
elif dtype_str.startswith("complex"):
51315131
kind = "complex"
5132-
elif dtype_str.startswith("int") or dtype_str.startswith("uint"):
5132+
elif dtype_str.startswith(("int", "uint")):
51335133
kind = "integer"
51345134
elif dtype_str.startswith("datetime64"):
51355135
kind = "datetime64"

pandas/io/stata.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -865,23 +865,23 @@ class StataMissingValue:
865865
MISSING_VALUES[i + b] = "." + chr(96 + i)
866866

867867
float32_base: bytes = b"\x00\x00\x00\x7f"
868-
increment: int = struct.unpack("<i", b"\x00\x08\x00\x00")[0]
868+
increment_32: int = struct.unpack("<i", b"\x00\x08\x00\x00")[0]
869869
for i in range(27):
870870
key = struct.unpack("<f", float32_base)[0]
871871
MISSING_VALUES[key] = "."
872872
if i > 0:
873873
MISSING_VALUES[key] += chr(96 + i)
874-
int_value = struct.unpack("<i", struct.pack("<f", key))[0] + increment
874+
int_value = struct.unpack("<i", struct.pack("<f", key))[0] + increment_32
875875
float32_base = struct.pack("<i", int_value)
876876

877877
float64_base: bytes = b"\x00\x00\x00\x00\x00\x00\xe0\x7f"
878-
increment = struct.unpack("q", b"\x00\x00\x00\x00\x00\x01\x00\x00")[0]
878+
increment_64 = struct.unpack("q", b"\x00\x00\x00\x00\x00\x01\x00\x00")[0]
879879
for i in range(27):
880880
key = struct.unpack("<d", float64_base)[0]
881881
MISSING_VALUES[key] = "."
882882
if i > 0:
883883
MISSING_VALUES[key] += chr(96 + i)
884-
int_value = struct.unpack("q", struct.pack("<d", key))[0] + increment
884+
int_value = struct.unpack("q", struct.pack("<d", key))[0] + increment_64
885885
float64_base = struct.pack("q", int_value)
886886

887887
BASE_MISSING_VALUES: Final = {

pandas/tests/copy_view/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ def test_subset_chained_getitem(
583583
# with ArrayManager, it doesn't matter whether we have
584584
# single vs mixed block or numpy vs nullable dtypes
585585
subset_is_view = test_callspec.endswith(
586-
"column-iloc-slice"
587-
) or test_callspec.endswith("column-loc-slice")
586+
("column-iloc-slice", "column-loc-slice")
587+
)
588588

589589
# modify subset -> don't modify parent
590590
subset = method(df)

pandas/tests/frame/methods/test_to_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def keys(self):
489489
df = DataFrame({"A": [1, 2], "B": [0.2, 1.5], "C": ["a", "bc"]})
490490

491491
dtype_mappings = {
492-
"column_dtypes": DictLike(**{"A": np.int8, "B": np.float32}),
492+
"column_dtypes": DictLike(A=np.int8, B=np.float32),
493493
"index_dtypes": f"{tm.ENDIAN}U2",
494494
}
495495

pandas/tests/io/formats/style/test_style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def mi_styler(mi_df):
4646
def mi_styler_comp(mi_styler):
4747
# comprehensively add features to mi_styler
4848
mi_styler = mi_styler._copy(deepcopy=True)
49-
mi_styler.css = {**mi_styler.css, **{"row": "ROW", "col": "COL"}}
49+
mi_styler.css = {**mi_styler.css, "row": "ROW", "col": "COL"}
5050
mi_styler.uuid_len = 5
5151
mi_styler.uuid = "abcde"
5252
mi_styler.set_caption("capt")

pandas/tseries/frequencies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def _is_annual(rule: str) -> bool:
596596

597597
def _is_quarterly(rule: str) -> bool:
598598
rule = rule.upper()
599-
return rule == "Q" or rule.startswith("Q-") or rule.startswith("BQ")
599+
return rule == "Q" or rule.startswith(("Q-", "BQ"))
600600

601601

602602
def _is_monthly(rule: str) -> bool:

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ select = [
212212
"Q",
213213
# pylint
214214
"PLE", "PLR", "PLW",
215+
# misc lints
216+
"PIE",
215217
# tidy imports
216218
"TID",
217219
]

scripts/validate_exception_location.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ def __init__(self, path: str, exception_set: set[str]) -> None:
5151

5252
def visit_ClassDef(self, node) -> None:
5353
def is_an_exception_subclass(base_id: str) -> bool:
54-
return (
55-
base_id == "Exception"
56-
or base_id.endswith("Warning")
57-
or base_id.endswith("Error")
58-
)
54+
return base_id == "Exception" or base_id.endswith(("Warning", "Error"))
5955

6056
exception_classes = []
6157

0 commit comments

Comments
 (0)