Skip to content

Commit 0d99c2a

Browse files
committed
Test the case that drop_first is on and categorical variable only has one level.
1 parent 45f14e8 commit 0d99c2a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pandas/core/reshape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def melt_stub(df, stub, i, j):
944944

945945

946946
def get_dummies(data, prefix=None, prefix_sep='_', dummy_na=False,
947-
columns=None, sparse=False):
947+
columns=None, sparse=False, drop_first=False):
948948
"""
949949
Convert categorical variable into dummy/indicator variables
950950

pandas/tests/test_reshape.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ def test_basic_drop_first(self):
435435
result = get_dummies(s_series_index, sparse=self.sparse, drop_first=True)
436436
assert_frame_equal(result, expected)
437437

438+
# Test the case that categorical variable only has one level.
439+
def test_basic_drop_first_one_level(self):
440+
result = get_dummies(list('aaa'), sparse=self.sparse, drop_first=True)
441+
self.assertEqual(result.empty, True)
442+
438443
def test_basic_drop_first_NA(self):
439444
# Test NA hadling together with drop_first
440445
s_NA = ['a', 'b', np.nan]

0 commit comments

Comments
 (0)