|
1 | 1 | import pytest
|
| 2 | +from mock import Mock |
2 | 3 |
|
3 | 4 | from pandas import DataFrame
|
4 | 5 | import pandas as pd
|
@@ -65,6 +66,36 @@ def test_with_car_dataframe(cars_dataframe):
|
65 | 66 | assert scores.mean() > 0.30
|
66 | 67 |
|
67 | 68 |
|
| 69 | +def test_cols_string_array(): |
| 70 | + """ |
| 71 | + If an string specified as the columns, the transformer |
| 72 | + is called with a 1-d array as input. |
| 73 | + """ |
| 74 | + dataframe = pd.DataFrame({"a": [1, 2, 3]}) |
| 75 | + mock_transformer = Mock() |
| 76 | + mock_transformer.transform.return_value = np.array([1, 2, 3]) # do nothing |
| 77 | + mapper = DataFrameMapper([("a", mock_transformer)]) |
| 78 | + |
| 79 | + mapper.fit_transform(dataframe) |
| 80 | + args, kwargs = mock_transformer.fit.call_args |
| 81 | + assert args[0].shape == (3,) |
| 82 | + |
| 83 | + |
| 84 | +def test_cols_list_column_vector(): |
| 85 | + """ |
| 86 | + If a one-element list is specified as the columns, the transformer |
| 87 | + is called with a column vector as input. |
| 88 | + """ |
| 89 | + dataframe = pd.DataFrame({"a": [1, 2, 3]}) |
| 90 | + mock_transformer = Mock() |
| 91 | + mock_transformer.transform.return_value = np.array([1, 2, 3]) # do nothing |
| 92 | + mapper = DataFrameMapper([(["a"], mock_transformer)]) |
| 93 | + |
| 94 | + mapper.fit_transform(dataframe) |
| 95 | + args, kwargs = mock_transformer.fit.call_args |
| 96 | + assert args[0].shape == (3, 1) |
| 97 | + |
| 98 | + |
68 | 99 | def test_list_transformers():
|
69 | 100 | dataframe = pd.DataFrame({"a": [1, np.nan, 3], "b": [1, 5, 7]})
|
70 | 101 |
|
|
0 commit comments