Skip to content

Commit 4b2b518

Browse files
authored
Backport PR pandas-dev#53548: CI/DEPS: Add xfail(strict=False) to related unstable sorting changes in Numpy 1.25 (pandas-dev#53566)
1 parent 745847e commit 4b2b518

File tree

3 files changed

+123
-10
lines changed

3 files changed

+123
-10
lines changed

pandas/tests/frame/methods/test_nlargest.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pandas as pd
1111
import pandas._testing as tm
12+
from pandas.util.version import Version
1213

1314

1415
@pytest.fixture
@@ -155,7 +156,7 @@ def test_nlargest_n_identical_values(self):
155156
[["a", "b", "c"], ["c", "b", "a"], ["a"], ["b"], ["a", "b"], ["c", "b"]],
156157
)
157158
@pytest.mark.parametrize("n", range(1, 6))
158-
def test_nlargest_n_duplicate_index(self, df_duplicates, n, order):
159+
def test_nlargest_n_duplicate_index(self, df_duplicates, n, order, request):
159160
# GH#13412
160161

161162
df = df_duplicates
@@ -165,6 +166,18 @@ def test_nlargest_n_duplicate_index(self, df_duplicates, n, order):
165166

166167
result = df.nlargest(n, order)
167168
expected = df.sort_values(order, ascending=False).head(n)
169+
if Version(np.__version__) >= Version("1.25") and (
170+
(order == ["a"] and n in (1, 2, 3, 4)) or (order == ["a", "b"]) and n == 5
171+
):
172+
request.node.add_marker(
173+
pytest.mark.xfail(
174+
reason=(
175+
"pandas default unstable sorting of duplicates"
176+
"issue with numpy>=1.25 with AVX instructions"
177+
),
178+
strict=False,
179+
)
180+
)
168181
tm.assert_frame_equal(result, expected)
169182

170183
def test_nlargest_duplicate_keep_all_ties(self):

pandas/tests/frame/methods/test_sort_values.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
date_range,
1313
)
1414
import pandas._testing as tm
15+
from pandas.util.version import Version
1516

1617

1718
class TestDataFrameSortValues:
@@ -849,9 +850,22 @@ def ascending(request):
849850

850851
class TestSortValuesLevelAsStr:
851852
def test_sort_index_level_and_column_label(
852-
self, df_none, df_idx, sort_names, ascending
853+
self, df_none, df_idx, sort_names, ascending, request
853854
):
854855
# GH#14353
856+
if (
857+
Version(np.__version__) >= Version("1.25")
858+
and request.node.callspec.id == "df_idx0-inner-True"
859+
):
860+
request.node.add_marker(
861+
pytest.mark.xfail(
862+
reason=(
863+
"pandas default unstable sorting of duplicates"
864+
"issue with numpy>=1.25 with AVX instructions"
865+
),
866+
strict=False,
867+
)
868+
)
855869

856870
# Get index levels from df_idx
857871
levels = df_idx.index.names
@@ -867,7 +881,7 @@ def test_sort_index_level_and_column_label(
867881
tm.assert_frame_equal(result, expected)
868882

869883
def test_sort_column_level_and_index_label(
870-
self, df_none, df_idx, sort_names, ascending
884+
self, df_none, df_idx, sort_names, ascending, request
871885
):
872886
# GH#14353
873887

@@ -886,6 +900,17 @@ def test_sort_column_level_and_index_label(
886900
# Compute result by transposing and sorting on axis=1.
887901
result = df_idx.T.sort_values(by=sort_names, ascending=ascending, axis=1)
888902

903+
if Version(np.__version__) >= Version("1.25"):
904+
request.node.add_marker(
905+
pytest.mark.xfail(
906+
reason=(
907+
"pandas default unstable sorting of duplicates"
908+
"issue with numpy>=1.25 with AVX instructions"
909+
),
910+
strict=False,
911+
)
912+
)
913+
889914
tm.assert_frame_equal(result, expected)
890915

891916
def test_sort_values_validate_ascending_for_value_error(self):

pandas/tests/groupby/test_value_counts.py

+82-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
to_datetime,
2222
)
2323
import pandas._testing as tm
24+
from pandas.util.version import Version
2425

2526

2627
def tests_value_counts_index_names_category_column():
@@ -244,8 +245,18 @@ def test_bad_subset(education_df):
244245
gp.value_counts(subset=["country"])
245246

246247

247-
def test_basic(education_df):
248+
def test_basic(education_df, request):
248249
# gh43564
250+
if Version(np.__version__) >= Version("1.25"):
251+
request.node.add_marker(
252+
pytest.mark.xfail(
253+
reason=(
254+
"pandas default unstable sorting of duplicates"
255+
"issue with numpy>=1.25 with AVX instructions"
256+
),
257+
strict=False,
258+
)
259+
)
249260
result = education_df.groupby("country")[["gender", "education"]].value_counts(
250261
normalize=True
251262
)
@@ -283,7 +294,7 @@ def _frame_value_counts(df, keys, normalize, sort, ascending):
283294
@pytest.mark.parametrize("as_index", [True, False])
284295
@pytest.mark.parametrize("frame", [True, False])
285296
def test_against_frame_and_seriesgroupby(
286-
education_df, groupby, normalize, name, sort, ascending, as_index, frame
297+
education_df, groupby, normalize, name, sort, ascending, as_index, frame, request
287298
):
288299
# test all parameters:
289300
# - Use column, array or function as by= parameter
@@ -293,6 +304,16 @@ def test_against_frame_and_seriesgroupby(
293304
# - 3-way compare against:
294305
# - apply with :meth:`~DataFrame.value_counts`
295306
# - `~SeriesGroupBy.value_counts`
307+
if Version(np.__version__) >= Version("1.25") and frame and sort and normalize:
308+
request.node.add_marker(
309+
pytest.mark.xfail(
310+
reason=(
311+
"pandas default unstable sorting of duplicates"
312+
"issue with numpy>=1.25 with AVX instructions"
313+
),
314+
strict=False,
315+
)
316+
)
296317
by = {
297318
"column": "country",
298319
"array": education_df["country"].values,
@@ -454,8 +475,18 @@ def nulls_df():
454475
],
455476
)
456477
def test_dropna_combinations(
457-
nulls_df, group_dropna, count_dropna, expected_rows, expected_values
478+
nulls_df, group_dropna, count_dropna, expected_rows, expected_values, request
458479
):
480+
if Version(np.__version__) >= Version("1.25") and not group_dropna:
481+
request.node.add_marker(
482+
pytest.mark.xfail(
483+
reason=(
484+
"pandas default unstable sorting of duplicates"
485+
"issue with numpy>=1.25 with AVX instructions"
486+
),
487+
strict=False,
488+
)
489+
)
459490
gp = nulls_df.groupby(["A", "B"], dropna=group_dropna)
460491
result = gp.value_counts(normalize=True, sort=True, dropna=count_dropna)
461492
columns = DataFrame()
@@ -546,10 +577,20 @@ def test_data_frame_value_counts_dropna(
546577
],
547578
)
548579
def test_categorical_single_grouper_with_only_observed_categories(
549-
education_df, as_index, observed, normalize, name, expected_data
580+
education_df, as_index, observed, normalize, name, expected_data, request
550581
):
551582
# Test single categorical grouper with only observed grouping categories
552583
# when non-groupers are also categorical
584+
if Version(np.__version__) >= Version("1.25"):
585+
request.node.add_marker(
586+
pytest.mark.xfail(
587+
reason=(
588+
"pandas default unstable sorting of duplicates"
589+
"issue with numpy>=1.25 with AVX instructions"
590+
),
591+
strict=False,
592+
)
593+
)
553594

554595
gp = education_df.astype("category").groupby(
555596
"country", as_index=as_index, observed=observed
@@ -645,10 +686,21 @@ def assert_categorical_single_grouper(
645686
],
646687
)
647688
def test_categorical_single_grouper_observed_true(
648-
education_df, as_index, normalize, name, expected_data
689+
education_df, as_index, normalize, name, expected_data, request
649690
):
650691
# GH#46357
651692

693+
if Version(np.__version__) >= Version("1.25"):
694+
request.node.add_marker(
695+
pytest.mark.xfail(
696+
reason=(
697+
"pandas default unstable sorting of duplicates"
698+
"issue with numpy>=1.25 with AVX instructions"
699+
),
700+
strict=False,
701+
)
702+
)
703+
652704
expected_index = [
653705
("FR", "male", "low"),
654706
("FR", "female", "high"),
@@ -715,10 +767,21 @@ def test_categorical_single_grouper_observed_true(
715767
],
716768
)
717769
def test_categorical_single_grouper_observed_false(
718-
education_df, as_index, normalize, name, expected_data
770+
education_df, as_index, normalize, name, expected_data, request
719771
):
720772
# GH#46357
721773

774+
if Version(np.__version__) >= Version("1.25"):
775+
request.node.add_marker(
776+
pytest.mark.xfail(
777+
reason=(
778+
"pandas default unstable sorting of duplicates"
779+
"issue with numpy>=1.25 with AVX instructions"
780+
),
781+
strict=False,
782+
)
783+
)
784+
722785
expected_index = [
723786
("FR", "male", "low"),
724787
("FR", "female", "high"),
@@ -856,10 +919,22 @@ def test_categorical_multiple_groupers(
856919
],
857920
)
858921
def test_categorical_non_groupers(
859-
education_df, as_index, observed, normalize, name, expected_data
922+
education_df, as_index, observed, normalize, name, expected_data, request
860923
):
861924
# GH#46357 Test non-observed categories are included in the result,
862925
# regardless of `observed`
926+
927+
if Version(np.__version__) >= Version("1.25"):
928+
request.node.add_marker(
929+
pytest.mark.xfail(
930+
reason=(
931+
"pandas default unstable sorting of duplicates"
932+
"issue with numpy>=1.25 with AVX instructions"
933+
),
934+
strict=False,
935+
)
936+
)
937+
863938
education_df = education_df.copy()
864939
education_df["gender"] = education_df["gender"].astype("category")
865940
education_df["education"] = education_df["education"].astype("category")

0 commit comments

Comments
 (0)