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

TYP: Various typing fixes. #29070

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
May 27, 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
2 changes: 1 addition & 1 deletion 2 numpy/_core/defchararray.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def add(x1: S_co, x2: S_co) -> NDArray[np.bytes_]: ...
@overload
def add(x1: _StringDTypeSupportsArray, x2: _StringDTypeSupportsArray) -> _StringDTypeArray: ...
@overload
def add(x1: T_co, T_co) -> _StringDTypeOrUnicodeArray: ...
def add(x1: T_co, x2: T_co) -> _StringDTypeOrUnicodeArray: ...

@overload
def multiply(a: U_co, i: i_co) -> NDArray[np.str_]: ...
Expand Down
15 changes: 15 additions & 0 deletions 15 numpy/_core/strings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ __all__ = [
"translate",
"upper",
"zfill",
"slice",
]

_StringDTypeArray: TypeAlias = np.ndarray[_AnyShape, np.dtypes.StringDType]
Expand Down Expand Up @@ -494,3 +495,17 @@ def translate(
table: str,
deletechars: str | None = None,
) -> _StringDTypeOrUnicodeArray: ...

#
@overload
def slice(a: U_co, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /) -> NDArray[np.str_]: ... # type: ignore[overload-overlap]
@overload
def slice(a: S_co, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /) -> NDArray[np.bytes_]: ...
@overload
def slice(
a: _StringDTypeSupportsArray, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /
) -> _StringDTypeArray: ...
@overload
def slice(
a: T_co, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /
) -> _StringDTypeOrUnicodeArray: ...
4 changes: 1 addition & 3 deletions 4 numpy/lib/_user_array_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from types import EllipsisType
from typing import Any, Generic, Self, SupportsIndex, TypeAlias, overload

from _typeshed import Incomplete
from typing_extensions import TypeVar, deprecated, override
from typing_extensions import TypeVar, override

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -220,8 +220,6 @@ class container(Generic[_ShapeT_co, _DTypeT_co]):

#
def copy(self, /) -> Self: ...
@deprecated("tostring() is deprecated. Use tobytes() instead.")
def tostring(self, /) -> bytes: ...
def tobytes(self, /) -> bytes: ...
def byteswap(self, /) -> Self: ...
def astype(self, /, typecode: _DTypeLike[_ScalarT]) -> container[_ShapeT_co, np.dtype[_ScalarT]]: ...
4 changes: 1 addition & 3 deletions 4 numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from collections.abc import Sequence
from typing import Any, Literal, Self, SupportsIndex, TypeAlias, overload

from _typeshed import Incomplete
from typing_extensions import TypeIs, TypeVar, deprecated
from typing_extensions import TypeIs, TypeVar

import numpy as np
from numpy import (
Expand Down Expand Up @@ -1057,8 +1057,6 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
def toflex(self) -> Incomplete: ...
def torecords(self) -> Incomplete: ...
def tolist(self, fill_value: Incomplete | None = None) -> Incomplete: ...
@deprecated("tostring() is deprecated. Use tobytes() instead.")
def tostring(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override]
def tobytes(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override]
def tofile(self, /, fid: Incomplete, sep: str = "", format: str = "%s") -> Incomplete: ...

Expand Down
2 changes: 2 additions & 0 deletions 2 numpy/strings/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ from numpy._core.strings import (
rjust,
rpartition,
rstrip,
slice,
startswith,
str_len,
strip,
Expand Down Expand Up @@ -92,4 +93,5 @@ __all__ = [
"decode",
"encode",
"translate",
"slice",
]
4 changes: 4 additions & 0 deletions 4 numpy/typing/tests/data/reveal/strings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ assert_type(np.strings.str_len(AR_T), npt.NDArray[np.int_])
assert_type(np.strings.translate(AR_U, ""), npt.NDArray[np.str_])
assert_type(np.strings.translate(AR_S, ""), npt.NDArray[np.bytes_])
assert_type(np.strings.translate(AR_T, ""), AR_T_alias)

assert_type(np.strings.slice(AR_U, 1, 5, 2), npt.NDArray[np.str_])
assert_type(np.strings.slice(AR_S, 1, 5, 2), npt.NDArray[np.bytes_])
assert_type(np.strings.slice(AR_T, 1, 5, 2), AR_T_alias)
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.