Skip to content

Commit

Permalink
Test the case that drop_first is on and categorical variable only h…
Browse files Browse the repository at this point in the history
…as one level.
  • Loading branch information
BranYang committed Feb 1, 2016
1 parent 45f14e8 commit 0d99c2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def melt_stub(df, stub, i, j):


def get_dummies(data, prefix=None, prefix_sep='_', dummy_na=False,
columns=None, sparse=False):
columns=None, sparse=False, drop_first=False):
"""
Convert categorical variable into dummy/indicator variables
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ def test_basic_drop_first(self):
result = get_dummies(s_series_index, sparse=self.sparse, drop_first=True)
assert_frame_equal(result, expected)

# Test the case that categorical variable only has one level.
def test_basic_drop_first_one_level(self):
result = get_dummies(list('aaa'), sparse=self.sparse, drop_first=True)
self.assertEqual(result.empty, True)

def test_basic_drop_first_NA(self):
# Test NA hadling together with drop_first
s_NA = ['a', 'b', np.nan]
Expand Down

0 comments on commit 0d99c2a

Please sign in to comment.