forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pre-commit-config.yaml
388 lines (372 loc) · 13.5 KB
/
.pre-commit-config.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
minimum_pre_commit_version: 2.15.0
exclude: ^LICENSES/|\.(html|csv|svg)$
# reserve "manual" for relatively slow hooks which we still want to run in CI
default_stages: [
commit,
merge-commit,
push,
prepare-commit-msg,
commit-msg,
post-checkout,
post-commit,
post-merge,
post-rewrite
]
ci:
autofix_prs: false
autoupdate_schedule: monthly
# manual stage hooks
skip: [pylint, pyright, mypy]
repos:
- repo: https://github.com/hauntsaninja/black-pre-commit-mirror
# black compiled with mypyc
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
- id: ruff
# TODO: remove autofixe-only rules when they are checked by ruff
name: ruff-selected-autofixes
alias: ruff-selected-autofixes
args: [--select, "ANN001,ANN204", --fix-only, --exit-non-zero-on-fix]
- repo: https://github.com/jendrikseipp/vulture
rev: 'v2.7'
hooks:
- id: vulture
entry: python scripts/run_vulture.py
pass_filenames: true
require_serial: false
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
types_or: [python, rst, markdown, cython, c]
additional_dependencies: [tomli]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0
hooks:
- id: cython-lint
- id: double-quote-cython-strings
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: check-toml
- id: check-xml
- id: check-yaml
exclude: ^ci/meta.yaml$
- id: debug-statements
- id: end-of-file-fixer
exclude: \.txt$
- id: mixed-line-ending
args: [--fix=auto]
exclude: ^pandas/tests/io/parser/data/utf16_ex.txt$
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: [--remove]
- id: trailing-whitespace
- repo: https://github.com/cpplint/cpplint
rev: 1.6.1
hooks:
- id: cpplint
exclude: ^pandas/_libs/include/pandas/vendored/klib
args: [
--quiet,
'--extensions=c,h',
'--headers=h',
--recursive,
--linelength=88,
'--filter=-readability/casting,-runtime/int,-build/include_subdir,-readability/fn_size'
]
- repo: https://github.com/pylint-dev/pylint
rev: v3.0.0a6
hooks:
- id: pylint
stages: [manual]
args: [--load-plugins=pylint.extensions.redefined_loop_name]
- id: pylint
alias: redefined-outer-name
name: Redefining name from outer scope
files: ^pandas/
exclude: |
(?x)
^pandas/tests # keep excluded
|/_testing/ # keep excluded
|^pandas/util/_test_decorators\.py # keep excluded
|^pandas/_version\.py # keep excluded
|^pandas/conftest\.py # keep excluded
args: [--disable=all, --enable=redefined-outer-name]
stages: [manual]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: rst-backticks
- id: rst-directive-colons
types: [text] # overwrite types: [rst]
types_or: [python, rst]
- id: rst-inline-touching-normal
types: [text] # overwrite types: [rst]
types_or: [python, rst]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.7
hooks:
- id: sphinx-lint
- repo: local
hooks:
- id: pyright
# note: assumes python env is setup and activated
name: pyright
entry: pyright
language: node
pass_filenames: false
types: [python]
stages: [manual]
additional_dependencies: &pyright_dependencies
- pyright@1.1.318
- id: pyright
# note: assumes python env is setup and activated
name: pyright reportGeneralTypeIssues
entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json --level warning
language: node
pass_filenames: false
types: [python]
stages: [manual]
additional_dependencies: *pyright_dependencies
- id: mypy
# note: assumes python env is setup and activated
name: mypy
entry: mypy
language: system
pass_filenames: false
types: [python]
stages: [manual]
- id: mypy
# note: assumes python env is setup and activated
# note: requires pandas dev to be installed
name: mypy (stubtest)
entry: python
language: system
pass_filenames: false
types: [pyi]
args: [scripts/run_stubtest.py]
stages: [manual]
- id: inconsistent-namespace-usage
name: 'Check for inconsistent use of pandas namespace'
entry: python scripts/check_for_inconsistent_pandas_namespace.py
exclude: ^pandas/core/interchange/
language: python
types: [python]
- id: unwanted-patterns
name: Unwanted patterns
language: pygrep
entry: |
(?x)
# outdated annotation syntax
\#\ type:\ (?!ignore)
# foo._class__ instead of type(foo)
|\.__class__
# Numpy
|from\ numpy\ import\ random
|from\ numpy\.random\ import
# Incorrect code-block / IPython directives
|\.\.\ code-block\ ::
|\.\.\ ipython\ ::
# directive should not have a space before ::
|\.\.\ \w+\ ::
# Check for deprecated messages without sphinx directive
|(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)
# {foo!r} instead of {repr(foo)}
|!r}
# builtin filter function
|(?<!def)[\(\s]filter\(
types_or: [python, cython, rst]
exclude: ^doc/source/development/code_style\.rst # contains examples of patterns to avoid
- id: incorrect-backticks
name: Check for backticks incorrectly rendering because of missing spaces
language: pygrep
entry: '[a-zA-Z0-9]\`\`?[a-zA-Z0-9]'
types: [rst]
files: ^doc/source/
- id: seed-check-asv
name: Check for unnecessary random seeds in asv benchmarks
language: pygrep
entry: 'np\.random\.seed'
files: ^asv_bench/benchmarks
exclude: ^asv_bench/benchmarks/pandas_vb_common\.py
- id: unwanted-patterns-in-tests
name: Unwanted patterns in tests
language: pygrep
entry: |
(?x)
# pytest.xfail instead of pytest.mark.xfail
pytest\.xfail
# imports from pandas._testing instead of `import pandas._testing as tm`
|from\ pandas\._testing\ import
|from\ pandas\ import\ _testing\ as\ tm
# No direct imports from conftest
|conftest\ import
|import\ conftest
# pandas.testing instead of tm
|pd\.testing\.
# pd.api.types instead of from pandas.api.types import ...
|(pd|pandas)\.api\.types\.
# np.testing, np.array_equal
|(numpy|np)(\.testing|\.array_equal)
# unittest.mock (use pytest builtin monkeypatch fixture instead)
|(unittest(\.| import )mock|mock\.Mock\(\)|mock\.patch)
# pytest raises without context
|\s\ pytest.raises
# pytest.warns (use tm.assert_produces_warning instead)
|pytest\.warns
# os.remove
|os\.remove
# Unseeded numpy default_rng
|default_rng\(\)
files: ^pandas/tests/
types_or: [python, cython, rst]
- id: unwanted-patterns-in-cython
name: Unwanted patterns in Cython code
language: pygrep
entry: |
(?x)
# `<type>obj` as opposed to `<type> obj`
[a-zA-Z0-9*]>[ ]
types: [cython]
- id: pip-to-conda
name: Generate pip dependency from conda
language: python
entry: python scripts/generate_pip_deps_from_conda.py
files: ^(environment.yml|requirements-dev.txt)$
pass_filenames: false
additional_dependencies: [tomli, pyyaml]
- id: title-capitalization
name: Validate correct capitalization among titles in documentation
entry: python scripts/validate_rst_title_capitalization.py
language: python
types: [rst]
files: ^doc/source/(development|reference)/
- id: unwanted-patterns-bare-pytest-raises
name: Check for use of bare pytest raises
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises"
types: [python]
files: ^pandas/tests/
exclude: ^pandas/tests/extension/
- id: unwanted-patterns-private-function-across-module
name: Check for use of private functions across modules
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
types: [python]
exclude: ^(asv_bench|pandas/tests|doc)/
- id: unwanted-patterns-private-import-across-module
name: Check for import of private attributes across modules
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module"
types: [python]
exclude: |
(?x)
^(asv_bench|pandas/tests|doc)/
|scripts/validate_min_versions_in_sync\.py$
- id: unwanted-patterns-strings-with-misplaced-whitespace
name: Check for strings with misplaced spaces
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace"
types_or: [python, cython]
- id: unwanted-patterns-nodefault-used-not-only-for-typing
name: Check that `pandas._libs.lib.NoDefault` is used only for typing
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="nodefault_used_not_only_for_typing"
types: [python]
- id: use-pd_array-in-core
name: Import pandas.array as pd_array in core
language: python
entry: python scripts/use_pd_array_in_core.py
files: ^pandas/core/
exclude: ^pandas/core/api\.py$
types: [python]
- id: use-io-common-urlopen
name: Use pandas.io.common.urlopen instead of urllib.request.urlopen
language: python
entry: python scripts/use_io_common_urlopen.py
files: ^pandas/
exclude: ^pandas/tests/
types: [python]
- id: no-bool-in-core-generic
name: Use bool_t instead of bool in pandas/core/generic.py
entry: python scripts/no_bool_in_generic.py
language: python
files: ^pandas/core/generic\.py$
- id: no-return-exception
name: Use raise instead of return for exceptions
language: pygrep
entry: 'return [A-Za-z]+(Error|Exit|Interrupt|Exception|Iteration)'
files: ^pandas/
types: [python]
exclude: ^pandas/tests/
- id: pandas-errors-documented
name: Ensure pandas errors are documented in doc/source/reference/testing.rst
entry: python scripts/pandas_errors_documented.py
language: python
files: ^pandas/errors/__init__.py$
- id: pg8000-not-installed-CI
name: Check for pg8000 not installed on CI for test_pg8000_sqlalchemy_passthrough_error
language: pygrep
entry: 'pg8000'
files: ^ci/deps
types: [yaml]
- id: validate-min-versions-in-sync
name: Check minimum version of dependencies are aligned
entry: python -m scripts.validate_min_versions_in_sync
language: python
files: ^(ci/deps/actions-.*-minimum_versions\.yaml|pandas/compat/_optional\.py)$
additional_dependencies: [tomli, pyyaml]
pass_filenames: false
- id: validate-errors-locations
name: Validate errors locations
description: Validate errors are in appropriate locations.
entry: python scripts/validate_exception_location.py
language: python
files: ^pandas/
exclude: ^(pandas/_libs/|pandas/tests/|pandas/errors/__init__.py$|pandas/_version.py)
types: [python]
- id: future-annotations
name: import annotations from __future__
entry: 'from __future__ import annotations'
language: pygrep
args: [--negate]
files: ^pandas/
types: [python]
exclude: |
(?x)
/(__init__\.py)|(api\.py)|(_version\.py)|(testing\.py)|(conftest\.py)$
|/tests/
|/_testing/
- id: check-test-naming
name: check that test names start with 'test'
entry: python -m scripts.check_test_naming
types: [python]
files: ^pandas/tests
language: python
- id: sort-whatsnew-items
name: sort whatsnew entries alphabetically
entry: python -m scripts.sort_whatsnew_note
types: [rst]
language: python
files: ^doc/source/whatsnew/v
exclude: ^doc/source/whatsnew/v(0|1|2\.0\.0)