Skip to content

Commit

Permalink
TYP: ExtensionIndex (#38783)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Dec 29, 2020
1 parent 508d0d2 commit 9415d10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 8 additions & 2 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def __repr__(self) -> str:
# ------------------------------------------------------------------------
# __array_function__ methods

def putmask(self, mask, value):
def putmask(self: NDArrayBackedExtensionArrayT, mask: np.ndarray, value) -> None:
"""
Analogue to np.putmask(self, mask, value)
Expand All @@ -343,7 +343,9 @@ def putmask(self, mask, value):

np.putmask(self._ndarray, mask, value)

def where(self, mask, value):
def where(
self: NDArrayBackedExtensionArrayT, mask: np.ndarray, value
) -> NDArrayBackedExtensionArrayT:
"""
Analogue to np.where(mask, self, value)
Expand All @@ -361,3 +363,7 @@ def where(self, mask, value):

res_values = np.where(mask, self._ndarray, value)
return self._from_backing_data(res_values)

def delete(self: NDArrayBackedExtensionArrayT, loc) -> NDArrayBackedExtensionArrayT:
res_values = np.delete(self._ndarray, loc)
return self._from_backing_data(res_values)
9 changes: 4 additions & 5 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,18 @@ class NDArrayBackedExtensionIndex(ExtensionIndex):
def _get_engine_target(self) -> np.ndarray:
return self._data._ndarray

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

def insert(self, loc: int, item):
def insert(self: _T, loc: int, item) -> _T:
"""
Make new Index inserting new item at location. Follows
Python list.append semantics for negative values.
Expand All @@ -371,7 +370,7 @@ def insert(self, loc: int, item):
return type(self)._simple_new(new_arr, name=self.name)

@doc(Index.where)
def where(self, cond, other=None):
def where(self: _T, cond: np.ndarray, other=None) -> _T:
res_values = self._data.where(cond, other)
return type(self)._simple_new(res_values, name=self.name)

Expand Down

0 comments on commit 9415d10

Please sign in to comment.