Last active
September 7, 2018 11:52
-
-
Save stringfellow/8ae4d3f25ca525e75bb79c01fbda4a24 to your computer and use it in GitHub Desktop.
linear & slinear interpolation of constant data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pandas slinear: [60.0, 60.0, 60.0, 60.0, 59.999999999999993, 60.0, 60.0, 60.0] | |
pandas linear: [60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0] | |
scipy slinear: [60.0, 60.0, 60.0, 60.0, 59.999999999999993, 60.0, 60.0, 60.0] | |
scipy linear: [60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0] | |
F | |
====================================================================== | |
FAIL: Proof that linear and slinear are not equal. | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "....", line 329, in test_slinear_versus_linear | |
self.assertEqual(scipy_y_slinear, scipy_y_linear) | |
AssertionError: Lists differ: [60.0, 60.0, 60.0, 60.0, 59.99... != [60.0, 60.0, 60.0, 60.0, 60.0,... | |
First differing element 4: | |
60.0 | |
60.0 | |
- [60.0, 60.0, 60.0, 60.0, 59.999999999999993, 60.0, 60.0, 60.0] | |
? -------------------- | |
+ [60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0] | |
? ++++++ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import unittest | |
from numpy import nan | |
from pandas import Series, date_range | |
from scipy import interpolate | |
class Tests(unittest.TestCase): | |
def test_slinear_versus_linear(self): | |
"""Proof that linear and slinear are not equal.""" | |
data = [ | |
(27 * 60 + 13, 60), (42 * 60 + 15, 60), | |
(57 * 60 + 17, 60), (60 * 60 + 12 * 60 +13, 60), | |
(60 * 60 + 27 * 60 + 15, 60), (60 * 60 + 60 * 42 + 15, 60), | |
] | |
s1 = Series( | |
data=[x for y, x in data], | |
index=[y for y, x in data] | |
) | |
empties = [30 * 60 * i for i in range(1, 3)] | |
s2 = s1.reindex(s1.index | empties) | |
x = s1.index | |
y = s1.values | |
pandas_y_linear = list(s2.interpolate(method='linear').values) | |
pandas_y_slinear = list(s2.interpolate(method='slinear').values) | |
scipy_y_linear = list( | |
interpolate.interp1d(x, y, kind='linear')(s2.index) | |
) | |
scipy_y_slinear = list( | |
interpolate.interp1d(x, y, kind='slinear')(s2.index) | |
) | |
print "pandas slinear:", pandas_y_slinear | |
print "pandas linear: ", pandas_y_linear | |
print "scipy slinear:", scipy_y_slinear | |
print "scipy linear: ", scipy_y_linear | |
self.assertEqual(scipy_y_slinear, scipy_y_linear) | |
self.assertEqual(pandas_y_slinear, pandas_y_linear) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment