22ND-Gridded cubic smoothing spline implementation
33"""
44
5- from typing import Optional , Sequence , Tuple , Union , cast
6- import collections .abc as c_abc
5+ from typing import Optional , Sequence , cast
76
87import numpy as np
98from scipy .interpolate import NdPPoly , PPoly
@@ -24,8 +23,8 @@ def ndgrid_prepare_data_vectors(
2423 data : SequenceUnivariateDataType ,
2524 name : str ,
2625 min_size : int = 2 ,
27- ) -> Tuple [Float1DArrayTupe , ...]:
28- if not isinstance (data , c_abc . Sequence ):
26+ ) -> tuple [Float1DArrayTupe , ...]:
27+ if not isinstance (data , Sequence ):
2928 raise TypeError (f"'{ name } ' must be a sequence of 1-d array-like (vectors) or scalars." )
3029
3130 data_ : list [Float1DArrayTupe ] = []
@@ -41,7 +40,7 @@ def ndgrid_prepare_data_vectors(
4140 return tuple (data_ )
4241
4342
44- class NdGridSplinePPForm (ISplinePPForm [Tuple [np .ndarray , ...], Tuple [int , ...]], NdPPoly ):
43+ class NdGridSplinePPForm (ISplinePPForm [tuple [np .ndarray , ...], tuple [int , ...]], NdPPoly ):
4544 """N-D grid spline representation in PP-form
4645
4746 N-D grid spline is represented in piecewise tensor product polynomial form.
@@ -56,33 +55,33 @@ class NdGridSplinePPForm(ISplinePPForm[Tuple[np.ndarray, ...], Tuple[int, ...]],
5655 __module__ = 'csaps'
5756
5857 @property
59- def breaks (self ) -> Tuple [np .ndarray , ...]:
58+ def breaks (self ) -> tuple [np .ndarray , ...]:
6059 return self .x
6160
6261 @property
6362 def coeffs (self ) -> np .ndarray :
6463 return self .c
6564
6665 @property
67- def order (self ) -> Tuple [int , ...]:
66+ def order (self ) -> tuple [int , ...]:
6867 return self .c .shape [: self .c .ndim // 2 ]
6968
7069 @property
71- def pieces (self ) -> Tuple [int , ...]:
70+ def pieces (self ) -> tuple [int , ...]:
7271 return self .c .shape [self .c .ndim // 2 :]
7372
7473 @property
7574 def ndim (self ) -> int :
7675 return len (self .x )
7776
7877 @property
79- def shape (self ) -> Tuple [int , ...]:
78+ def shape (self ) -> tuple [int , ...]:
8079 return tuple (len (xi ) for xi in self .x )
8180
8281 def __call__ ( # type: ignore[override]
8382 self ,
8483 x : SequenceUnivariateDataType ,
85- nu : Optional [Tuple [int , ...]] = None ,
84+ nu : Optional [tuple [int , ...]] = None ,
8685 extrapolate : Optional [bool ] = None ,
8786 ) -> np .ndarray :
8887 """Evaluate the spline for given data
@@ -160,9 +159,9 @@ def __repr__(self): # pragma: no cover
160159class NdGridCubicSmoothingSpline (
161160 ISmoothingSpline [
162161 NdGridSplinePPForm ,
163- Tuple [float , ...],
162+ tuple [float , ...],
164163 SequenceUnivariateDataType ,
165- Tuple [int , ...],
164+ tuple [int , ...],
166165 bool ,
167166 ]
168167):
@@ -209,8 +208,8 @@ def __init__(
209208 self ,
210209 xdata : SequenceUnivariateDataType ,
211210 ydata : np .ndarray ,
212- weights : Optional [ SequenceUnivariateDataType ] = None ,
213- smooth : Optional [ Union [ float , Sequence [Optional [ float ]]]] = None ,
211+ weights : SequenceUnivariateDataType | None = None ,
212+ smooth : float | Sequence [float | None ] | None = None ,
214213 normalizedsmooth : bool = False ,
215214 ) -> None :
216215 x , y , w , s = self ._prepare_data (xdata , ydata , weights , smooth )
@@ -220,8 +219,8 @@ def __init__(
220219 def __call__ (
221220 self ,
222221 x : SequenceUnivariateDataType ,
223- nu : Optional [ Tuple [ int , ...]] = None ,
224- extrapolate : Optional [ bool ] = None ,
222+ nu : tuple [ int , ...] | None = None ,
223+ extrapolate : bool | None = None ,
225224 ) -> FloatNDArrayType :
226225 """Evaluate the spline for given data
227226
@@ -249,12 +248,12 @@ def __call__(
249248 return self ._spline (x , nu = nu , extrapolate = extrapolate )
250249
251250 @property
252- def smooth (self ) -> Tuple [float , ...]:
251+ def smooth (self ) -> tuple [float , ...]:
253252 """Returns a tuple of smoothing parameters for each axis
254253
255254 Returns
256255 -------
257- smooth : Tuple [float, ...]
256+ smooth : tuple [float, ...]
258257 The smoothing parameter in the range ``[0, 1]`` for each axis
259258 """
260259 return self ._smooth
@@ -299,7 +298,7 @@ def _prepare_data(cls, xdata, ydata, weights, smooth):
299298 if smooth is None :
300299 smooth = [None ] * data_ndim
301300
302- if not isinstance (smooth , c_abc . Sequence ):
301+ if not isinstance (smooth , Sequence ):
303302 smooth = [float (smooth )] * data_ndim
304303 else :
305304 smooth = list (smooth )
0 commit comments