-
-
Notifications
You must be signed in to change notification settings - Fork 150
refactor(ruff): switch from select
to ignore
#1412
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
f99f004
c664a0d
d120bea
1b34b99
85ab0f9
6847e86
06f1136
3e7bb89
faa516e
2e81ce6
5cb4685
83518db
b6394f9
ace7a24
f251900
0a322ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,16 +176,48 @@ fix = true | |
|
||
|
||
[tool.ruff.lint] | ||
extend-select = ["B007", "B018", "PYI", "UP", "RUF100", "RUF059"] | ||
extend-select = ["ALL"] | ||
ignore = [ | ||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long/ | ||
"E731", # https://docs.astral.sh/ruff/rules/lambda-assignment/ | ||
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ | ||
# The following rules are ignored permanently for good reasons | ||
"COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com | ||
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d | ||
"E501", # handled by black https://docs.astral.sh/ruff/rules/line-too-long/ | ||
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em | ||
"FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt | ||
"I", # handled by isort | ||
] | ||
|
||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"_*.pyi" = ["PYI001"] | ||
"*.pyi" = [ | ||
# The following rules are ignored permanently for good reasons | ||
"A001", # https://docs.astral.sh/ruff/rules/builtin-variable-shadowing/ | ||
|
||
"A002", # https://docs.astral.sh/ruff/rules/builtin-argument-shadowing/ | ||
"A004", # https://docs.astral.sh/ruff/rules/builtin-import-shadowing/ | ||
|
||
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n | ||
"PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/ | ||
|
||
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ | ||
|
||
"TD002", # https://docs.astral.sh/ruff/rules/missing-todo-author/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO is in one file, so can we make this a single file ignore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
# The following rules are ignored temporarily. Either fix them or move to the permanent list above. | ||
"ERA", "S", "ANN", "FIX002", "TD003", "TD004", "PLR0402", "PLC0105" | ||
|
||
] | ||
"scripts/*" = [ | ||
# The following rules are ignored permanently for good reasons | ||
"S603", # https://docs.astral.sh/ruff/rules/subprocess-without-shell-equals-true/ | ||
# The following rules are ignored temporarily. Either fix them or move to the permanent list above. | ||
"TRY", "PT", "BLE" | ||
] | ||
"tests/*" = [ | ||
# The following rules are ignored permanently for good reasons | ||
"E731", # https://docs.astral.sh/ruff/rules/lambda-assignment/ | ||
"PD", # Pandas is here | ||
"PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ | ||
"S101", # https://docs.astral.sh/ruff/rules/assert/ | ||
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ | ||
|
||
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ | ||
|
||
# The following rules are ignored temporarily. Either fix them or move to the permanent list above. | ||
"ANN", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901", "FIX", "TD", "A001", "PYI042", "ANN201" | ||
|
||
] | ||
|
||
|
||
[tool.mypy] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,8 +87,7 @@ def check( | |
and get_origin(shape_type) is tuple | ||
and (tuple_args := get_args(shape_type)) | ||
and ... not in tuple_args # fixed-length tuple | ||
and (arr_ndim := getattr(actual, "ndim")) | ||
!= (expected_ndim := len(tuple_args)) | ||
and (arr_ndim := actual.ndim) != (expected_ndim := len(tuple_args)) # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] | ||
|
||
): | ||
raise RuntimeError( | ||
f"Array has wrong dimension {arr_ndim}, expected {expected_ndim}" | ||
|
@@ -100,7 +99,7 @@ def check( | |
and (dtype_args := get_args(dtype_type)) | ||
and isinstance((expected_dtype := dtype_args[0]), type) | ||
and issubclass(expected_dtype, np.generic) | ||
and (arr_dtype := getattr(actual, "dtype")) != expected_dtype | ||
and (arr_dtype := actual.dtype) != expected_dtype # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] | ||
|
||
): | ||
raise RuntimeError( | ||
f"Array has wrong dtype {arr_dtype}, expected {expected_dtype.__name__}" | ||
|
@@ -208,8 +207,6 @@ def pytest_warns_bounded( | |
current = Version(version_str) | ||
if lb < current < ub: | ||
return pytest.warns(warning, match=match) | ||
else: | ||
if upper_exception is None: | ||
return nullcontext() | ||
else: | ||
return suppress(upper_exception) | ||
if upper_exception is None: | ||
return nullcontext() | ||
return suppress(upper_exception) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,21 +150,18 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs: Any): | |
def reconstruct(x): | ||
if isinstance(x, (decimal.Decimal, numbers.Number)): | ||
return x | ||
else: | ||
return DecimalArray._from_sequence(x) | ||
return DecimalArray._from_sequence(x) | ||
|
||
if ufunc.nout > 1: | ||
return tuple(reconstruct(x) for x in result) | ||
else: | ||
return reconstruct(result) | ||
return reconstruct(result) | ||
|
||
def __getitem__(self, item): | ||
if isinstance(item, numbers.Integral): | ||
return self._data[item] | ||
else: | ||
# array, slice. | ||
item = check_array_indexer(self, item) | ||
return type(self)(self._data[item]) | ||
# array, slice. | ||
item = check_array_indexer(self, item) | ||
return type(self)(self._data[item]) | ||
|
||
def take( | ||
self, indexer: TakeIndexer, *, allow_fill: bool = False, fill_value=None | ||
|
@@ -208,10 +205,9 @@ def __len__(self) -> int: | |
def __contains__(self, item) -> bool | np.bool_: | ||
if not isinstance(item, decimal.Decimal): | ||
return False | ||
elif item.is_nan(): | ||
if item.is_nan(): | ||
return self.isna().any() | ||
else: | ||
return super().__contains__(item) | ||
return super().__contains__(item) | ||
|
||
@property | ||
def nbytes(self) -> int: | ||
|
@@ -270,7 +266,7 @@ def convert_values(param): | |
|
||
# If the operator is not defined for the underlying objects, | ||
# a TypeError should be raised | ||
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)] | ||
res = [op(a, b) for (a, b) in zip(lvalues, rvalues, strict=False)] | ||
|
||
|
||
return np.asarray(res, dtype=bool) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,9 @@ def test_multiindex_constructors() -> None: | |
pd.MultiIndex, | ||
) | ||
check( | ||
assert_type(pd.MultiIndex.from_tuples(zip([1, 2], [3, 4])), pd.MultiIndex), | ||
assert_type( | ||
pd.MultiIndex.from_tuples(zip([1, 2], [3, 4], strict=False)), pd.MultiIndex | ||
|
||
), | ||
pd.MultiIndex, | ||
) | ||
check( | ||
|
@@ -152,10 +154,10 @@ def test_column_contains() -> None: | |
# https://github.com/microsoft/python-type-stubs/issues/199 | ||
df = pd.DataFrame({"A": [1, 2], "B": ["c", "d"], "E": [3, 4]}) | ||
|
||
collist = [column for column in df.columns] | ||
collist = list(df.columns) | ||
check(assert_type(collist, list[str]), list, str) | ||
|
||
collist2 = [column for column in df.columns[df.columns.str.contains("A|B")]] | ||
collist2 = list(df.columns[df.columns.str.contains("A|B")]) | ||
check(assert_type(collist2, list[str]), list, str) | ||
|
||
length = len(df.columns[df.columns.str.contains("A|B")]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1910,7 +1910,7 @@ def test_resample() -> None: | |
# GH 181 | ||
N = 10 | ||
index = pd.date_range("1/1/2000", periods=N, freq="min") | ||
x = [x for x in range(N)] | ||
x = list(range(N)) | ||
s = pd.Series(x, index=index, dtype=float) | ||
check(assert_type(s.resample("2min").std(), "pd.Series[float]"), pd.Series, float) | ||
check(assert_type(s.resample("2min").var(), "pd.Series[float]"), pd.Series, float) | ||
|
@@ -2141,7 +2141,7 @@ def func() -> MySeries[float]: | |
def test_change_to_dict_return_type() -> None: | ||
id = [1, 2, 3] | ||
value = ["a", "b", "c"] | ||
df = pd.DataFrame(zip(id, value), columns=["id", "value"]) | ||
df = pd.DataFrame(zip(id, value, strict=False), columns=["id", "value"]) | ||
|
||
fd = df.set_index("id")["value"].to_dict() | ||
check(assert_type(fd, dict[Any, Any]), dict) | ||
|
||
|
@@ -2976,7 +2976,7 @@ def test_astype_other() -> None: | |
|
||
def test_all_astype_args_tested() -> None: | ||
"""Check that all relevant numpy type aliases are tested.""" | ||
NUMPY_ALIASES: set[str] = {k for k in np.sctypeDict} | ||
NUMPY_ALIASES: set[str] = set(np.sctypeDict) | ||
EXCLUDED_ALIASES = { | ||
"datetime64", | ||
"m", | ||
|
@@ -3631,7 +3631,7 @@ def test_series_unique_timedelta() -> None: | |
def test_slice_timestamp() -> None: | ||
dti = pd.date_range("1/1/2025", "2/28/2025") | ||
|
||
s = pd.Series([i for i in range(len(dti))], index=dti) | ||
s = pd.Series(list(range(len(dti))), index=dti) | ||
|
||
# For `s1`, see discussion in GH 397. Needs mypy fix. | ||
# s1 = s.loc["2025-01-15":"2025-01-20"] | ||
|
@@ -3708,7 +3708,7 @@ def test_series_bool_fails() -> None: | |
if s == "foo": # pyright: ignore[reportGeneralTypeIssues] | ||
# Next line is unreachable. | ||
_a = s[0] | ||
assert False | ||
raise AssertionError | ||
except ValueError: | ||
pass | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious as to why we can't include this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They enforce
instead of
I find them annoying, especially that we are raising only for tests and CI here in
pandas-stubs
.