Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

🐛 fix typing errors in numpy.ndarray #200

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 3 commits into from
Feb 25, 2025
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
3,085 changes: 1,712 additions & 1,373 deletions 3,085 src/numpy-stubs/__init__.pyi

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 4 src/numpy-stubs/_core/_multiarray_umath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import numpy as np
import numpy.typing as npt
from numpy import ( # noqa: ICN003
_AnyShapeT,
_CanSeekTellFileNo,
_CastingKind,
_ModeKind,
_OrderCF,
_OrderKACF,
_SupportsBuffer,
_SupportsFileMethods,
# NOTE: These implicitly re-exported ufuncs are defined in this ext-module at runtime
absolute as absolute,
add as add,
Expand Down Expand Up @@ -266,7 +266,7 @@ _ToDeltaArray = TypeAliasType(
_ArrayLike[np.timedelta64[Any] | np.integer] | _NestedSequence[_ToDelta],
)

_ToFile: TypeAlias = StrOrBytesPath | _SupportsFileMethods
_ToFile: TypeAlias = StrOrBytesPath | _CanSeekTellFileNo

_3P = TypeAliasType("_3P", L[3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
_2: TypeAlias = L[2]
Expand Down
17 changes: 13 additions & 4 deletions 17 src/numpy-stubs/_core/defchararray.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import ConvertibleToInt
from typing import Any, Literal as L, SupportsIndex, TypeAlias, overload
from typing_extensions import Self, TypeVar
from typing_extensions import Self, TypeVar, override

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -134,11 +134,17 @@ class chararray(np.ndarray[_ShapeT_co, _DTypeT_co]):
) -> chararray[_Shape, np.dtype[np.str_]]: ...

#
def __eq__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override]
def __ne__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override]
@override
def __eq__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __ne__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __ge__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __gt__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __lt__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __le__(self, other: _ToCharND, /) -> npt.NDArray[np.bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

#
Expand All @@ -153,9 +159,12 @@ class chararray(np.ndarray[_ShapeT_co, _DTypeT_co]):
def __radd__(self: _CharArray[np.bytes_], lhs: _ToBytesND, /) -> _CharArray[np.bytes_]: ... # pyright: ignore[reportIncompatibleMethodOverride]

#
@override
def __mul__(self, rhs: _ToIntND, /) -> chararray[_Shape, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __rmul__(self, lhs: _ToIntND, /) -> chararray[_Shape, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __mod__(self, rhs: object, /) -> Self: ... # pyright: ignore[reportIncompatibleMethodOverride]
@override
def __mod__(self, rhs: object, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

#
def decode(
Expand Down
1 change: 1 addition & 0 deletions 1 src/numpy-stubs/_typing/_ufunc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class _SupportsArrayUFunc(Protocol):
self,
ufunc: np.ufunc,
method: Literal["__call__", "reduce", "reduceat", "accumulate", "outer", "at"],
/,
*inputs: Any,
**kwargs: Any,
) -> Any: ...
Expand Down
23 changes: 17 additions & 6 deletions 23 src/numpy-stubs/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
@property
def shape(self) -> _ShapeT_co: ...
@shape.setter
def shape(self: MaskedArray[_ShapeT], shape: _ShapeT, /) -> None: ...
def shape(self: MaskedArray[_ShapeT], shape: _ShapeT, /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride]

#
@property
Expand Down Expand Up @@ -438,7 +438,7 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
def __deepcopy__(self, /, memo: Incomplete = ...) -> Self: ...

#
def view( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def view( # pyright: ignore[reportIncompatibleMethodOverride]
self,
/,
dtype: Incomplete = None,
Expand All @@ -463,7 +463,7 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
refcheck: Incomplete = ...,
order: Incomplete = ...,
) -> Incomplete: ...
def put(self, indices: Incomplete, values: Incomplete, mode: Incomplete = ...) -> Incomplete: ... # pyright: ignore[reportIncompatibleMethodOverride]
def put(self, indices: Incomplete, values: Incomplete, mode: Incomplete = ...) -> Incomplete: ...
def ids(self) -> Incomplete: ...
def iscontiguous(self) -> Incomplete: ...
def all( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
Expand All @@ -479,7 +479,7 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
keepdims: Incomplete = ...,
) -> Incomplete: ...
def nonzero(self) -> Incomplete: ...
def trace(
def trace( # pyright: ignore[reportIncompatibleMethodOverride]
self,
offset: Incomplete = ...,
axis1: Incomplete = ...,
Expand Down Expand Up @@ -619,8 +619,19 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
def argpartition(self, *args: Incomplete, **kwargs: Incomplete) -> Incomplete: ...

#
def take(self, indices: Incomplete, axis: Incomplete = ..., out: Incomplete = ..., mode: Incomplete = ...) -> Incomplete: ...
def take( # pyright: ignore[reportIncompatibleMethodOverride]
self,
/,
indices: Incomplete,
axis: Incomplete = ...,
out: Incomplete = ...,
mode: Incomplete = ...,
) -> Incomplete: ...

#
def copy(self, /, order: _OrderKACF = "C") -> Self: ...

#
diagonal: Any
flatten: Any
repeat: Any
Expand Down Expand Up @@ -673,7 +684,7 @@ class MaskedConstant(MaskedArray[tuple[()], np.dtype[np.float64]]):
def __iadd__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
def __isub__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
def __imul__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
def __ifloordiv__(self, other: Incomplete, /) -> Self: ...
def __ifloordiv__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
def __itruediv__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
def __ipow__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]

Expand Down
7 changes: 4 additions & 3 deletions 7 test/runtime/accept/ndarray_shape_manipulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import cast

import numpy as np

nd1 = np.array([[1, 2], [3, 4]])
nd1 = cast("np.ndarray[tuple[int, int], np.dtype[np.intp]]", np.array([[1, 2], [3, 4]]))

# reshape
nd1.reshape(4)
Expand All @@ -12,12 +14,11 @@

# resize
nd1.resize()
nd1.resize(4)
nd1.resize(2, 2)
nd1.resize((2, 2))

nd1.resize((2, 2), refcheck=True)
nd1.resize(4, refcheck=True)
nd1.resize(2, 2, refcheck=True)

nd2 = np.array([[1, 2], [3, 4]])

Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.