preprocess_test.py 1.48 KB
Newer Older
Lukas Eller's avatar
Lukas Eller committed
1
import unittest
2

Lukas Eller's avatar
Lukas Eller committed
3 4
import pandas as pd

Lukas Eller's avatar
Lukas Eller committed
5 6
from context import measprocess as mpc

7

Lukas Eller's avatar
Lukas Eller committed
8 9 10 11 12
class TestLinkFrames(unittest.TestCase):
    def setUp(self):
        #Init the Dummy Example
        A = pd.DataFrame({'ref':[10,20,30, 31, 5], 'info': [5, 4, 1, 2, 1]})
        A.index = range(2, 7)
Lukas Eller's avatar
Lukas Eller committed
13

Lukas Eller's avatar
Lukas Eller committed
14 15
        B = pd.DataFrame({'ref':[15,17,27, 4], 'info': [1, 2, 3, 4], 'yo': [4, 6, 1, 8]})
        B.index = range(9, 13)
Lukas Eller's avatar
Lukas Eller committed
16

Lukas Eller's avatar
Lukas Eller committed
17 18 19 20
        self._A, self._B = A, B

        self._meas = pd.read_csv("tests/example_files/scanner_1/measurement_example.csv", index_col=0)
        self._gps = pd.read_csv("tests/example_files/scanner_1/gps_example.csv", index_col=0)
Lukas Eller's avatar
Lukas Eller committed
21

Lukas Eller's avatar
Lukas Eller committed
22
    def test_multiindex_dummy(self):
23
        combined, _ = mpc.preprocess.link_dataframes(self._A, self._B, ref_col="ref")
Lukas Eller's avatar
Lukas Eller committed
24

Lukas Eller's avatar
Lukas Eller committed
25 26 27 28 29 30 31 32 33
        self.assertTrue(
            all(self._A == combined['A'])
        )

    def test_real_numeric_type(self):
        with self.assertRaises(ValueError):
            combined = mpc.preprocess.link_dataframes(
                self._meas,
                self._gps,
34
                "Datetime"
Lukas Eller's avatar
Lukas Eller committed
35 36 37 38 39 40 41
            )

    def test_multiindex_real(self):
        meas, gps = self._meas, self._gps
        meas['Datetime'] = pd.to_datetime(meas['Datetime'])
        gps['Datetime'] = pd.to_datetime(gps['Datetime'])

42
        combined, _ = mpc.preprocess.link_dataframes(
Lukas Eller's avatar
Lukas Eller committed
43 44
            meas,
            gps,
45
            "Datetime"
Lukas Eller's avatar
Lukas Eller committed
46
        )
Lukas Eller's avatar
Lukas Eller committed
47

Lukas Eller's avatar
Lukas Eller committed
48 49 50
        self.assertTrue(
            all(meas == combined['A'])
        )
Lukas Eller's avatar
Lukas Eller committed
51 52 53

if __name__ == '__main__':
    unittest.main()