From 0d99c2aeb6176239f28799c02cc4728e64db36d0 Mon Sep 17 00:00:00 2001 From: Bran Yang Date: Thu, 28 Jan 2016 00:03:47 +0800 Subject: [PATCH] Test the case that `drop_first` is on and categorical variable only has one level. --- pandas/core/reshape.py | 2 +- pandas/tests/test_reshape.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/reshape.py b/pandas/core/reshape.py index fc6a660bf276d..bb7eba496e34a 100644 --- a/pandas/core/reshape.py +++ b/pandas/core/reshape.py @@ -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 diff --git a/pandas/tests/test_reshape.py b/pandas/tests/test_reshape.py index 98b15c0ec850c..b0dd578ae2bf7 100644 --- a/pandas/tests/test_reshape.py +++ b/pandas/tests/test_reshape.py @@ -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]