Skip to content

Commit

Permalink
REF: Share Index.delete (#43934)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Oct 10, 2021
1 parent 4276939 commit aeebff4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
9 changes: 8 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,7 @@ def is_all_dates(self) -> bool:
)
return self._is_all_dates

@final
@cache_readonly
def _is_multi(self) -> bool:
"""
Expand Down Expand Up @@ -6299,7 +6300,13 @@ def delete(self: _IndexT, loc) -> _IndexT:
>>> idx.delete([0, 2])
Index(['b'], dtype='object')
"""
res_values = np.delete(self._data, loc)
values = self._values
if isinstance(values, np.ndarray):
# TODO(__array_function__): special casing will be unnecessary
res_values = np.delete(values, loc)
else:
res_values = values.delete(loc)

# _constructor so RangeIndex->Int64Index
return self._constructor._simple_new(res_values, name=self.name)

Expand Down
11 changes: 0 additions & 11 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,6 @@ def __getitem__(self, key):

# ---------------------------------------------------------------------

def delete(self, loc):
"""
Make new Index with passed location(-s) deleted
Returns
-------
new_index : Index
"""
arr = self._data.delete(loc)
return type(self)._simple_new(arr, name=self.name)

def repeat(self, repeats, axis=None):
nv.validate_repeat((), {"axis": axis})
result = self._data.repeat(repeats, axis=axis)
Expand Down

0 comments on commit aeebff4

Please sign in to comment.