MCPcopy
hub / github.com/pandas-dev/pandas / sortlevel

Method sortlevel

pandas/core/indexes/base.py:2157–2201  ·  view source on GitHub ↗

For internal compatibility with the Index API. Sort the Index. This is for compat with MultiIndex Parameters ---------- ascending : bool, default True False to sort in descending order na_position : {'first' or 'last'}, default 'first'

(
        self,
        level=None,
        ascending: bool | list[bool] = True,
        sort_remaining=None,
        na_position: NaPosition = "first",
    )

Source from the content-addressed store, hash-verified

2155 return 0
2156
2157 def sortlevel(
2158 self,
2159 level=None,
2160 ascending: bool | list[bool] = True,
2161 sort_remaining=None,
2162 na_position: NaPosition = "first",
2163 ) -> tuple[Self, np.ndarray]:
2164 """
2165 For internal compatibility with the Index API.
2166
2167 Sort the Index. This is for compat with MultiIndex
2168
2169 Parameters
2170 ----------
2171 ascending : bool, default True
2172 False to sort in descending order
2173 na_position : {'first' or 'last'}, default 'first'
2174 Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at
2175 the end.
2176
2177 .. versionadded:: 2.1.0
2178
2179 level, sort_remaining are compat parameters
2180
2181 Returns
2182 -------
2183 Index
2184 """
2185 if not isinstance(ascending, (list, bool)):
2186 raise TypeError(
2187 "ascending must be a single bool value or"
2188 "a list of bool values of length 1"
2189 )
2190
2191 if isinstance(ascending, list):
2192 if len(ascending) != 1:
2193 raise TypeError("ascending must be a list of bool values of length 1")
2194 ascending = ascending[0]
2195
2196 if not isinstance(ascending, bool):
2197 raise TypeError("ascending must be a bool value")
2198
2199 return self.sort_values(
2200 return_indexer=True, ascending=ascending, na_position=na_position
2201 )
2202
2203 def _get_level_values(self, level) -> Index:
2204 """

Callers 15

test_sortlevelMethod · 0.95
time_sortlevel_int64Method · 0.45
time_sortlevel_zeroMethod · 0.45
time_sortlevel_oneMethod · 0.45
get_indexer_indexerFunction · 0.45
test_int64_overflowMethod · 0.45
test_differenceFunction · 0.45
test_sortlevelFunction · 0.45

Calls 1

sort_valuesMethod · 0.95

Tested by 12

test_sortlevelMethod · 0.76
test_int64_overflowMethod · 0.36
test_differenceFunction · 0.36
test_sortlevelFunction · 0.36