Skip to content

Commit 97c7671

Browse files
authored
Merge pull request #83 from espdev/update-packaging
Update packaging
2 parents 681fc82 + 6b15559 commit 97c7671

File tree

16 files changed

+1096
-914
lines changed

16 files changed

+1096
-914
lines changed

.github/workflows/main.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jobs:
1313
max-parallel: 8
1414
matrix:
1515
platform: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
16-
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
17-
poetry-version: [ "1.7.1" ]
16+
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
17+
poetry-version: [ "1.8.3" ]
1818

1919
steps:
2020
- name: Checkout project
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Setup Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v4
24+
uses: actions/setup-python@v5
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

2828
- name: Install Poetry ${{ matrix.poetry-version }}
29-
uses: abatilo/actions-poetry@v2
29+
uses: abatilo/actions-poetry@v3
3030
with:
3131
poetry-version: ${{ matrix.poetry-version }}
3232

@@ -36,7 +36,7 @@ jobs:
3636
poetry config virtualenvs.in-project true --local
3737
3838
- name: Define a cache for the virtual environment based on the dependencies lock file
39-
uses: actions/cache@v3
39+
uses: actions/cache@v4
4040
with:
4141
path: ./.venv
4242
key: venv-${{ hashFiles('poetry.lock') }}
@@ -47,7 +47,6 @@ jobs:
4747
- name: Run static analysis and linters
4848
run: |
4949
poetry run ruff check .
50-
poetry run isort -c .
5150
5251
- name: Run tests
5352
run: poetry run pytest -v --color=yes --cov=csaps --cov-report=term --cov-report=lcov:coverage.info

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
4+
repos:
5+
- repo: local
6+
hooks:
7+
- id: ruff
8+
name: ruff
9+
entry: poetry run ruff check
10+
language: system
11+
types: [python]
12+
require_serial: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Use pip for installing:
2222
pip install -U csaps
2323
```
2424

25-
The module depends only on NumPy and SciPy. Python 3.6 or above is supported.
25+
The module depends only on NumPy and SciPy. Python 3.9 or above is supported.
2626

2727
## Simple Examples
2828

csaps/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
# Shortcut
1414
'csaps',
1515
'AutoSmoothingResult',
16-
1716
# Classes
1817
'ISplinePPForm',
1918
'ISmoothingSpline',
2019
'SplinePPForm',
2120
'NdGridSplinePPForm',
2221
'CubicSmoothingSpline',
2322
'NdGridCubicSmoothingSpline',
24-
2523
# Type-hints
2624
'UnivariateDataType',
2725
'MultivariateDataType',

csaps/_base.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212

1313
class ISplinePPForm(abc.ABC, Generic[TData, TProps]):
14-
"""The interface class for spline representation in PP-form
15-
"""
14+
"""The interface class for spline representation in PP-form"""
1615

1716
__module__ = 'csaps'
1817

@@ -84,24 +83,20 @@ def shape(self) -> Tuple[int, ...]:
8483

8584

8685
class ISmoothingSpline(abc.ABC, Generic[TSpline, TSmooth, TXi, TNu, TExtrapolate]):
87-
"""The interface class for smooting splines
88-
"""
86+
"""The interface class for smooting splines"""
8987

9088
__module__ = 'csaps'
9189

9290
@property
9391
@abc.abstractmethod
9492
def smooth(self) -> TSmooth:
95-
"""Returns smoothing factor(s)
96-
"""
93+
"""Returns smoothing factor(s)"""
9794

9895
@property
9996
@abc.abstractmethod
10097
def spline(self) -> TSpline:
101-
"""Returns spline representation in PP-form
102-
"""
98+
"""Returns spline representation in PP-form"""
10399

104100
@abc.abstractmethod
105101
def __call__(self, xi: TXi, nu: Optional[TNu] = None, extrapolate: Optional[TExtrapolate] = None) -> np.ndarray:
106-
"""Evaluates spline on the data sites
107-
"""
102+
"""Evaluates spline on the data sites"""

csaps/_reshape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def umv_coeffs_to_flatten(arr: np.ndarray):
150150
strides = arr.strides[:-3:-1]
151151
arr_view = as_strided(arr, shape=shape, strides=strides)
152152
else: # pragma: no cover
153-
raise ValueError(f"The array ndim must be 2 or 3, but given array has ndim={arr.ndim}.")
153+
raise ValueError(f'The array ndim must be 2 or 3, but given array has ndim={arr.ndim}.')
154154

155155
return arr_view
156156

csaps/_sspndg.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def coeffs(self) -> np.ndarray:
6262

6363
@property
6464
def order(self) -> Tuple[int, ...]:
65-
return self.c.shape[:self.c.ndim // 2]
65+
return self.c.shape[: self.c.ndim // 2]
6666

6767
@property
6868
def pieces(self) -> Tuple[int, ...]:
69-
return self.c.shape[self.c.ndim // 2:]
69+
return self.c.shape[self.c.ndim // 2 :]
7070

7171
@property
7272
def ndim(self) -> int:
@@ -112,7 +112,7 @@ def __call__(
112112
raise ValueError(f"'x' sequence must have length {self.ndim} according to 'breaks'")
113113

114114
if nu is None:
115-
nu = (0, ) * len(x)
115+
nu = (0,) * len(x)
116116

117117
if extrapolate is None:
118118
extrapolate = True
@@ -210,7 +210,6 @@ def __init__(
210210
smooth: Optional[Union[float, Sequence[Optional[float]]]] = None,
211211
normalizedsmooth: bool = False,
212212
) -> None:
213-
214213
x, y, w, s = self._prepare_data(xdata, ydata, weights, smooth)
215214
coeffs, smooth = self._make_spline(x, y, w, s, normalizedsmooth)
216215

@@ -306,8 +305,7 @@ def _prepare_data(cls, xdata, ydata, weights, smooth):
306305

307306
if len(smooth) != data_ndim:
308307
raise ValueError(
309-
'Number of smoothing parameter values must '
310-
f'be equal number of dimensions ({data_ndim})'
308+
'Number of smoothing parameter values must ' f'be equal number of dimensions ({data_ndim})'
311309
)
312310

313311
return xdata, ydata, weights, smooth
@@ -324,7 +322,7 @@ def _make_spline(xdata, ydata, weights, smooth, normalizedsmooth):
324322
smooth=smooth[0],
325323
normalizedsmooth=normalizedsmooth,
326324
)
327-
return s.spline.coeffs, (s.smooth, )
325+
return s.spline.coeffs, (s.smooth,)
328326

329327
shape = ydata.shape
330328
coeffs = ydata

csaps/_sspumv.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def ndim(self) -> int:
5858

5959
@property
6060
def shape(self) -> Tuple[int, ...]:
61-
"""Returns the source data shape
62-
"""
61+
"""Returns the source data shape"""
6362
shape: List[int] = list(self.c.shape[2:])
6463
shape.insert(self.axis, self.c.shape[1] + 1)
6564

@@ -124,7 +123,6 @@ def __init__(
124123
axis: int = -1,
125124
normalizedsmooth: bool = False,
126125
):
127-
128126
x, y, w, shape, axis = self._prepare_data(xdata, ydata, weights, axis)
129127
coeffs, smooth = self._make_spline(x, y, w, smooth, shape, normalizedsmooth)
130128
spline = SplinePPForm.construct_fast(coeffs, x, axis=axis)
@@ -236,7 +234,7 @@ def _compute_smooth(a, b):
236234
def trace(m: sp.dia_matrix):
237235
return m.diagonal().sum()
238236

239-
return 1. / (1. + trace(a) / (6. * trace(b)))
237+
return 1.0 / (1.0 + trace(a) / (6.0 * trace(b)))
240238

241239
@staticmethod
242240
def _normalize_smooth(x: np.ndarray, w: np.ndarray, smooth: Optional[float]):
@@ -246,8 +244,8 @@ def _normalize_smooth(x: np.ndarray, w: np.ndarray, smooth: Optional[float]):
246244

247245
span = np.ptp(x)
248246

249-
eff_x = 1 + (span**2) / np.sum(np.diff(x)**2)
250-
eff_w = np.sum(w)**2 / np.sum(w**2)
247+
eff_x = 1 + (span**2) / np.sum(np.diff(x) ** 2)
248+
eff_w = np.sum(w) ** 2 / np.sum(w**2)
251249
k = 80 * (span**3) * (x.size**-2) * (eff_x**-0.5) * (eff_w**-0.5)
252250

253251
s = 0.5 if smooth is None else smooth
@@ -281,11 +279,11 @@ def _make_spline(x, y, w, smooth, shape, normalizedsmooth):
281279
diags_r = np.vstack((dx[1:], 2 * (dx[1:] + dx[:-1]), dx[:-1]))
282280
r = sp.spdiags(diags_r, [-1, 0, 1], pcount - 2, pcount - 2)
283281

284-
dx_recip = 1. / dx
282+
dx_recip = 1.0 / dx
285283
diags_qtw = np.vstack((dx_recip[:-1], -(dx_recip[1:] + dx_recip[:-1]), dx_recip[1:]))
286-
diags_sqrw_recip = 1. / np.sqrt(w)
284+
diags_sqrw_recip = 1.0 / np.sqrt(w)
287285

288-
qtw = (sp.diags(diags_qtw, [0, 1, 2], (pcount - 2, pcount)) @ sp.diags(diags_sqrw_recip, 0, (pcount, pcount)))
286+
qtw = sp.diags(diags_qtw, [0, 1, 2], (pcount - 2, pcount)) @ sp.diags(diags_sqrw_recip, 0, (pcount, pcount))
289287
qtw = qtw @ qtw.T
290288

291289
p = smooth
@@ -295,7 +293,7 @@ def _make_spline(x, y, w, smooth, shape, normalizedsmooth):
295293
elif smooth is None:
296294
p = CubicSmoothingSpline._compute_smooth(r, qtw)
297295

298-
pp = (6. * (1. - p))
296+
pp = 6.0 * (1.0 - p)
299297

300298
# Solve linear system for the 2nd derivatives
301299
a = pp * qtw + p * r
@@ -314,15 +312,15 @@ def _make_spline(x, y, w, smooth, shape, normalizedsmooth):
314312
d1 = np.diff(vpad(u), axis=0) / dx
315313
d2 = np.diff(vpad(d1), axis=0)
316314

317-
diags_w_recip = 1. / w
315+
diags_w_recip = 1.0 / w
318316
w = sp.diags(diags_w_recip, 0, (pcount, pcount))
319317

320318
yi = y.T - (pp * w) @ d2
321319
pu = vpad(p * u)
322320

323321
c1 = np.diff(pu, axis=0) / dx
324-
c2 = 3. * pu[:-1, :]
325-
c3 = np.diff(yi, axis=0) / dx - dx * (2. * pu[:-1, :] + pu[1:, :])
322+
c2 = 3.0 * pu[:-1, :]
323+
c3 = np.diff(yi, axis=0) / dx - dx * (2.0 * pu[:-1, :] + pu[1:, :])
326324
c4 = yi[:-1, :]
327325

328326
c_shape = (4, pcount - 1) + shape[1:]

docs/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
def _get_version():
2727
from csaps import __version__
28+
2829
return __version__
2930

3031

@@ -54,10 +55,10 @@ def _get_version():
5455
'figure.autolayout': 'True',
5556
'figure.figsize': '5, 3.5',
5657
'savefig.bbox': 'tight',
57-
'savefig.facecolor': "None",
58+
'savefig.facecolor': 'None',
5859
}
5960

60-
plot_formats = [("png", 90)]
61+
plot_formats = [('png', 90)]
6162
plot_include_source = True
6263
plot_html_show_source_link = False
6364
plot_html_show_formats = False

0 commit comments

Comments
 (0)