Repository: espdev/csaps

Issue:
results of UnivariateCubicSmoothingSpline for smooth = 0
@espdev Thank you for writing this library. it is awesome and very useful. I noticed that when I use UnivariateCubicSmoothingSpline with smooth = 0,  I don't get a straight line, instead, it does "auto smooth".

using the example you gave with smooth = 0 I get:
![image](https://user-images.githubusercontent.com/32917209/58765859-1e01cb00-852c-11e9-914d-ef9cb454ebfe.png)

what I expected to get is the following:
![image](https://user-images.githubusercontent.com/32917209/58765836-e3982e00-852b-11e9-9f22-7e2c0ea624ca.png)

I believe the root cause for this is that the following if statement in the code would be false for  self._smooth = 0:
`if self._smooth:`
`                p = self._smooth`
` else:`
`                 p = self._compute_smooth(r, qtwq)`

proposed correction:
`if (self._smooth or self._smooth==0):`
`                p = self._smooth`
` else:`
`                 p = self._compute_smooth(r, qtwq)`



Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..d405cbf
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,7 @@
+# v0.4.2
+
+* FIX: "smooth" value is 0.0 was not used
+
+# v0.4.1
+
+* First PyPI release
diff --git a/csaps.py b/csaps.py
index c838584..e5d82e2 100644
--- a/csaps.py
+++ b/csaps.py
@@ -281,10 +281,10 @@ class UnivariateCubicSmoothingSpline:
             # Solve linear system for the 2nd derivatives
             qtwq = qtw @ qtw.T
 
-            if self._smooth:
-                p = self._smooth
-            else:
+            if self._smooth is None:
                 p = self._compute_smooth(r, qtwq)
+            else:
+                p = self._smooth
 
             a = (6. * (1. - p)) * qtwq + p * r
             b = np.diff(divdydx, axis=self._axis).T
diff --git a/setup.py b/setup.py
index 34d524a..b2f82e4 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ from setuptools import setup
 
 
 NAME = 'csaps'
-VERSION = '0.4.1'
+VERSION = '0.4.2'
 ROOT_DIR = pathlib.Path(__file__).parent
 
 


Test patch:
diff --git a/tests/test_csaps.py b/tests/test_csaps.py
index 61172dc..7eb3260 100644
--- a/tests/test_csaps.py
+++ b/tests/test_csaps.py
@@ -252,5 +252,21 @@ def test_surface_smoothing():
     _ = sp(xdata)
 
 
+def test_zero_smooth():
+    x = [1., 2., 4., 6.]
+    y = [2., 4., 5., 7.]
+
+    sp = csaps.UnivariateCubicSmoothingSpline(x, y, smooth=0.)
+
+    assert sp.smooth == pytest.approx(0.)
+
+    ys = sp(x)
+
+    assert ys == pytest.approx([2.440677966101695,
+                                3.355932203389830,
+                                5.186440677966102,
+                                7.016949152542373])
+
+
 if __name__ == '__main__':
     pytest.main()