Skip to content

Commit c7de7fb

Browse files
committed
use pandas-dev-flaker
1 parent 58721f7 commit c7de7fb

20 files changed

+35
-1250
lines changed

.pre-commit-config.yaml

+9-95
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ repos:
3636
rev: 3.9.0
3737
hooks:
3838
- id: flake8
39-
additional_dependencies: [flake8-comprehensions>=3.1.0, flake8-bugbear>=21.3.2]
39+
additional_dependencies:
40+
- flake8-comprehensions>=3.1.0
41+
- flake8-bugbear>=21.3.2
42+
- pandas-dev-flaker==0.1.2
4043
- id: flake8
4144
name: flake8 (cython)
4245
types: [cython]
@@ -69,7 +72,11 @@ repos:
6972
rev: v1.2.2
7073
hooks:
7174
- id: yesqa
72-
additional_dependencies: [flake8==3.9.0]
75+
additional_dependencies:
76+
- flake8==3.9.0
77+
- flake8-comprehensions>=3.1.0
78+
- flake8-bugbear>=21.3.2
79+
- pandas-dev-flaker==0.1.2
7380
- repo: local
7481
hooks:
7582
- id: flake8-rst
@@ -80,28 +87,6 @@ repos:
8087
types: [rst]
8188
args: [--filename=*.rst]
8289
additional_dependencies: [flake8-rst==0.7.0, flake8==3.7.9]
83-
- id: frame-or-series-union
84-
name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
85-
entry: Union\[.*(Series,.*DataFrame|DataFrame,.*Series).*\]
86-
language: pygrep
87-
types: [python]
88-
exclude: ^pandas/_typing\.py$
89-
- id: inconsistent-namespace-usage
90-
name: 'Check for inconsistent use of pandas namespace'
91-
entry: python scripts/check_for_inconsistent_pandas_namespace.py
92-
language: python
93-
types: [python]
94-
- id: no-os-remove
95-
name: Check code for instances of os.remove
96-
entry: os\.remove
97-
language: pygrep
98-
types: [python]
99-
files: ^pandas/tests/
100-
exclude: |
101-
(?x)^
102-
pandas/tests/io/excel/test_writers\.py
103-
|pandas/tests/io/pytables/common\.py
104-
|pandas/tests/io/pytables/test_store\.py$
10590
- id: unwanted-patterns
10691
name: Unwanted patterns
10792
language: pygrep
@@ -111,52 +96,10 @@ repos:
11196
\#\ type:\ (?!ignore)
11297
|\#\ type:\s?ignore(?!\[)
11398
114-
# foo._class__ instead of type(foo)
115-
|\.__class__
116-
117-
# np.bool/np.object instead of np.bool_/np.object_
118-
|np\.bool[^_8]
119-
|np\.object[^_8]
120-
121-
# imports from pandas.core.common instead of `import pandas.core.common as com`
122-
|from\ pandas\.core\.common\ import
123-
|from\ pandas\.core\ import\ common
124-
125-
# imports from collections.abc instead of `from collections import abc`
126-
|from\ collections\.abc\ import
127-
128-
# Numpy
129-
|from\ numpy\ import\ random
130-
|from\ numpy\.random\ import
131-
13299
# Incorrect code-block / IPython directives
133100
|\.\.\ code-block\ ::
134101
|\.\.\ ipython\ ::
135102
types_or: [python, cython, rst]
136-
exclude: ^doc/source/development/code_style\.rst # contains examples of patterns to avoid
137-
- id: unwanted-patterns-in-tests
138-
name: Unwanted patterns in tests
139-
language: pygrep
140-
entry: |
141-
(?x)
142-
# pytest.xfail instead of pytest.mark.xfail
143-
pytest\.xfail
144-
145-
# imports from pandas._testing instead of `import pandas._testing as tm`
146-
|from\ pandas\._testing\ import
147-
|from\ pandas\ import\ _testing\ as\ tm
148-
149-
# No direct imports from conftest
150-
|conftest\ import
151-
|import\ conftest
152-
153-
# pandas.testing instead of tm
154-
|pd\.testing\.
155-
156-
# pd.api.types instead of from pandas.api.types import ...
157-
|(pd|pandas)\.api\.types\.
158-
files: ^pandas/tests/
159-
types_or: [python, cython, rst]
160103
- id: pip-to-conda
161104
name: Generate pip dependency from conda
162105
description: This hook checks if the conda environment.yml and requirements-dev.txt are equal
@@ -178,35 +121,6 @@ repos:
178121
language: python
179122
types: [rst]
180123
files: ^doc/source/(development|reference)/
181-
- id: unwanted-patterns-bare-pytest-raises
182-
name: Check for use of bare pytest raises
183-
language: python
184-
entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises"
185-
types: [python]
186-
files: ^pandas/tests/
187-
exclude: ^pandas/tests/extension/
188-
- id: unwanted-patterns-private-function-across-module
189-
name: Check for use of private functions across modules
190-
language: python
191-
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
192-
types: [python]
193-
exclude: ^(asv_bench|pandas/tests|doc)/
194-
- id: unwanted-patterns-private-import-across-module
195-
name: Check for import of private attributes across modules
196-
language: python
197-
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module"
198-
types: [python]
199-
exclude: ^(asv_bench|pandas/tests|doc)/
200-
- id: unwanted-patterns-strings-to-concatenate
201-
name: Check for use of not concatenated strings
202-
language: python
203-
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate"
204-
types_or: [python, cython]
205-
- id: unwanted-patterns-strings-with-wrong-placed-whitespace
206-
name: Check for strings with wrong placed spaces
207-
language: python
208-
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace"
209-
types_or: [python, cython]
210124
- id: use-pd_array-in-core
211125
name: Import pandas.array as pd_array in core
212126
language: python

asv_bench/benchmarks/gil.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
except ImportError:
3232
from pandas import algos
3333
try:
34-
from pandas._testing import test_parallel
34+
from pandas._testing import test_parallel # noqa: PDF014
3535

3636
have_real_test_parallel = True
3737
except ImportError:

asv_bench/benchmarks/pandas_vb_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class BaseIO:
7070
def remove(self, f):
7171
"""Remove created files"""
7272
try:
73-
os.remove(f)
73+
os.remove(f) # noqa: PDF008
7474
except OSError:
7575
# On Windows, attempting to remove a file that is in use
7676
# causes an exception to be raised

ci/code_checks.sh

-30
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,6 @@ fi
6464
### PATTERNS ###
6565
if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
6666

67-
MSG='Check for use of exec' ; echo $MSG
68-
invgrep -R --include="*.py*" -E "[^a-zA-Z0-9_]exec\(" pandas
69-
RET=$(($RET + $?)) ; echo $MSG "DONE"
70-
71-
MSG='Check for pytest warns' ; echo $MSG
72-
invgrep -r -E --include '*.py' 'pytest\.warns' pandas/tests/
73-
RET=$(($RET + $?)) ; echo $MSG "DONE"
74-
75-
MSG='Check for pytest raises without context' ; echo $MSG
76-
invgrep -r -E --include '*.py' "[[:space:]] pytest.raises" pandas/tests/
77-
RET=$(($RET + $?)) ; echo $MSG "DONE"
78-
79-
MSG='Check for use of builtin filter function' ; echo $MSG
80-
invgrep -R --include="*.py" -P '(?<!def)[\(\s]filter\(' pandas
81-
RET=$(($RET + $?)) ; echo $MSG "DONE"
82-
83-
# Check for the following code in testing: `np.testing` and `np.array_equal`
84-
MSG='Check for invalid testing' ; echo $MSG
85-
invgrep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/
86-
RET=$(($RET + $?)) ; echo $MSG "DONE"
87-
8867
# Check for the following code in the extension array base tests: `tm.assert_frame_equal` and `tm.assert_series_equal`
8968
MSG='Check for invalid EA testing' ; echo $MSG
9069
invgrep -r -E --include '*.py' --exclude base.py 'tm.assert_(series|frame)_equal' pandas/tests/extension/base
@@ -98,15 +77,6 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
9877
invgrep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
9978
RET=$(($RET + $?)) ; echo $MSG "DONE"
10079

101-
# Check for the following code in testing: `unittest.mock`, `mock.Mock()` or `mock.patch`
102-
MSG='Check that unittest.mock is not used (pytest builtin monkeypatch fixture should be used instead)' ; echo $MSG
103-
invgrep -r -E --include '*.py' '(unittest(\.| import )mock|mock\.Mock\(\)|mock\.patch)' pandas/tests/
104-
RET=$(($RET + $?)) ; echo $MSG "DONE"
105-
106-
MSG='Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
107-
invgrep -R --include=*.{py,pyx} '!r}' pandas
108-
RET=$(($RET + $?)) ; echo $MSG "DONE"
109-
echo $MSG "DONE"
11080
fi
11181

11282
### CODE ###

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,4 @@ dependencies:
117117
- pip:
118118
- git+https://github.com/pydata/pydata-sphinx-theme.git@master
119119
- numpydoc < 1.2 # 2021-02-09 1.2dev breaking CI
120+
- pandas-dev-flaker==0.1.2

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def external_error_raised(expected_exception: type[Exception]) -> ContextManager
915915
"""
916916
import pytest
917917

918-
return pytest.raises(expected_exception, match=None)
918+
return pytest.raises(expected_exception, match=None) # noqa: PDF010
919919

920920

921921
cython_table = pd.core.common._cython_table.items()

pandas/core/window/ewm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from pandas.core.dtypes.common import is_datetime64_ns_dtype
2222
from pandas.core.dtypes.missing import isna
2323

24-
import pandas.core.common as common
24+
import pandas.core.common as com
2525
from pandas.core.util.numba_ import maybe_use_numba
2626
from pandas.core.window.common import zsqrt
2727
from pandas.core.window.doc import (
@@ -51,7 +51,7 @@ def get_center_of_mass(
5151
halflife: float | None,
5252
alpha: float | None,
5353
) -> float:
54-
valid_count = common.count_not_none(comass, span, halflife, alpha)
54+
valid_count = com.count_not_none(comass, span, halflife, alpha)
5555
if valid_count > 1:
5656
raise ValueError("comass, span, halflife, and alpha are mutually exclusive")
5757

@@ -279,7 +279,7 @@ def __init__(
279279
self._deltas = np.diff(_times) / _halflife
280280
# Halflife is no longer applicable when calculating COM
281281
# But allow COM to still be calculated if the user passes other decay args
282-
if common.count_not_none(self.com, self.span, self.alpha) > 0:
282+
if com.count_not_none(self.com, self.span, self.alpha) > 0:
283283
self._com = get_center_of_mass(self.com, self.span, None, self.alpha)
284284
else:
285285
self._com = 1.0

pandas/core/window/rolling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
DataError,
5757
SelectionMixin,
5858
)
59-
import pandas.core.common as common
59+
import pandas.core.common as com
6060
from pandas.core.indexes.api import (
6161
Index,
6262
MultiIndex,
@@ -643,7 +643,7 @@ def _apply_pairwise(
643643
)
644644

645645
gb_pairs = (
646-
common.maybe_make_list(pair) for pair in self._grouper.indices.keys()
646+
com.maybe_make_list(pair) for pair in self._grouper.indices.keys()
647647
)
648648
groupby_codes = []
649649
groupby_levels = []

pandas/tests/api/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class TestTesting(Base):
275275
]
276276

277277
def test_testing(self):
278-
from pandas import testing
278+
from pandas import testing # noqa: PDF015
279279

280280
self.check(testing, self.funcs)
281281

pandas/tests/indexes/object/test_astype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pandas import Index
2-
import pandas.testing as tm
2+
import pandas._testing as tm
33

44

55
def test_astype_str_from_bytes():

pandas/tests/io/pytables/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def safe_remove(path):
1717
if path is not None:
1818
try:
19-
os.remove(path)
19+
os.remove(path) # noqa: PDF008
2020
except OSError:
2121
pass
2222

pandas/tests/io/pytables/test_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs):
911911
os.close(fd)
912912
except (OSError, ValueError):
913913
pass
914-
os.remove(new_f)
914+
os.remove(new_f) # noqa: PDF008
915915

916916
# new table
917917
df = tm.makeDataFrame()

pandas/tests/tools/test_to_numeric.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ def test_type_check(errors):
232232
# see gh-11776
233233
df = DataFrame({"a": [1, -3.14, 7], "b": ["4", "5", "6"]})
234234
kwargs = {"errors": errors} if errors is not None else {}
235-
error_ctx = pytest.raises(TypeError, match="1-d array")
236-
237-
with error_ctx:
235+
with pytest.raises(TypeError, match="1-d array"):
238236
to_numeric(df, **kwargs)
239237

240238

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ tabulate>=0.8.3
8080
natsort
8181
git+https://github.com/pydata/pydata-sphinx-theme.git@master
8282
numpydoc < 1.2
83+
pandas-dev-flaker==0.1.2

0 commit comments

Comments
 (0)