Skip to content

TYP: add some types to pandas/core/arrays/numpy_.py #29969

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

Merged
Merged
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numbers
from typing import Union

import numpy as np
from numpy.lib.mixins import NDArrayOperatorsMixin
Expand Down Expand Up @@ -121,7 +122,7 @@ class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin):
# ------------------------------------------------------------------------
# Constructors

def __init__(self, values, copy=False):
def __init__(self, values: Union[np.ndarray, "PandasArray"], copy: bool = False):
if isinstance(values, type(self)):
values = values._ndarray
if not isinstance(values, np.ndarray):
Expand All @@ -137,8 +138,8 @@ def __init__(self, values, copy=False):
if copy:
values = values.copy()

self._ndarray = values
self._dtype = PandasDtype(values.dtype)
self._ndarray: np.ndarray = values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move the definition to the class level as in some of the work @jbrockmendel has been doing as well? Off the top of my head I thought that was the PEP recommendation

self._dtype: ExtensionDtype = PandasDtype(values.dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is PandasDtype valid here? seems more specific

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove for now. mypy may no longer require this type annotation.


@classmethod
def _from_sequence(cls, scalars, dtype=None, copy=False):
Expand Down