Skip to content

Commit 2a2b1f3

Browse files
committed
Format code by ruff formatter
1 parent 277eeec commit 2a2b1f3

11 files changed

+334
-208
lines changed

Diff for: csaps/__init__.py

-2
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',

Diff for: csaps/_base.py

+5-10
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"""

Diff for: csaps/_reshape.py

+1-1
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

Diff for: csaps/_sspndg.py

+5-7
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

Diff for: csaps/_sspumv.py

+11-13
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:]

Diff for: docs/conf.py

+3-2
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)