|
1 | 1 | """Tests for the index plot module.""" |
2 | 2 |
|
| 3 | +import ibis |
3 | 4 | import matplotlib.pyplot as plt |
4 | 5 | import numpy as np |
5 | 6 | import pandas as pd |
|
8 | 9 | from pyretailscience.plots.index import get_indexes, plot |
9 | 10 |
|
10 | 11 | OFFSET_VALUE = 100 |
11 | | -OFFSET_THRESHOLD = -5 |
| 12 | +OFFSET_THRESHOLD = 5 |
12 | 13 |
|
13 | 14 |
|
14 | 15 | def test_get_indexes_basic(): |
@@ -109,14 +110,14 @@ def test_get_indexes_with_offset(): |
109 | 110 | index_col="category", |
110 | 111 | value_col="value", |
111 | 112 | group_col="category", |
112 | | - offset=5, |
| 113 | + offset=OFFSET_THRESHOLD, |
113 | 114 | ) |
114 | 115 |
|
115 | 116 | assert isinstance(result, pd.DataFrame) |
116 | 117 | assert "category" in result.columns |
117 | 118 | assert "index" in result.columns |
118 | 119 | assert not result.empty |
119 | | - assert all(result["index"] >= OFFSET_THRESHOLD) |
| 120 | + assert all(result["index"] >= -OFFSET_THRESHOLD) |
120 | 121 |
|
121 | 122 |
|
122 | 123 | def test_get_indexes_single_column(): |
@@ -168,6 +169,23 @@ def test_get_indexes_two_columns(): |
168 | 169 | pd.testing.assert_frame_equal(output, expected_output) |
169 | 170 |
|
170 | 171 |
|
| 172 | +def test_get_indexes_with_ibis_table_input(): |
| 173 | + """Test that the get_indexes function works with an ibis Table.""" |
| 174 | + df = pd.DataFrame( |
| 175 | + { |
| 176 | + "category": ["A", "B", "C"], |
| 177 | + "value": [10, 20, 30], |
| 178 | + }, |
| 179 | + ) |
| 180 | + table = ibis.memtable(df) |
| 181 | + |
| 182 | + result = get_indexes(table, value_to_index="A", index_col="category", value_col="value", group_col="category") |
| 183 | + assert isinstance(result, pd.DataFrame) |
| 184 | + assert "category" in result.columns |
| 185 | + assert "index" in result.columns |
| 186 | + assert not result.empty |
| 187 | + |
| 188 | + |
171 | 189 | class TestIndexPlot: |
172 | 190 | """Tests for the index_plot function.""" |
173 | 191 |
|
|
0 commit comments