Skip to content

Commit cdec74a

Browse files
authored
Translate more banned import config to ruff (#57283)
* Translate more banned import config to ruff * Remove redundant rules
1 parent 373fb91 commit cdec74a

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

.pre-commit-config.yaml

+3-20
Original file line numberDiff line numberDiff line change
@@ -208,39 +208,22 @@ repos:
208208
language: pygrep
209209
entry: |
210210
(?x)
211-
# pytest.xfail instead of pytest.mark.xfail
212-
pytest\.xfail
213-
214211
# imports from pandas._testing instead of `import pandas._testing as tm`
215-
|from\ pandas\._testing\ import
212+
from\ pandas\._testing\ import
216213
|from\ pandas\ import\ _testing\ as\ tm
217214
218-
# No direct imports from conftest
219-
|conftest\ import
220-
|import\ conftest
221-
222215
# pandas.testing instead of tm
223216
|pd\.testing\.
224217
225218
# pd.api.types instead of from pandas.api.types import ...
226219
|(pd|pandas)\.api\.types\.
227220
228-
# np.testing, np.array_equal
229-
|(numpy|np)(\.testing|\.array_equal)
230-
231-
# unittest.mock (use pytest builtin monkeypatch fixture instead)
232-
|(unittest(\.| import )mock|mock\.Mock\(\)|mock\.patch)
221+
# np.array_equal
222+
|(numpy|np)\.array_equal
233223
234224
# pytest raises without context
235225
|\s\ pytest.raises
236226
237-
# TODO
238-
# pytest.warns (use tm.assert_produces_warning instead)
239-
# |pytest\.warns
240-
241-
# os.remove
242-
|os\.remove
243-
244227
# Unseeded numpy default_rng
245228
|default_rng\(\)
246229
files: ^pandas/tests/

doc/make.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def html(self):
233233
ret_code = self._sphinx_build("html")
234234
zip_fname = os.path.join(BUILD_PATH, "html", "pandas.zip")
235235
if os.path.exists(zip_fname):
236-
os.remove(zip_fname)
236+
os.remove(zip_fname) # noqa: TID251
237237

238238
if ret_code == 0:
239239
if self.single_doc_html is not None:
@@ -285,7 +285,7 @@ def zip_html(self) -> None:
285285
"""
286286
zip_fname = os.path.join(BUILD_PATH, "html", "pandas.zip")
287287
if os.path.exists(zip_fname):
288-
os.remove(zip_fname)
288+
os.remove(zip_fname) # noqa: TID251
289289
dirname = os.path.join(BUILD_PATH, "html")
290290
fnames = os.listdir(dirname)
291291
os.chdir(dirname)

pandas/tests/copy_view/test_chained_assignment_deprecation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_series_setitem(indexer):
1818

1919
# using custom check instead of tm.assert_produces_warning because that doesn't
2020
# fail if multiple warnings are raised
21-
with pytest.warns() as record:
21+
with pytest.warns() as record: # noqa: TID251
2222
df["a"][indexer] = 0
2323
assert len(record) == 1
2424
assert record[0].category == ChainedAssignmentError

pyproject.toml

+11
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ exclude = [
331331

332332
[tool.ruff.lint.flake8-tidy-imports.banned-api]
333333
"urllib.request.urlopen".msg = "Use pandas.io.common.urlopen instead of urllib.request.urlopen"
334+
# numpy.random is banned but np.random is not. Is this intentional?
335+
# "numpy.random".msg = "Do not use numpy.random"
336+
"pytest.warns".msg = "Use tm.assert_produces_warning instead of pytest.warns"
337+
"pytest.xfail".msg = "Use pytest.mark.xfail instead of pytest.xfail"
338+
"conftest".msg = "No direct imports from conftest"
339+
"numpy.testing".msg = "Do not use numpy.testing"
340+
# "numpy.array_equal".msg = "Do not use numpy.array_equal" # Used in pandas/core
341+
"unittest.mock".msg = "use pytest builtin monkeypatch fixture instead"
342+
"os.remove".msg = "Do not use os.remove"
343+
344+
334345

335346
[tool.ruff.per-file-ignores]
336347
# relative imports allowed for asv_bench

web/tests/test_pandas_web.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest.mock import (
1+
from unittest.mock import ( # noqa: TID251
22
mock_open,
33
patch,
44
)

0 commit comments

Comments
 (0)