Skip to content

Commit 0ccca08

Browse files
committed
changes for pre-commit.ci
1 parent 254284b commit 0ccca08

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

pandas/tests/indexes/test_common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,8 @@ def test_hasnans_isnans(self, index_flat):
445445
def test_sort_values_invalid_na_position(index_with_missing, na_position):
446446
non_na_values = [x for x in index_with_missing if pd.notna(x)]
447447
if len({type(x) for x in non_na_values}) > 1:
448-
pytest.mark.xfail(
449-
reason="Sorting fails due to heterogeneous types in index (int vs str)"
450-
)
448+
pytest.xfail("Sorting fails due to heterogeneous types in index"
449+
" (int vs str)")
451450

452451
with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"):
453452
index_with_missing.sort_values(na_position=na_position)
@@ -464,9 +463,8 @@ def test_sort_values_with_missing(index_with_missing, na_position, request):
464463

465464
non_na_values = [x for x in index_with_missing if pd.notna(x)]
466465
if len({type(x) for x in non_na_values}) > 1:
467-
pytest.mark.xfail(
468-
reason="Sorting fails due to heterogeneous types in index (int vs str)"
469-
)
466+
pytest.xfail("Sorting fails due to heterogeneous types"
467+
" in index (int vs str)")
470468

471469
if isinstance(index_with_missing, CategoricalIndex):
472470
request.applymarker(

pandas/tests/indexes/test_numpy_compat.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,12 @@ def test_numpy_ufuncs_reductions(index, func, request):
155155
# TODO: overlap with tests.series.test_ufunc.test_reductions
156156
if len(index) == 0:
157157
pytest.skip("Test doesn't make sense for empty index.")
158-
159-
if any(isinstance(x, str) for x in index) and any(
160-
isinstance(x, int) for x in index
161-
):
158+
has_str = any(isinstance(x, str) for x in index)
159+
has_int = any(isinstance(x, int) for x in index)
160+
if has_str and has_int:
162161
request.applymarker(
163-
pytest.mark.xfail(
164-
reason=(
165-
"Cannot compare mixed types (int and str) in ufunc reductions"
166-
" and should raise a TypeError"
167-
)
168-
)
162+
pytest.mark.xfail(reason="Cannot compare mixed types (int and str)"
163+
" in ufunc reductions")
169164
)
170165
if isinstance(index, CategoricalIndex) and index.dtype.ordered is False:
171166
with pytest.raises(TypeError, match="is not ordered for"):

pandas/tests/indexes/test_setops.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ def test_union_same_types(index):
7676
def test_union_different_types(index_flat, index_flat2, request):
7777
idx1 = index_flat
7878
idx2 = index_flat2
79-
80-
# Special handling for mixed int-string types
81-
if idx1.equals(pd.Index([0, "a", 1, "b", 2, "c"])) or idx2.equals(
82-
pd.Index([0, "a", 1, "b", 2, "c"])
83-
):
79+
# mixed int string
80+
target_index = pd.Index([0, "a", 1, "b", 2, "c"])
81+
if idx1.equals(target_index) or idx2.equals(target_index):
8482
idx1 = idx1.astype(str)
8583
idx2 = idx2.astype(str)
8684

@@ -922,17 +920,16 @@ def test_symmetric_difference_mi(self, sort):
922920
index2 = MultiIndex.from_tuples([("foo", 1), ("bar", 3)])
923921

924922
def has_mixed_types(level):
925-
return any(isinstance(x, str) for x in level) and any(
926-
isinstance(x, int) for x in level
923+
return (
924+
any(isinstance(x, str) for x in level)
925+
and any(isinstance(x, int) for x in level)
927926
)
928927

929928
for idx in [index1, index2]:
930929
for lvl in range(idx.nlevels):
931930
if has_mixed_types(idx.get_level_values(lvl)):
932-
skip_message = (
933-
f"Mixed types in MultiIndex level {lvl} are not orderable"
934-
)
935-
pytest.skip(skip_message)
931+
pytest.skip(f"Mixed types in MultiIndex level {lvl}"
932+
" are not orderable")
936933

937934
result = index1.symmetric_difference(index2, sort=sort)
938935
expected = MultiIndex.from_tuples([("bar", 2), ("baz", 3), ("bar", 3)])

pandas/tests/test_algos.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ def test_factorize_complex(self):
6363
expected_uniques = np.array([(1 + 0j), (2 + 0j), (2 + 1j)], dtype=complex)
6464
tm.assert_numpy_array_equal(uniques, expected_uniques)
6565

66-
@pytest.mark.parametrize(
67-
"index_or_series_obj", [[1, 2, 3], ["a", "b", "c"], [0, "a", 1, "b", 2, "c"]]
68-
)
66+
@pytest.mark.parametrize("index_or_series_obj",
67+
[
68+
[1, 2, 3],
69+
["a", "b", "c"],
70+
[0, "a", 1, "b", 2, "c"]
71+
])
6972
@pytest.mark.parametrize("sort", [True, False])
7073
def test_factorize(self, index_or_series_obj, sort):
7174
obj = Index(index_or_series_obj)
@@ -74,11 +77,9 @@ def test_factorize(self, index_or_series_obj, sort):
7477
pytest.skip("Skipping test for empty Index")
7578

7679
if obj.name == "mixed-int-string" or obj.name is None:
77-
skip_message = (
78-
"Skipping test for mixed-int-string due to unsupported comparison "
79-
"between str and int"
80-
)
81-
pytest.skip(skip_message)
80+
pytest.skip("Skipping test for mixed-int-string due"
81+
" to unsupported comparison between str and int")
82+
8283

8384
result_codes, result_uniques = obj.factorize(sort=sort)
8485

0 commit comments

Comments
 (0)