8000 TYP: annotate strings.slice · numpy/numpy@3ef41f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ef41f7

Browse files
jorenhamcharris
authored andcommitted
TYP: annotate strings.slice
1 parent 274f1b9 commit 3ef41f7

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

numpy/_core/strings.pyi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ __all__ = [
5454
"translate",
5555
"upper",
5656
"zfill",
57+
"slice",
5758
]
5859

5960
_StringDTypeArray: TypeAlias = np.ndarray[_AnyShape, np.dtypes.StringDType]
@@ -494,3 +495,17 @@ def translate(
494495
table: str,
495496
deletechars: str | None = None,
496497
) -> _StringDTypeOrUnicodeArray: ...
498+
499+
#
500+
@overload
501+
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]
502+
@overload
503+
def slice(a: S_co, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /) -> NDArray[np.bytes_]: ...
504+
@overload
505+
def slice(
506+
a: _StringDTypeSupportsArray, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /
507+
) -> _StringDTypeArray: ...
508+
@overload
509+
def slice(
510+
a: T_co, start: i_co | None = None, stop: i_co | None = None, step: i_co | None = None, /
511+
) -> _StringDTypeOrUnicodeArray: ...

numpy/strings/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from numpy._core.strings import (
3636
rjust,
3737
rpartition,
3838
rstrip,
39+
slice,
3940
startswith,
4041
str_len,
4142
strip,
@@ -92,4 +93,5 @@ __all__ = [
9293
"decode",
9394
"encode",
9495
"translate",
96+
"slice",
9597
]

numpy/typing/tests/data/reveal/strings.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,7 @@ assert_type(np.strings.str_len(AR_T), npt.NDArray[np.int_])
190190
assert_type(np.strings.translate(AR_U, ""), npt.NDArray[np.str_])
191191
assert_type(np.strings.translate(AR_S, ""), npt.NDArray[np.bytes_])
192192
assert_type(np.strings.translate(AR_T, ""), AR_T_alias)
193+
194+
assert_type(np.strings.slice(AR_U, 1, 5, 2), npt.NDArray[np.str_])
195+
assert_type(np.strings.slice(AR_S, 1, 5, 2), npt.NDArray[np.bytes_])
196+
assert_type(np.strings.slice(AR_T, 1, 5, 2), AR_T_alias)

0 commit comments

Comments
 (0)
0