-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_pandas.py
More file actions
54 lines (45 loc) · 1.96 KB
/
test_pandas.py
File metadata and controls
54 lines (45 loc) · 1.96 KB
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
import unittest
from matplotlib.axes import Axes
import pandas
from teachpyx.ext_test_case import ExtTestCase
from teachpyx.tools.pandas import plot_waterfall, read_csv_cached
class TestPandas(ExtTestCase):
def test_read_csv_cached(self):
df = read_csv_cached(
"https://github.com/sdpython/teachpyx/raw/main/_data/paris_54000.zip"
)
df2 = read_csv_cached(
"https://github.com/sdpython/teachpyx/raw/main/_data/paris_54000.zip"
)
self.assertEqual(df.shape, df2.shape)
self.assertEqual(list(df.columns), list(df2.columns))
def test_plot_waterfall(self):
df = pandas.DataFrame(
{
"name": ["A", "B", "C"],
"delta": [10, -3, 5],
}
)
ax, plot_df = plot_waterfall(df, "delta", "name", total_label="TOTAL")
self.assertIsInstance(ax, Axes)
self.assertEqual(list(plot_df["label"]), ["A", "B", "C", "TOTAL"])
self.assertEqual(list(plot_df["start"]), [0.0, 10.0, 7.0, 0.0])
self.assertEqual(list(plot_df["end"]), [10.0, 7.0, 12.0, 12.0])
def test_plot_waterfall_missing_column(self):
df = pandas.DataFrame({"name": ["A"], "delta": [1]})
with self.assertRaises(ValueError):
plot_waterfall(df, "missing", "name")
def test_plot_waterfall_missing_label_column(self):
df = pandas.DataFrame({"name": ["A"], "delta": [1]})
with self.assertRaises(ValueError):
plot_waterfall(df, "delta", "missing")
def test_plot_waterfall_bad_colors(self):
df = pandas.DataFrame({"name": ["A"], "delta": [1]})
with self.assertRaises(ValueError):
plot_waterfall(df, "delta", "name", colors=("r",))
def test_plot_waterfall_not_numeric(self):
df = pandas.DataFrame({"name": ["A"], "delta": ["x"]})
with self.assertRaises(ValueError):
plot_waterfall(df, "delta", "name")
if __name__ == "__main__":
unittest.main()