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

Method _drop_from_level

pandas/core/indexes/multi.py:2873–2892  ·  view source on GitHub ↗
(
        self, codes, level, errors: IgnoreRaise = "raise"
    )

Source from the content-addressed store, hash-verified

2871 return self.delete(inds)
2872
2873 def _drop_from_level(
2874 self, codes, level, errors: IgnoreRaise = "raise"
2875 ) -> MultiIndex:
2876 codes = com.index_labels_to_array(codes)
2877 i = self._get_level_number(level)
2878 index = self.levels[i]
2879 values = index.get_indexer(codes)
2880 # If nan should be dropped it will equal -1 here. We have to check which values
2881 # are not nan and equal -1, this means they are missing in the index
2882 nan_codes = isna(codes)
2883 values[(np.equal(nan_codes, False)) & (values == -1)] = -2
2884 if index.shape[0] == self.shape[0]:
2885 values[np.equal(nan_codes, True)] = -2
2886
2887 not_found = codes[values == -2]
2888 if len(not_found) != 0 and errors != "ignore":
2889 raise KeyError(f"labels {not_found} not found in level")
2890 mask = ~algos.isin(self.codes[i], values)
2891
2892 return self[mask]
2893
2894 def swaplevel(self, i=-2, j=-1) -> MultiIndex:
2895 """

Callers 1

dropMethod · 0.95

Calls 4

_get_level_numberMethod · 0.95
isnaFunction · 0.90
get_indexerMethod · 0.45
isinMethod · 0.45

Tested by

no test coverage detected