Skip to content

Commit b9189f3

Browse files
authored
Merge pull request #12 from espdev/drop-py35
v0.9.0 * Drop support of Python 3.5 * `weights`, `smooth` and `axis` arguments in `csaps` function are keyword-only now * `UnivariateCubicSmoothingSpline` and `MultivariateCubicSmoothingSpline` classes are deprecated and will be removed in 1.0.0 version. Use `CubicSmoothingSpline` instead.
2 parents 40e6179 + 766735f commit b9189f3

18 files changed

Lines changed: 148 additions & 90 deletions

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ language: python
33

44
matrix:
55
include:
6-
- python: "3.5"
7-
env: TOXENV=py35-pytest
86
- python: "3.6"
97
env: TOXENV=py36-pytest
108
- python: "3.7"

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.9.0
4+
5+
* Drop support of Python 3.5
6+
* `weights`, `smooth` and `axis` arguments in `csaps` function are keyword-only now
7+
* `UnivariateCubicSmoothingSpline` and `MultivariateCubicSmoothingSpline` classes are deprecated
8+
and will be removed in 1.0.0 version. Use `CubicSmoothingSpline` instead.
9+
310
## v0.8.0
411

512
* Add `csaps` function that can be used as the main API

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## Installation
1313

14-
Python 3.5 or above is supported.
14+
Python 3.6 or above is supported.
1515

1616
```
1717
pip install -U csaps

csaps/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from csaps._sspumv import (
1515
SplinePPForm,
16+
CubicSmoothingSpline,
1617
UnivariateCubicSmoothingSpline,
1718
MultivariateCubicSmoothingSpline,
1819
)
@@ -38,6 +39,7 @@
3839
'ISmoothingSpline',
3940
'SplinePPForm',
4041
'NdGridSplinePPForm',
42+
'CubicSmoothingSpline',
4143
'UnivariateCubicSmoothingSpline',
4244
'MultivariateCubicSmoothingSpline',
4345
'NdGridCubicSmoothingSpline',

csaps/_base.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import numpy as np
1212

13-
from csaps._types import TData, TProps, TSmooth, TXi, TSpline
13+
from ._types import TData, TProps, TSmooth, TXi, TSpline
1414

1515

1616
class SplinePPFormBase(abc.ABC, ty.Generic[TData, TProps]):
@@ -87,17 +87,15 @@ def evaluate(self, xi: TData) -> np.ndarray:
8787
Interpolated/smoothed data
8888
"""
8989

90-
def __repr__(self):
90+
def __repr__(self): # pragma: no cover
9191
return (
92-
'{}\n'
93-
' breaks: {}\n'
94-
' coeffs: {} shape\n'
95-
' pieces: {}\n'
96-
' order: {}\n'
97-
' ndim: {}\n'
98-
).format(
99-
type(self).__name__, self.breaks, self.coeffs.shape,
100-
self.pieces, self.order, self.ndim)
92+
f'{type(self).__name__}\n'
93+
f' breaks: {self.breaks}\n'
94+
f' coeffs: {self.coeffs.shape} shape\n'
95+
f' pieces: {self.pieces}\n'
96+
f' order: {self.order}\n'
97+
f' ndim: {self.ndim}\n'
98+
)
10199

102100

103101
class ISmoothingSpline(abc.ABC, ty.Generic[TSpline, TSmooth, TXi]):

csaps/_utils.py renamed to csaps/_reshape.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def to_2d(arr: np.ndarray, axis: int) -> np.ndarray:
6464
arr = np.asarray(arr)
6565
axis = arr.ndim + axis if axis < 0 else axis
6666

67-
if axis >= arr.ndim:
68-
raise ValueError('axis {} is out of array axes {}'.format(axis, arr.ndim))
67+
if axis >= arr.ndim: # pragma: no cover
68+
raise ValueError(f'axis {axis} is out of array axes {arr.ndim}')
6969

7070
tr_axes = list(range(arr.ndim))
7171
tr_axes.pop(axis)
@@ -135,8 +135,8 @@ def from_2d(arr: np.ndarray, shape: ty.Sequence[int], axis: int) -> np.ndarray:
135135
ndim = len(shape)
136136
axis = ndim + axis if axis < 0 else axis
137137

138-
if axis >= ndim:
139-
raise ValueError('axis {} is out of N-D array axes {}'.format(axis, ndim))
138+
if axis >= ndim: # pragma: no cover
139+
raise ValueError(f'axis {axis} is out of N-D array axes {ndim}')
140140

141141
new_shape = list(shape)
142142
new_shape.pop(axis)

csaps/_shortcut.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
import numpy as np
1212

13-
from csaps._base import ISmoothingSpline
14-
from csaps._sspumv import UnivariateCubicSmoothingSpline
15-
from csaps._sspndg import ndgrid_prepare_data_sites, NdGridCubicSmoothingSpline
16-
from csaps._types import (
13+
from ._base import ISmoothingSpline
14+
from ._sspumv import CubicSmoothingSpline
15+
from ._sspndg import ndgrid_prepare_data_sites, NdGridCubicSmoothingSpline
16+
from ._types import (
1717
UnivariateDataType,
1818
UnivariateVectorizedDataType,
1919
NdGridDataType,
@@ -25,11 +25,16 @@
2525
_WeightsDataType = Optional[Union[UnivariateDataType, NdGridDataType]]
2626
_SmoothDataType = Optional[Union[float, Sequence[Optional[float]]]]
2727

28-
AutoSmoothingResult = NamedTuple('AutoSmoothingResult', [
29-
('values', _YDataType),
30-
('smooth', _SmoothDataType),
31-
])
32-
"""The result for auto smoothing for `csaps` function"""
28+
29+
class AutoSmoothingResult(NamedTuple):
30+
"""The result for auto smoothing for `csaps` function"""
31+
32+
values: _YDataType
33+
"""Smoothed data values"""
34+
35+
smooth: _SmoothDataType
36+
"""The calculated smoothing parameter"""
37+
3338

3439
_ReturnType = Union[
3540
_YDataType,
@@ -41,6 +46,7 @@
4146
def csaps(xdata: _XDataType,
4247
ydata: _YDataType,
4348
xidata: _XiDataType = None,
49+
*,
4450
weights: _WeightsDataType = None,
4551
smooth: _SmoothDataType = None,
4652
axis: Optional[int] = None) -> _ReturnType:
@@ -105,7 +111,7 @@ def csaps(xdata: _XDataType,
105111
106112
ssp_obj : ISmoothingSpline
107113
Smoothing spline object if ``xidata`` was not set:
108-
- :class:`UnivariateCubicSmoothingSpline` instance for univariate/multivariate data
114+
- :class:`CubicSmoothingSpline` instance for univariate/multivariate data
109115
- :class:`NdGridCubicSmoothingSpline` instance for nd-gridded data
110116
111117
Examples
@@ -134,7 +140,7 @@ def csaps(xdata: _XDataType,
134140
See Also
135141
--------
136142
137-
UnivariateCubicSmoothingSpline
143+
CubicSmoothingSpline
138144
NdGridCubicSmoothingSpline
139145
140146
"""
@@ -151,7 +157,7 @@ def csaps(xdata: _XDataType,
151157

152158
if umv:
153159
axis = -1 if axis is None else axis
154-
sp = UnivariateCubicSmoothingSpline(xdata, ydata, weights, smooth, axis)
160+
sp = CubicSmoothingSpline(xdata, ydata, weights, smooth, axis)
155161
else:
156162
sp = NdGridCubicSmoothingSpline(xdata, ydata, weights, smooth)
157163

csaps/_sspndg.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@
1010

1111
import numpy as np
1212

13-
from csaps._base import SplinePPFormBase, ISmoothingSpline
14-
from csaps._types import UnivariateDataType, NdGridDataType
15-
from csaps._sspumv import SplinePPForm, UnivariateCubicSmoothingSpline
13+
from ._base import SplinePPFormBase, ISmoothingSpline
14+
from ._types import UnivariateDataType, NdGridDataType
15+
from ._sspumv import SplinePPForm, CubicSmoothingSpline
1616

1717

1818
def ndgrid_prepare_data_sites(data, name) -> ty.Tuple[np.ndarray, ...]:
1919
if not isinstance(data, c_abc.Sequence):
20-
raise TypeError("'{}' must be a sequence of the vectors.".format(name))
20+
raise TypeError(f"'{name}' must be a sequence of the vectors.")
2121

2222
data = list(data)
2323

2424
for i, di in enumerate(data):
2525
di = np.array(di, dtype=np.float64)
2626
if di.ndim > 1:
27-
raise ValueError("All '{}' elements must be a vector.".format(name))
27+
raise ValueError(f"All '{name}' elements must be a vector.")
2828
if di.size < 2:
29-
raise ValueError(
30-
"'{}' must contain at least 2 data points.".format(name))
29+
raise ValueError(f"'{name}' must contain at least 2 data points.")
3130
data[i] = di
3231

3332
return tuple(data)
@@ -165,28 +164,24 @@ def _prepare_data(cls, xdata, ydata, weights, smooth):
165164
data_ndim = len(xdata)
166165

167166
if ydata.ndim != data_ndim:
168-
raise ValueError(
169-
'ydata must have dimension {} according to xdata'.format(data_ndim))
167+
raise ValueError(f'ydata must have dimension {data_ndim} according to xdata')
170168

171169
for yd, xs in zip(ydata.shape, map(len, xdata)):
172170
if yd != xs:
173-
raise ValueError(
174-
'ydata ({}) and xdata ({}) dimension size mismatch'.format(yd, xs))
171+
raise ValueError(f'ydata ({yd}) and xdata ({xs}) dimension size mismatch')
175172

176173
if not weights:
177174
weights = [None] * data_ndim
178175
else:
179176
weights = ndgrid_prepare_data_sites(weights, 'weights')
180177

181178
if len(weights) != data_ndim:
182-
raise ValueError(
183-
'weights ({}) and xdata ({}) dimensions mismatch'.format(len(weights), data_ndim))
179+
raise ValueError(f'weights ({len(weights)}) and xdata ({data_ndim}) dimensions mismatch')
184180

185181
for w, x in zip(weights, xdata):
186182
if w is not None:
187183
if w.size != x.size:
188-
raise ValueError(
189-
'weights ({}) and xdata ({}) dimension size mismatch'.format(w, x))
184+
raise ValueError(f'weights ({w}) and xdata ({x}) dimension size mismatch')
190185

191186
if not smooth:
192187
smooth = [None] * data_ndim
@@ -198,8 +193,8 @@ def _prepare_data(cls, xdata, ydata, weights, smooth):
198193

199194
if len(smooth) != data_ndim:
200195
raise ValueError(
201-
'Number of smoothing parameter values must be equal '
202-
'number of dimensions ({})'.format(data_ndim))
196+
f'Number of smoothing parameter values must '
197+
f'be equal number of dimensions ({data_ndim})')
203198

204199
return xdata, ydata, weights, smooth
205200

@@ -208,9 +203,8 @@ def __call__(self, xi: NdGridDataType) -> np.ndarray:
208203
"""
209204
xi = ndgrid_prepare_data_sites(xi, 'xi')
210205

211-
if len(xi) != self._ndim:
212-
raise ValueError(
213-
'xi ({}) and xdata ({}) dimensions mismatch'.format(len(xi), self._ndim))
206+
if len(xi) != self._ndim: # pragma: no cover
207+
raise ValueError(f'xi ({len(xi)}) and xdata ({self._ndim}) dimensions mismatch')
214208

215209
return self._spline.evaluate(xi)
216210

@@ -224,8 +218,8 @@ def _make_spline(self, smooth: ty.List[ty.Optional[float]]) -> ty.Tuple[NdGridSp
224218
shape_i = (np.prod(sizey[:-1]), sizey[-1])
225219
ydata_i = ydata.reshape(shape_i, order='F')
226220

227-
s = UnivariateCubicSmoothingSpline(
228-
self._xdata[i], ydata_i, self._weights[i], smooth[i])
221+
s = CubicSmoothingSpline(
222+
self._xdata[i], ydata_i, weights=self._weights[i], smooth=smooth[i])
229223

230224
_smooth.append(s.smooth)
231225
sizey[-1] = s.spline.pieces * s.spline.order

0 commit comments

Comments
 (0)