Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYP: ExtensionIndex #38783

Merged
merged 2 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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