|
| 1 | + |
| 2 | +import pandas as pd |
| 3 | +import pytest |
| 4 | + |
| 5 | +from toolkit.data_processing import buffdescribe |
| 6 | +from toolkit.data_analysis import * |
| 7 | +from toolkit.machine_learning import * |
| 8 | +from toolkit.plot import * |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | + |
| 12 | +def test_df(): |
| 13 | + return pd.DataFrame({'a': [1, 2, 3], 'b': ['x', 'y', 'z'], 'c': [4.5, 6.7, 8.9]}) |
| 14 | + |
| 15 | +def test_buffdescribe_columns(test_df): |
| 16 | + result = buffdescribe(test_df) |
| 17 | + assert result.index.tolist() == ['a', 'b', 'c'] |
| 18 | + |
| 19 | +def test_buffdescribe_data_type(test_df): |
| 20 | + result = buffdescribe(test_df) |
| 21 | + assert result['DATA_TYPE'].tolist() == ['int64', 'object', 'float64'] |
| 22 | + |
| 23 | +def test_buffdescribe_null_values(test_df): |
| 24 | + result = buffdescribe(test_df) |
| 25 | + assert result['MISSINGS (%)'].tolist() == [0.0, 0.0, 0.0] |
| 26 | + |
| 27 | +def test_buffdescribe_non_null_values(test_df): |
| 28 | + result = buffdescribe(test_df) |
| 29 | + assert result['NOT_NULL'].tolist() == [3, 3, 3] |
| 30 | + |
| 31 | +def test_buffdescribe_unique_values(test_df): |
| 32 | + result = buffdescribe(test_df) |
| 33 | + assert result['UNIQUE_VALUES'].tolist() == [3, 3, 3] |
| 34 | + |
| 35 | +def test_buffdescribe_cardinality(test_df): |
| 36 | + result = buffdescribe(test_df) |
| 37 | + assert result['CARDIN (%)'].tolist() == [100.0, 100.0, 100.0] |
| 38 | + |
| 39 | +def test_buffdescribe_descriptive_statistics(test_df): |
| 40 | + result = buffdescribe(test_df) |
| 41 | + assert result.columns.tolist() == ['DATA_TYPE', 'MISSINGS (%)', 'NOT_NULL', 'UNIQUE_VALUES', 'CARDIN (%)', |
| 42 | + 'mean', 'median', 'std'] |
| 43 | + |
0 commit comments