Skip to content

Commit 742244d

Browse files
committed
Test columns selector (list vs. string) integration with transformers.
1 parent d2539ba commit 742244d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_dataframe_mapper.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from mock import Mock
23

34
from pandas import DataFrame
45
import pandas as pd
@@ -65,6 +66,36 @@ def test_with_car_dataframe(cars_dataframe):
6566
assert scores.mean() > 0.30
6667

6768

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+
6899
def test_list_transformers():
69100
dataframe = pd.DataFrame({"a": [1, np.nan, 3], "b": [1, 5, 7]})
70101

0 commit comments

Comments
 (0)