Skip to content

Commit 425c60e

Browse files
committed
Merge pull request #22 from dukebody/single-col-nparray
Return a numpy array when selecting a single column.
2 parents c374c98 + 478489e commit 425c60e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

sklearn_pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _get_col_subset(self, X, cols):
9595
X = X.df
9696

9797
if return_vector:
98-
t = X[cols[0]]
98+
t = X[cols[0]].values
9999
else:
100100
t = X.as_matrix(cols)
101101

tests/test_dataframe_mapper.py

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def test_with_iris_dataframe(iris_dataframe):
5151
assert (scores.std() * 2) < 0.04
5252

5353

54+
def test_get_col_subset_single_column_array(iris_dataframe):
55+
"""
56+
Selecting a single column should return a 1-dimensional numpy array.
57+
"""
58+
mapper = DataFrameMapper(None)
59+
array = mapper._get_col_subset(iris_dataframe, "species")
60+
61+
assert type(array) == np.ndarray
62+
assert array.shape == (len(iris_dataframe["species"]),)
63+
64+
5465
def test_with_car_dataframe(cars_dataframe):
5566
pipeline = Pipeline([
5667
("preprocess", DataFrameMapper([

0 commit comments

Comments
 (0)