-
Notifications
You must be signed in to change notification settings - Fork 25
/
MultiIndexExploderTest.py
47 lines (39 loc) · 1.93 KB
/
MultiIndexExploderTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import unittest
from pandas.testing import assert_frame_equal
from MultiIndexExploder import MultiIndexExploder
from TestHelper import TestHelper
import pandas as pd
class MultiIndexExploderTest(unittest.TestCase):
def test_explodeMultiIndexOfTable(self):
# Given
table = TestHelper.createDataFrame(
columns = ['DATA', 'COUNTRY'],
data = [ ['A, B data', 'Country A'],
['C, A data', 'Country B'],
['C, B data', 'Country C']],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT1', 'VAX_LOT2'],
tuples = [['A', 'B'],
['C', 'A'],
['C', 'B']]))
# When
explodedTable = MultiIndexExploder.explodeMultiIndexOfTable(table)
# Then
assert_frame_equal(
explodedTable,
TestHelper.createDataFrame(
columns = ['DATA', 'COUNTRY'],
data = [ ['A, B data', 'Country A'],
['A, B data', 'Country A'],
['C, A data', 'Country B'],
['C, A data', 'Country B'],
['C, B data', 'Country C'],
['C, B data', 'Country C']],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT_EXPLODED', 'VAX_LOT1', 'VAX_LOT2'],
tuples = [['A', 'A', 'B'],
['B', 'A', 'B'],
['C', 'C', 'A'],
['A', 'C', 'A'],
['C', 'C', 'B'],
['B', 'C', 'B']])))