Skip to content

Commit b82961d

Browse files
committed
changes for tests (lf, markxfail, ci)
1 parent a784a90 commit b82961d

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

pandas/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def _create_mi_with_dt64tz_level():
706706
"string-python": Index(
707707
pd.array([f"pandas_{i}" for i in range(10)], dtype="string[python]")
708708
),
709-
"mixed-int-string": Index([0, "a", 1, "b", 2, "c"])
709+
"mixed-int-string": Index([0, "a", 1, "b", 2, "c"]),
710710
}
711711
if has_pyarrow:
712712
idx = Index(pd.array([f"pandas_{i}" for i in range(10)], dtype="string[pyarrow]"))

pandas/tests/base/test_value_counts.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ def test_value_counts_null(null_obj, index_or_series_obj):
6363
elif isinstance(orig, MultiIndex):
6464
pytest.skip(f"MultiIndex can't hold '{null_obj}'")
6565

66-
if obj.dtype == 'object':
66+
if obj.dtype == "object":
6767
obj = obj.astype(str)
6868

69-
7069
values = obj._values
7170
values[0:2] = null_obj
7271

pandas/tests/indexes/test_common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,17 @@ def test_hasnans_isnans(self, index_flat):
436436
tm.assert_numpy_array_equal(idx._isnan, expected)
437437
assert idx.hasnans is True
438438

439-
440439
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
441440
@pytest.mark.parametrize("na_position", [None, "middle"])
442441
def test_sort_values_invalid_na_position(index_with_missing, na_position):
443442
non_na_values = [x for x in index_with_missing if pd.notna(x)]
444443
if len({type(x) for x in non_na_values}) > 1:
445-
pytest.xfail("Sorting fails due to heterogeneous types in index (int vs str)")
444+
pytest.mark.xfail(
445+
reason="Sorting fails due to heterogeneous types in index (int vs str)")
446446

447447
with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"):
448448
index_with_missing.sort_values(na_position=na_position)
449449

450-
451450
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
452451
@pytest.mark.parametrize("na_position", ["first", "last"])
453452
def test_sort_values_with_missing(index_with_missing, na_position, request):
@@ -456,7 +455,8 @@ def test_sort_values_with_missing(index_with_missing, na_position, request):
456455

457456
non_na_values = [x for x in index_with_missing if pd.notna(x)]
458457
if len({type(x) for x in non_na_values}) > 1:
459-
pytest.xfail("Sorting fails due to heterogeneous types in index (int vs str)")
458+
pytest.mark.xfail(
459+
reason="Sorting fails due to heterogeneous types in index (int vs str)")
460460

461461
if isinstance(index_with_missing, CategoricalIndex):
462462
request.applymarker(

pandas/tests/indexes/test_mixed_int_string.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import pytest
2+
23
import pandas as pd
34

5+
46
def test_mixed_int_string_index():
57
idx = pd.Index([0, "a", 1, "b", 2, "c"])
6-
8+
79
# Check if the index is of type Index
810
assert len(idx) == 6
911
assert idx[1] == "a"
1012
assert idx[-1] == "c"
11-
13+
1214
# Check if the index is sorted (it should not be)
1315
with pytest.raises(TypeError):
1416
idx.sort_values()

pandas/tests/indexes/test_numpy_compat.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,13 @@ def test_numpy_ufuncs_reductions(index, func, request):
156156
if len(index) == 0:
157157
pytest.skip("Test doesn't make sense for empty index.")
158158

159-
if any(isinstance(x, str) for x in index) and any(isinstance(x, int) for x in index):
159+
if any(isinstance(x, str) for x in index) and any(
160+
isinstance(x, int) for x in index
161+
):
160162
request.applymarker(
161-
pytest.mark.xfail(reason="Cannot compare mixed types (int and str) in ufunc reductions")
163+
pytest.mark.xfail(
164+
reason="Cannot compare mixed types (int and str) in ufunc reductions"
165+
)
162166
)
163167

164168
if isinstance(index, CategoricalIndex) and index.dtype.ordered is False:

pandas/tests/indexes/test_setops.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
from datetime import datetime
77
import operator
8-
import pandas as pd
8+
99
import numpy as np
1010
import pytest
1111

1212
from pandas._libs import lib
1313

1414
from pandas.core.dtypes.cast import find_common_type
1515

16+
import pandas as pd
1617
from pandas import (
1718
CategoricalDtype,
1819
CategoricalIndex,
@@ -71,12 +72,15 @@ def test_union_same_types(index):
7172
idx2 = index.sort_values()
7273
assert idx1.union(idx2, sort=False).dtype == idx1.dtype
7374

75+
7476
def test_union_different_types(index_flat, index_flat2, request):
7577
idx1 = index_flat
7678
idx2 = index_flat2
7779

78-
# Ειδική μεταχείριση για mixed-int-string
79-
if idx1.equals(pd.Index([0, "a", 1, "b", 2, "c"])) or idx2.equals(pd.Index([0, "a", 1, "b", 2, "c"])):
80+
# mixed int string
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+
):
8084
idx1 = idx1.astype(str)
8185
idx2 = idx2.astype(str)
8286

@@ -129,6 +133,7 @@ def test_union_different_types(index_flat, index_flat2, request):
129133
assert res1.dtype == common_dtype
130134
assert res2.dtype == common_dtype
131135

136+
132137
@pytest.mark.parametrize(
133138
"idx1,idx2",
134139
[
@@ -233,7 +238,6 @@ def test_intersection_base(self, index):
233238

234239
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
235240
def test_union_base(self, index):
236-
237241
if index.inferred_type in ["mixed", "mixed-integer"]:
238242
pytest.skip("Mixed-type Index not orderable; union fails")
239243

@@ -295,7 +299,6 @@ def test_difference_base(self, sort, index):
295299

296300
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
297301
def test_symmetric_difference(self, index, using_infer_string, request):
298-
299302
if (
300303
using_infer_string
301304
and index.dtype == "object"
@@ -392,7 +395,7 @@ def test_union_unequal(self, index_flat, fname, sname, expected_name):
392395
else:
393396
index = index_flat
394397

395-
if index.dtype == 'object':
398+
if index.dtype == "object":
396399
index = index.astype(str)
397400

398401
# test copy.union(subset) - need sort for unicode and string
@@ -464,7 +467,7 @@ def test_intersect_unequal(self, index_flat, fname, sname, expected_name):
464467
else:
465468
index = index_flat
466469

467-
if index.dtype == 'object':
470+
if index.dtype == "object":
468471
index = index.astype(str)
469472
# test copy.intersection(subset) - need sort for unicode and string
470473
first = index.copy().set_names(fname)
@@ -919,12 +922,16 @@ def test_symmetric_difference_mi(self, sort):
919922
index2 = MultiIndex.from_tuples([("foo", 1), ("bar", 3)])
920923

921924
def has_mixed_types(level):
922-
return any(isinstance(x, str) for x in level) and any(isinstance(x, int) for x in level)
925+
return any(isinstance(x, str) for x in level) and any(
926+
isinstance(x, int) for x in level
927+
)
923928

924929
for idx in [index1, index2]:
925930
for lvl in range(idx.nlevels):
926931
if has_mixed_types(idx.get_level_values(lvl)):
927-
pytest.skip(f"Mixed types in MultiIndex level {lvl} are not orderable")
932+
pytest.skip(
933+
f"Mixed types in MultiIndex level {lvl} are not orderable"
934+
)
928935

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

pandas/tests/test_algos.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,9 @@ 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("index_or_series_obj",
67-
[
68-
[1, 2, 3],
69-
["a", "b", "c"],
70-
[0, "a", 1, "b", 2, "c"]
71-
])
66+
@pytest.mark.parametrize(
67+
"index_or_series_obj", [[1, 2, 3], ["a", "b", "c"], [0, "a", 1, "b", 2, "c"]]
68+
)
7269
@pytest.mark.parametrize("sort", [True, False])
7370
def test_factorize(self, index_or_series_obj, sort):
7471
obj = Index(index_or_series_obj)
@@ -77,8 +74,9 @@ def test_factorize(self, index_or_series_obj, sort):
7774
pytest.skip("Skipping test for empty Index")
7875

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

8381
result_codes, result_uniques = obj.factorize(sort=sort)
8482

@@ -91,11 +89,9 @@ def test_factorize(self, index_or_series_obj, sort):
9189
if expected_uniques.dtype == bool and obj.dtype == object:
9290
expected_uniques = expected_uniques.astype(object)
9391

94-
9592
if sort:
9693
expected_uniques = expected_uniques.sort_values()
9794

98-
9995
# construct an integer ndarray so that
10096
# `expected_uniques.take(expected_codes)` is equal to `obj`
10197
expected_uniques_list = list(expected_uniques)

0 commit comments

Comments
 (0)