Skip to content

Commit c7998c2

Browse files
committed
TYP: Add type tests for the numpy.polynomial series-specific methods
1 parent dc68125 commit c7998c2

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

numpy/polynomial/chebyshev.pyi

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def _zseries_to_cseries(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
8686
def _zseries_mul(
8787
z1: npt.NDArray[_SCT],
8888
z2: npt.NDArray[_SCT],
89-
) -> _Series[_SCT]: ...
89+
) -> _Series[_SCT]: ...
9090
def _zseries_div(
9191
z1: npt.NDArray[_SCT],
9292
z2: npt.NDArray[_SCT],
93-
) -> _Series[_SCT]: ...
93+
) -> _Series[_SCT]: ...
9494
def _zseries_der(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
9595
def _zseries_int(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
9696

@@ -130,27 +130,25 @@ chebpts1: _FuncPts[L["chebpts1"]]
130130
chebpts2: _FuncPts[L["chebpts2"]]
131131

132132
# keep in sync with `Chebyshev.interpolate`
133-
_RT = TypeVar(
134-
"_RT",
135-
np.float64,
136-
np.complex128,
137-
np.floating[Any],
138-
np.complexfloating[Any, Any],
139-
np.number[Any],
140-
np.object_,
141-
)
133+
_RT = TypeVar("_RT", bound=np.number[Any] | np.bool | np.object_)
134+
@overload
135+
def chebinterpolate(
136+
func: np.ufunc,
137+
deg: _IntLike_co,
138+
args: tuple[()] = ...,
139+
) -> npt.NDArray[np.float64 | np.complex128 | np.object_]: ...
142140
@overload
143141
def chebinterpolate(
144142
func: Callable[[npt.NDArray[np.float64]], _RT],
145143
deg: _IntLike_co,
146144
args: tuple[()] = ...,
147-
) -> npt.NDArray[_RT]: ...
145+
) -> npt.NDArray[_RT]: ...
148146
@overload
149147
def chebinterpolate(
150148
func: Callable[Concatenate[npt.NDArray[np.float64], ...], _RT],
151149
deg: _IntLike_co,
152150
args: Iterable[Any],
153-
) -> npt.NDArray[_RT]: ...
151+
) -> npt.NDArray[_RT]: ...
154152

155153
_Self = TypeVar("_Self", bound=object)
156154

@@ -164,7 +162,7 @@ class Chebyshev(ABCPolyBase[L["T"]]):
164162
deg: _IntLike_co,
165163
domain: None | _SeriesLikeCoef_co = ...,
166164
args: tuple[()] = ...,
167-
) -> _Self: ...
165+
) -> _Self: ...
168166
@overload
169167
@classmethod
170168
def interpolate(
@@ -178,7 +176,7 @@ class Chebyshev(ABCPolyBase[L["T"]]):
178176
domain: None | _SeriesLikeCoef_co = ...,
179177
*,
180178
args: Iterable[Any],
181-
) -> _Self: ...
179+
) -> _Self: ...
182180
@overload
183181
@classmethod
184182
def interpolate(
@@ -191,4 +189,4 @@ class Chebyshev(ABCPolyBase[L["T"]]):
191189
domain: None | _SeriesLikeCoef_co,
192190
args: Iterable[Any],
193191
/,
194-
) -> _Self: ...
192+
) -> _Self: ...

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ AR_c16: npt.NDArray[np.complex128]
2525
AR_O: npt.NDArray[np.object_]
2626

2727
PS_poly: npp.Polynomial
28+
PS_cheb: npp.Chebyshev
2829

2930
assert_type(npp.polynomial.polyroots(AR_f8), _ArrFloat1D64)
3031
assert_type(npp.polynomial.polyroots(AR_c16), _ArrComplex1D128)
@@ -119,3 +120,25 @@ assert_type(
119120
npp.polynomial.polyfit(AR_f8, AR_c16, 1, full=True)[0],
120121
npt.NDArray[np.complexfloating[Any, Any]],
121122
)
123+
124+
assert_type(npp.chebyshev.chebgauss(2), tuple[_ArrFloat1D64, _ArrFloat1D64])
125+
126+
assert_type(npp.chebyshev.chebweight(AR_f8), npt.NDArray[np.float64])
127+
assert_type(npp.chebyshev.chebweight(AR_c16), npt.NDArray[np.complex128])
128+
assert_type(npp.chebyshev.chebweight(AR_O), npt.NDArray[np.object_])
129+
130+
assert_type(npp.chebyshev.poly2cheb(AR_f8), _ArrFloat1D)
131+
assert_type(npp.chebyshev.poly2cheb(AR_c16), _ArrComplex1D)
132+
assert_type(npp.chebyshev.poly2cheb(AR_O), _ArrObject1D)
133+
134+
assert_type(npp.chebyshev.cheb2poly(AR_f8), _ArrFloat1D)
135+
assert_type(npp.chebyshev.cheb2poly(AR_c16), _ArrComplex1D)
136+
assert_type(npp.chebyshev.cheb2poly(AR_O), _ArrObject1D)
137+
138+
assert_type(npp.chebyshev.chebpts1(6), _ArrFloat1D64)
139+
assert_type(npp.chebyshev.chebpts2(6), _ArrFloat1D64)
140+
141+
assert_type(
142+
npp.chebyshev.chebinterpolate(np.tanh, 3),
143+
npt.NDArray[np.float64 | np.complex128 | np.object_],
144+
)

0 commit comments

Comments
 (0)