Skip to content

Commit 3a0db10

Browse files
authored
Revert "STYLE use pandas-dev-flaker (#40906) (#50519)
* Revert "STYLE use pandas-dev-flaker (#40906)" This reverts commit 1f27ed0. * fixups * fixup? * make _compressors public * use typing.Callable * reduce diff * further reduce * one more * fixup regex * fixup regex * add xfail to request * remove else after xfail mark * make copy_on_write public Co-authored-by: MarcoGorelli <>
1 parent f816fb9 commit 3a0db10

37 files changed

+1302
-100
lines changed

.pre-commit-config.yaml

+123-3
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@ repos:
7070
rev: 6.0.0
7171
hooks:
7272
- id: flake8
73-
# Need to patch os.remove rule in pandas-dev-flaker
74-
exclude: ^ci/fix_wheels.py
7573
additional_dependencies: &flake8_dependencies
7674
- flake8==6.0.0
7775
- flake8-bugbear==22.7.1
78-
- pandas-dev-flaker==0.5.0
7976
- repo: https://github.com/pycqa/pylint
8077
rev: v2.15.9
8178
hooks:
@@ -183,6 +180,21 @@ repos:
183180
types: [rst]
184181
args: [--filename=*.rst]
185182
additional_dependencies: [flake8-rst==0.7.0, flake8==3.7.9]
183+
- id: inconsistent-namespace-usage
184+
name: 'Check for inconsistent use of pandas namespace'
185+
entry: python scripts/check_for_inconsistent_pandas_namespace.py
186+
exclude: ^pandas/core/interchange/
187+
language: python
188+
types: [python]
189+
- id: no-os-remove
190+
name: Check code for instances of os.remove
191+
entry: os\.remove
192+
language: pygrep
193+
types: [python]
194+
files: ^pandas/tests/
195+
exclude: |
196+
(?x)^
197+
pandas/tests/io/pytables/test_store\.py$
186198
- id: unwanted-patterns
187199
name: Unwanted patterns
188200
language: pygrep
@@ -192,6 +204,20 @@ repos:
192204
\#\ type:\ (?!ignore)
193205
|\#\ type:\s?ignore(?!\[)
194206
207+
# foo._class__ instead of type(foo)
208+
|\.__class__
209+
210+
# np.bool/np.object instead of np.bool_/np.object_
211+
|np\.bool[^_8`]
212+
|np\.object[^_8`]
213+
214+
# imports from collections.abc instead of `from collections import abc`
215+
|from\ collections\.abc\ import
216+
217+
# Numpy
218+
|from\ numpy\ import\ random
219+
|from\ numpy\.random\ import
220+
195221
# Incorrect code-block / IPython directives
196222
|\.\.\ code-block\ ::
197223
|\.\.\ ipython\ ::
@@ -200,7 +226,17 @@ repos:
200226
201227
# Check for deprecated messages without sphinx directive
202228
|(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)
229+
230+
# {foo!r} instead of {repr(foo)}
231+
|!r}
232+
233+
# builtin filter function
234+
|(?<!def)[\(\s]filter\(
235+
236+
# exec
237+
|[^a-zA-Z0-9_]exec\(
203238
types_or: [python, cython, rst]
239+
exclude: ^doc/source/development/code_style\.rst # contains examples of patterns to avoid
204240
- id: cython-casting
205241
name: Check Cython casting is `<type>obj`, not `<type> obj`
206242
language: pygrep
@@ -231,6 +267,58 @@ repos:
231267
files: ^pandas/tests/extension/base
232268
types: [python]
233269
exclude: ^pandas/tests/extension/base/base\.py
270+
- id: unwanted-patterns-in-tests
271+
name: Unwanted patterns in tests
272+
language: pygrep
273+
entry: |
274+
(?x)
275+
# pytest.xfail instead of pytest.mark.xfail
276+
pytest\.xfail
277+
278+
# imports from pandas._testing instead of `import pandas._testing as tm`
279+
|from\ pandas\._testing\ import
280+
|from\ pandas\ import\ _testing\ as\ tm
281+
282+
# No direct imports from conftest
283+
|conftest\ import
284+
|import\ conftest
285+
286+
# pandas.testing instead of tm
287+
|pd\.testing\.
288+
289+
# pd.api.types instead of from pandas.api.types import ...
290+
|(pd|pandas)\.api\.types\.
291+
292+
# np.testing, np.array_equal
293+
|(numpy|np)(\.testing|\.array_equal)
294+
295+
# unittest.mock (use pytest builtin monkeypatch fixture instead)
296+
|(unittest(\.| import )mock|mock\.Mock\(\)|mock\.patch)
297+
298+
# pytest raises without context
299+
|\s\ pytest.raises
300+
301+
# pytest.warns (use tm.assert_produces_warning instead)
302+
|pytest\.warns
303+
files: ^pandas/tests/
304+
types_or: [python, cython, rst]
305+
- id: unwanted-patterns-in-ea-tests
306+
name: Unwanted patterns in EA tests
307+
language: pygrep
308+
entry: |
309+
(?x)
310+
tm.assert_(series|frame)_equal
311+
files: ^pandas/tests/extension/base/
312+
exclude: ^pandas/tests/extension/base/base\.py$
313+
types_or: [python, cython, rst]
314+
- id: unwanted-patterns-in-cython
315+
name: Unwanted patterns in Cython code
316+
language: pygrep
317+
entry: |
318+
(?x)
319+
# `<type>obj` as opposed to `<type> obj`
320+
[a-zA-Z0-9*]>[ ]
321+
types: [cython]
234322
- id: pip-to-conda
235323
name: Generate pip dependency from conda
236324
language: python
@@ -251,6 +339,38 @@ repos:
251339
language: python
252340
types: [rst]
253341
files: ^doc/source/(development|reference)/
342+
- id: unwanted-patterns-bare-pytest-raises
343+
name: Check for use of bare pytest raises
344+
language: python
345+
entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises"
346+
types: [python]
347+
files: ^pandas/tests/
348+
exclude: ^pandas/tests/extension/
349+
- id: unwanted-patterns-private-function-across-module
350+
name: Check for use of private functions across modules
351+
language: python
352+
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
353+
types: [python]
354+
exclude: ^(asv_bench|pandas/tests|doc)/
355+
- id: unwanted-patterns-private-import-across-module
356+
name: Check for import of private attributes across modules
357+
language: python
358+
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module"
359+
types: [python]
360+
exclude: |
361+
(?x)
362+
^(asv_bench|pandas/tests|doc)/
363+
|scripts/validate_min_versions_in_sync\.py$
364+
- id: unwanted-patterns-strings-to-concatenate
365+
name: Check for use of not concatenated strings
366+
language: python
367+
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate"
368+
types_or: [python, cython]
369+
- id: unwanted-patterns-strings-with-misplaced-whitespace
370+
name: Check for strings with misplaced spaces
371+
language: python
372+
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace"
373+
types_or: [python, cython]
254374
- id: use-pd_array-in-core
255375
name: Import pandas.array as pd_array in core
256376
language: python

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) # noqa: PDF008
73+
os.remove(f)
7474
except OSError:
7575
# On Windows, attempting to remove a file that is in use
7676
# causes an exception to be raised

doc/scripts/eval_performance.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from pandas import DataFrame
77

88
setup_common = """from pandas import DataFrame
9-
from numpy.random import randn
10-
df = DataFrame(randn(%d, 3), columns=list('abc'))
9+
df = DataFrame(np.random.randn(%d, 3), columns=list('abc'))
1110
%s"""
1211

1312
setup_with = "s = 'a + b * (c ** 2 + b ** 2 - a) / (a * c) ** 3'"

doc/source/development/contributing_codebase.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Pre-commit
4343
----------
4444

4545
Additionally, :ref:`Continuous Integration <contributing.ci>` will run code formatting checks
46-
like ``black``, ``flake8`` (including a `pandas-dev-flaker <https://github.com/pandas-dev/pandas-dev-flaker>`_ plugin),
46+
like ``black``, ``flake8``,
4747
``isort``, and ``cpplint`` and more using `pre-commit hooks <https://pre-commit.com/>`_
4848
Any warnings from these checks will cause the :ref:`Continuous Integration <contributing.ci>` to fail; therefore,
4949
it is helpful to run the check yourself before submitting code. This

doc/source/whatsnew/v1.4.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Null-values are no longer coerced to NaN-value in value_counts and mode
320320
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
321321

322322
:meth:`Series.value_counts` and :meth:`Series.mode` no longer coerce ``None``,
323-
``NaT`` and other null-values to a NaN-value for ``np.object``-dtype. This
323+
``NaT`` and other null-values to a NaN-value for ``np.object_``-dtype. This
324324
behavior is now consistent with ``unique``, ``isin`` and others
325325
(:issue:`42688`).
326326

environment.yml

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ dependencies:
9090
- gitdb
9191
- natsort # DataFrame.sort_values doctest
9292
- numpydoc
93-
- pandas-dev-flaker=0.5.0
9493
- pydata-sphinx-theme<0.11
9594
- pytest-cython # doctest
9695
- sphinx

pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
)
136136

137137
from pandas import api, arrays, errors, io, plotting, tseries
138-
from pandas import testing # noqa:PDF015
138+
from pandas import testing
139139
from pandas.util._print_versions import show_versions
140140

141141
from pandas.io.api import (

pandas/_libs/lib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
14821482
return val
14831483

14841484
if values.descr.type_num != NPY_OBJECT:
1485-
# i.e. values.dtype != np.object
1485+
# i.e. values.dtype != np.object_
14861486
# This should not be reached
14871487
values = values.astype(object)
14881488

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ def external_error_raised(expected_exception: type[Exception]) -> ContextManager
886886
"""
887887
import pytest
888888

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

891891

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

pandas/compat/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
import sys
1515

1616
from pandas._typing import F
17-
import pandas.compat._compressors
1817
from pandas.compat._constants import (
1918
IS64,
2019
PY39,
2120
PY310,
2221
PY311,
2322
PYPY,
2423
)
24+
import pandas.compat.compressors
2525
from pandas.compat.numpy import (
2626
is_numpy_dev,
2727
np_version_under1p21,
@@ -131,7 +131,7 @@ def is_ci_environment() -> bool:
131131
return os.environ.get("PANDAS_CI", "0") == "1"
132132

133133

134-
def get_lzma_file() -> type[pandas.compat._compressors.LZMAFile]:
134+
def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]:
135135
"""
136136
Importing the `LZMAFile` class from the `lzma` module.
137137
@@ -145,13 +145,13 @@ def get_lzma_file() -> type[pandas.compat._compressors.LZMAFile]:
145145
RuntimeError
146146
If the `lzma` module was not imported correctly, or didn't exist.
147147
"""
148-
if not pandas.compat._compressors.has_lzma:
148+
if not pandas.compat.compressors.has_lzma:
149149
raise RuntimeError(
150150
"lzma module not available. "
151151
"A Python re-install with the proper dependencies, "
152152
"might be required to solve this issue."
153153
)
154-
return pandas.compat._compressors.LZMAFile
154+
return pandas.compat.compressors.LZMAFile
155155

156156

157157
__all__ = [
File renamed without changes.

pandas/core/arrays/string_arrow.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable # noqa: PDF001
43
import re
5-
from typing import Union
4+
from typing import (
5+
Callable,
6+
Union,
7+
)
68

79
import numpy as np
810

pandas/core/generic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@
133133
from pandas.core import (
134134
algorithms as algos,
135135
arraylike,
136+
common,
136137
indexing,
137138
nanops,
138139
sample,
139140
)
140-
from pandas.core import common # noqa: PDF018
141141
from pandas.core.array_algos.replace import should_use_regex
142142
from pandas.core.arrays import ExtensionArray
143143
from pandas.core.base import PandasObject
@@ -158,7 +158,7 @@
158158
SingleArrayManager,
159159
)
160160
from pandas.core.internals.construction import mgr_to_mgr
161-
from pandas.core.internals.managers import _using_copy_on_write
161+
from pandas.core.internals.managers import using_copy_on_write
162162
from pandas.core.methods.describe import describe_ndframe
163163
from pandas.core.missing import (
164164
clean_fill_method,
@@ -10102,7 +10102,7 @@ def truncate(
1010210102
if isinstance(ax, MultiIndex):
1010310103
setattr(result, self._get_axis_name(axis), ax.truncate(before, after))
1010410104

10105-
if copy or (copy is None and not _using_copy_on_write()):
10105+
if copy or (copy is None and not using_copy_on_write()):
1010610106
result = result.copy(deep=copy)
1010710107

1010810108
return result

pandas/core/interchange/dataframe.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from pandas.core.interchange.dataframe_protocol import DataFrame as DataFrameXchg
88

99
if TYPE_CHECKING:
10-
import pandas as pd
11-
from pandas import Index
10+
from pandas import (
11+
DataFrame,
12+
Index,
13+
)
1214

1315

1416
class PandasDataFrameXchg(DataFrameXchg):
@@ -21,7 +23,7 @@ class PandasDataFrameXchg(DataFrameXchg):
2123
"""
2224

2325
def __init__(
24-
self, df: pd.DataFrame, nan_as_null: bool = False, allow_copy: bool = True
26+
self, df: DataFrame, nan_as_null: bool = False, allow_copy: bool = True
2527
) -> None:
2628
"""
2729
Constructor - an instance of this (private) class is returned from

0 commit comments

Comments
 (0)