-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_construction_functions.py
54 lines (35 loc) · 1.27 KB
/
test_construction_functions.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
48
49
50
51
52
53
import sys
import os
import pandas as pd
# import pytest
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from pkg.construction_functions import remove_blanks, convert_to_float
def test_blank_removal():
data = {
'name': ['Alice', None, 'Charlie', None, 'Emma'],
'age': [25, 30, 35, 40, 45]}
df = pd.DataFrame(data)
expected = {
'name': ['Alice','Charlie','Emma'],
'age': [25,35,45]
}
df_expected = pd.DataFrame(expected)
#need to pass the column as a list bc of the axis=1 part of the function
blanks_df = remove_blanks(df, ['name'])
blanks_df = blanks_df.reset_index(drop=True)
assert blanks_df.equals(df_expected)
#this test passed
def test_converting_float():
data_input = {
'name': ['Alice', None, 'Charlie', None, 'Emma'],
'age': ['25', '30', '35', '40', '45']}
df = pd.DataFrame(data_input)
expected_output = {
'name': ['Alice', None, 'Charlie', None, 'Emma'],
'age': [25.0, 30.0, 35.0, 40.0, 45.0]
}
df_expected_out = pd.DataFrame(expected_output)
float_df = convert_to_float(df,['age'])
float_df = float_df.reset_index(drop=True)
assert float_df.equals(df_expected_out)
#this test passed