diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index 1b1d9d7640058..a431842218b3b 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -98,8 +98,8 @@ def get_indexer_indexer( sort_remaining=sort_remaining, na_position=na_position, ) - elif (ascending and target.is_monotonic_increasing) or ( - not ascending and target.is_monotonic_decreasing + elif (np.all(ascending) and target.is_monotonic_increasing) or ( + not np.any(ascending) and target.is_monotonic_decreasing ): # Check monotonic-ness before sort an index (GH 11080) return None diff --git a/pandas/tests/series/methods/test_sort_index.py b/pandas/tests/series/methods/test_sort_index.py index c5d4694f8bdbd..d6817aa179b7b 100644 --- a/pandas/tests/series/methods/test_sort_index.py +++ b/pandas/tests/series/methods/test_sort_index.py @@ -317,3 +317,21 @@ def test_sort_values_key_type(self): result = s.sort_index(key=lambda x: x.month_name()) expected = s.iloc[[2, 1, 0]] tm.assert_series_equal(result, expected) + + @pytest.mark.parametrize( + "ascending", + [ + [True, False], + [False, True], + ], + ) + def test_sort_index_multi_already_monotonic(self, ascending): + # GH 56049 + mi = MultiIndex.from_product([[1, 2], [3, 4]]) + ser = Series(range(len(mi)), index=mi) + result = ser.sort_index(ascending=ascending) + if ascending == [True, False]: + expected = ser.take([1, 0, 3, 2]) + elif ascending == [False, True]: + expected = ser.take([2, 3, 0, 1]) + tm.assert_series_equal(result, expected)