Skip to content

TYP: misc fixes for numpy types 4 #36102

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

Closed
wants to merge 4 commits into from
Closed
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/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class NDArrayBackedExtensionArray(ExtensionArray):
ExtensionArray that is backed by a single NumPy ndarray.
"""

_ndarray: np.ndarray
@property
def _ndarray(self) -> np.ndarray:
raise AbstractMethodError(self)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to not prefer an abc here?


def _from_backing_data(self: _T, arr: np.ndarray) -> _T:
"""
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class PandasArray(
# pandas internals, which turns off things like block consolidation.
_typ = "npy_extension"
__array_priority__ = 1000
_ndarray: np.ndarray

# ------------------------------------------------------------------------
# Constructors
Expand All @@ -172,9 +171,13 @@ def __init__(self, values: Union[np.ndarray, "PandasArray"], copy: bool = False)
if copy:
values = values.copy()

self._ndarray = values
self._data = values
self._dtype = PandasDtype(values.dtype)

@property
def _ndarray(self) -> np.ndarray:
return self._data

@classmethod
def _from_sequence(cls, scalars, dtype=None, copy: bool = False) -> "PandasArray":
if isinstance(dtype, PandasDtype):
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ def _adjust_to_origin(arg, origin, unit):


@overload
def to_datetime(
# error: Overloaded function signatures 1 and 3 overlap with incompatible return types
Copy link
Member

Choose a reason for hiding this comment

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

Hmm do you know why we are getting this error? Seems like an issue with the annotation

Copy link
Member Author

Choose a reason for hiding this comment

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

since np.ndarray resolves to Any, this will need ignores if merging now b4 the numpy types are available. will close and include in #36092 instead.

def to_datetime( # type: ignore[misc]
arg: DatetimeScalar,
errors: str = ...,
dayfirst: bool = ...,
Expand All @@ -567,7 +568,8 @@ def to_datetime(


@overload
def to_datetime(
# error: Overloaded function signatures 2 and 3 overlap with incompatible return types
def to_datetime( # type: ignore[misc]
arg: "Series",
errors: str = ...,
dayfirst: bool = ...,
Expand All @@ -585,7 +587,7 @@ def to_datetime(

@overload
def to_datetime(
arg: Union[List, Tuple],
arg: Union[List, Tuple, ArrayLike],
errors: str = ...,
dayfirst: bool = ...,
yearfirst: bool = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def handle_shared_axes(
_remove_labels_from_axis(ax.yaxis)


def flatten_axes(axes: Union["Axes", Sequence["Axes"]]) -> Sequence["Axes"]:
def flatten_axes(axes: Union["Axes", Sequence["Axes"]]) -> np.ndarray:
if not is_list_like(axes):
return np.array([axes])
elif isinstance(axes, (np.ndarray, ABCIndexClass)):
Expand Down