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: annotate to_numpy #32809

Merged
merged 1 commit into from
Mar 18, 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
4 changes: 3 additions & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ def __iter__(self):
for i in range(len(self)):
yield self[i]

def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default):
def to_numpy(
self, dtype=None, copy: bool = False, na_value=lib.no_default
) -> np.ndarray:
"""
Convert to a NumPy ndarray.

Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,10 @@ def skew(self, axis=None, dtype=None, out=None, keepdims=False, skipna=True):

# ------------------------------------------------------------------------
# Additional Methods
def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default):

def to_numpy(
self, dtype=None, copy: bool = False, na_value=lib.no_default
) -> np.ndarray:
result = np.asarray(self._ndarray, dtype=dtype)

if (copy or na_value is not lib.no_default) and result is self._ndarray:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def from_dict(cls, data, orient="columns", dtype=None, columns=None) -> "DataFra

return cls(data, index=index, columns=columns, dtype=dtype)

def to_numpy(self, dtype=None, copy=False) -> np.ndarray:
def to_numpy(self, dtype=None, copy: bool = False) -> np.ndarray:
"""
Convert the DataFrame to a NumPy array.

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def _from_factorized(cls, values, original):

_HANDLED_TYPES = (decimal.Decimal, numbers.Number, np.ndarray)

def to_numpy(self, dtype=None, copy=False, na_value=no_default, decimals=None):
def to_numpy(
self, dtype=None, copy: bool = False, na_value=no_default, decimals=None
) -> np.ndarray:
result = np.asarray(self, dtype=dtype)
if decimals is not None:
result = np.asarray([round(x, decimals) for x in result])
Expand Down