Skip to content

Commit c25ed5d

Browse files
authored
STY: Enable ruff pytest checks (#56671)
* Enable PT001 * Add PT002 * Add PT003 * ignore 4 and 5 * Ignore 6, 7, 8 * Ignore PT009 * Enable PT010 * Enable PT011 * Ignore 12, enable 13 * Enable PT014 * Enforce PT015 * Enable 16 * Disable 17 * Ignore 18 * Ignore 19 * Add 20 * add 21 * Enable 22 * Add 23 * Add 24 * Add 25 * add 26 * Add 27 * use PT * fix some tests * Deduplcate test * Add tests * Added nested tuple case
1 parent 9a05458 commit c25ed5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+78
-315
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,6 @@ repos:
272272
language: python
273273
types: [rst]
274274
files: ^doc/source/(development|reference)/
275-
- id: unwanted-patterns-bare-pytest-raises
276-
name: Check for use of bare pytest raises
277-
language: python
278-
entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises"
279-
types: [python]
280-
files: ^pandas/tests/
281-
exclude: ^pandas/tests/extension/
282275
- id: unwanted-patterns-private-function-across-module
283276
name: Check for use of private functions across modules
284277
language: python

pandas/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,6 @@ def warsaw(request) -> str:
19711971
return request.param
19721972

19731973

1974-
@pytest.fixture()
1974+
@pytest.fixture
19751975
def arrow_string_storage():
19761976
return ("pyarrow", "pyarrow_numpy")

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,6 @@ def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit):
13851385
"SemiMonthBegin",
13861386
"Week",
13871387
("Week", {"weekday": 3}),
1388-
"Week",
13891388
("Week", {"weekday": 6}),
13901389
"BusinessDay",
13911390
"BDay",

pandas/tests/arrays/categorical/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ def test_set_categories(self):
291291
(["a", "b", "c"], ["a", "b"], ["a", "b"]),
292292
(["a", "b", "c"], ["a", "b"], ["b", "a"]),
293293
(["b", "a", "c"], ["a", "b"], ["a", "b"]),
294-
(["b", "a", "c"], ["a", "b"], ["a", "b"]),
294+
(["b", "a", "c"], ["a", "b"], ["b", "a"]),
295295
# Introduce NaNs
296296
(["a", "b", "c"], ["a", "b"], ["a"]),
297297
(["a", "b", "c"], ["a", "b"], ["b"]),
298298
(["b", "a", "c"], ["a", "b"], ["a"]),
299-
(["b", "a", "c"], ["a", "b"], ["a"]),
299+
(["b", "a", "c"], ["a", "b"], ["b"]),
300300
# No overlap
301301
(["a", "b", "c"], ["a", "b"], ["d", "e"]),
302302
],

pandas/tests/arrays/categorical/test_dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def test_set_dtype_new_categories(self):
7373
(["a", "b", "c"], ["a", "b"], ["a", "b"]),
7474
(["a", "b", "c"], ["a", "b"], ["b", "a"]),
7575
(["b", "a", "c"], ["a", "b"], ["a", "b"]),
76-
(["b", "a", "c"], ["a", "b"], ["a", "b"]),
76+
(["b", "a", "c"], ["a", "b"], ["b", "a"]),
7777
# Introduce NaNs
7878
(["a", "b", "c"], ["a", "b"], ["a"]),
7979
(["a", "b", "c"], ["a", "b"], ["b"]),
8080
(["b", "a", "c"], ["a", "b"], ["a"]),
81-
(["b", "a", "c"], ["a", "b"], ["a"]),
81+
(["b", "a", "c"], ["a", "b"], ["b"]),
8282
# No overlap
8383
(["a", "b", "c"], ["a", "b"], ["d", "e"]),
8484
],

pandas/tests/arrays/masked/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def data(request):
2121
return request.param
2222

2323

24-
@pytest.fixture()
24+
@pytest.fixture
2525
def numpy_dtype(data):
2626
"""
2727
Fixture returning numpy dtype from 'data' input array.

pandas/tests/arrays/sparse/test_arithmetics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,6 @@ def test_ufuncs(ufunc, arr):
433433
[
434434
(SparseArray([0, 0, 0]), np.array([0, 1, 2])),
435435
(SparseArray([0, 0, 0], fill_value=1), np.array([0, 1, 2])),
436-
(SparseArray([0, 0, 0], fill_value=1), np.array([0, 1, 2])),
437-
(SparseArray([0, 0, 0], fill_value=1), np.array([0, 1, 2])),
438-
(SparseArray([0, 0, 0], fill_value=1), np.array([0, 1, 2])),
439436
],
440437
)
441438
@pytest.mark.parametrize("ufunc", [np.add, np.greater])

pandas/tests/arrays/string_/test_string_arrow.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,22 @@ def test_setitem_invalid_indexer_raises():
220220

221221
arr = ArrowStringArray(pa.array(list("abcde")))
222222

223-
with pytest.raises(IndexError, match=None):
223+
with tm.external_error_raised(IndexError):
224224
arr[5] = "foo"
225225

226-
with pytest.raises(IndexError, match=None):
226+
with tm.external_error_raised(IndexError):
227227
arr[-6] = "foo"
228228

229-
with pytest.raises(IndexError, match=None):
229+
with tm.external_error_raised(IndexError):
230230
arr[[0, 5]] = "foo"
231231

232-
with pytest.raises(IndexError, match=None):
232+
with tm.external_error_raised(IndexError):
233233
arr[[0, -6]] = "foo"
234234

235-
with pytest.raises(IndexError, match=None):
235+
with tm.external_error_raised(IndexError):
236236
arr[[True, True, False]] = "foo"
237237

238-
with pytest.raises(ValueError, match=None):
238+
with tm.external_error_raised(ValueError):
239239
arr[[0, 1]] = ["foo", "bar", "baz"]
240240

241241

pandas/tests/arrays/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030

3131

32-
@pytest.mark.parametrize("dtype_unit", ["M8[h]", "M8[m]", "m8[h]", "M8[m]"])
32+
@pytest.mark.parametrize("dtype_unit", ["M8[h]", "M8[m]", "m8[h]"])
3333
def test_dt64_array(dtype_unit):
3434
# PR 53817
3535
dtype_var = np.dtype(dtype_unit)

pandas/tests/copy_view/test_internals.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def test_switch_options():
8383
([0, 1, 2], np.array([[-1, -2, -3], [-4, -5, -6], [-4, -5, -6]]).T),
8484
([1, 2], np.array([[-1, -2, -3], [-4, -5, -6]]).T),
8585
([1, 3], np.array([[-1, -2, -3], [-4, -5, -6]]).T),
86-
([1, 3], np.array([[-1, -2, -3], [-4, -5, -6]]).T),
8786
],
8887
)
8988
def test_iset_splits_blocks_inplace(using_copy_on_write, locs, arr, dtype):

0 commit comments

Comments
 (0)