preprocess_test.py 1.47 KB
Newer Older
Lukas Eller's avatar
Lukas Eller committed
1
import unittest
Lukas Eller's avatar
Lukas Eller committed
2 3
import pandas as pd

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

Lukas Eller's avatar
Lukas Eller committed
6 7 8 9 10
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
11

Lukas Eller's avatar
Lukas Eller committed
12 13
        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
14

Lukas Eller's avatar
Lukas Eller committed
15 16 17 18
        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
19

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

Lukas Eller's avatar
Lukas Eller committed
23 24 25 26 27 28 29 30 31
        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,
32
                "Datetime"
Lukas Eller's avatar
Lukas Eller committed
33 34 35 36 37 38 39
            )

    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'])

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

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

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