-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_dataframe.py
101 lines (96 loc) · 2.45 KB
/
test_dataframe.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""Tests of the dataframe module"""
import pandas as pd
from bokeh.models.widgets.tables import NumberFormatter
from awesome_panel_extensions.widgets import dataframe
def test_get_default_formatters():
"""We test that formatters for int, float and str are as expected"""
# Given
data = pd.DataFrame(
{
"int": [
1,
2,
3000,
],
"float": [
3.14,
6.28,
9000.42,
],
"str": [
"A",
"B",
"C",
],
},
index=[
1,
2,
3,
],
)
assert not data.index.name
# When
actual = dataframe.get_default_formatters(data)
# Then
assert isinstance(
actual["int"],
NumberFormatter,
)
assert actual["int"].format == dataframe.INT_FORMAT
assert actual["int"].text_align == dataframe.INT_ALIGN
assert isinstance(
actual["float"],
NumberFormatter,
)
assert actual["float"].format == dataframe.FLOAT_FORMAT
assert actual["float"].text_align == dataframe.FLOAT_ALIGN
assert "str" not in actual
assert data.index.name == "index"
assert actual["index"].format == dataframe.INT_FORMAT
assert actual["index"].text_align == dataframe.INT_ALIGN
def test_get_default_formatters_multi_level_index():
"""We test that formatters for int, float and str are as expected"""
# Given
data = pd.DataFrame(
{
"int": [
1,
2,
3000,
],
"float": [
3.14,
6.28,
9000.42,
],
"str": [
"A",
"B",
"C",
],
},
)
data = data.set_index(
[
"int",
"float",
]
)
# When
actual = dataframe.get_default_formatters(data)
# Then
print(actual)
assert isinstance(
actual["int"],
NumberFormatter,
)
assert actual["int"].format == dataframe.INT_FORMAT
assert actual["int"].text_align == dataframe.INT_ALIGN
assert isinstance(
actual["float"],
NumberFormatter,
)
assert actual["float"].format == dataframe.FLOAT_FORMAT
assert actual["float"].text_align == dataframe.FLOAT_ALIGN
assert "str" not in actual