Skip to content

Commit dceb014

Browse files
committed
Resolve conflicts after branch change
1 parent c0ca9ae commit dceb014

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

pandas/tests/indexes/test_common.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,18 @@ def test_sort_values_invalid_na_position(
459459

460460
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
461461
@pytest.mark.parametrize("na_position", ["first", "last"])
462+
@pytest.mark.parametrize("box_in_series", [False, True])
462463
@pytest.mark.xfail(
463-
reason="Sorting fails due to heterogeneous types in index (int vs str)"
464+
reason="Sorting fails due to heterogeneous types in index (int vs str)",
465+
strict=False,
464466
)
465-
def test_sort_values_with_missing(index_with_missing, na_position, request):
467+
def test_sort_values_with_missing(index_with_missing, na_position, request, box_in_series):
466468
# GH 35584. Test that sort_values works with missing values,
467469
# sort non-missing and place missing according to na_position
468470

471+
if box_in_series:
472+
index_with_missing = pd.Series(index_with_missing)
473+
469474
non_na_values = [x for x in index_with_missing if pd.notna(x)]
470475
if len({type(x) for x in non_na_values}) > 1:
471476
index_with_missing = index_with_missing.map(str)
@@ -478,18 +483,30 @@ def test_sort_values_with_missing(index_with_missing, na_position, request):
478483
)
479484

480485
missing_count = np.sum(index_with_missing.isna())
481-
not_na_vals = index_with_missing[index_with_missing.notna()].values
486+
487+
if isinstance(index_with_missing, pd.Series):
488+
not_na_vals = index_with_missing[index_with_missing.notna()].values
489+
else:
490+
not_na_vals = index_with_missing[index_with_missing.notna()].values
491+
492+
482493
sorted_values = np.sort(not_na_vals)
483494
if na_position == "first":
484495
sorted_values = np.concatenate([[None] * missing_count, sorted_values])
485496
else:
486497
sorted_values = np.concatenate([sorted_values, [None] * missing_count])
487498

488499
# Explicitly pass dtype needed for Index backed by EA e.g. IntegerArray
489-
expected = type(index_with_missing)(sorted_values, dtype=index_with_missing.dtype)
500+
if isinstance(index_with_missing, pd.Series):
501+
expected = pd.Series(sorted_values, dtype=index_with_missing.dtype)
502+
else:
503+
expected = type(index_with_missing)(sorted_values, dtype=index_with_missing.dtype)
490504

491505
result = index_with_missing.sort_values(na_position=na_position)
492-
tm.assert_index_equal(result, expected)
506+
if isinstance(index_with_missing, pd.Series):
507+
tm.assert_series_equal(result, expected)
508+
else:
509+
tm.assert_index_equal(result, expected)
493510

494511

495512
def test_sort_values_natsort_key():

0 commit comments

Comments
 (0)