Skip to content

Commit e97398c

Browse files
committed
implement tests to check duplicate cols
1 parent 1111847 commit e97398c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pandas/tests/frame/test_dtypes.py

+15
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,21 @@ def test_select_dtypes_include_exclude_mixed_scalars_lists(self):
287287
ei = df[['b', 'c', 'f', 'k']]
288288
assert_frame_equal(ri, ei)
289289

290+
def test_select_dtypes_duplicate_columns(self):
291+
df = DataFrame({'a': list('abc'),
292+
'b': list(range(1, 4)),
293+
'c': np.arange(3, 6).astype('u1'),
294+
'd': np.arange(4.0, 7.0, dtype='float64'),
295+
'e': [True, False, True],
296+
'f': pd.date_range('now', periods=3).values})
297+
df.columns = ['a', 'a', 'b', 'b', 'b', 'c']
298+
299+
e = DataFrame({'a': list(range(1, 4)),
300+
'b': np.arange(3, 6).astype('u1')})
301+
302+
r = df.select_dtypes(include=[np.number], exclude=['floating'])
303+
assert_frame_equal(r, e)
304+
290305
def test_select_dtypes_not_an_attr_but_still_valid_dtype(self):
291306
df = DataFrame({'a': list('abc'),
292307
'b': list(range(1, 4)),

pandas/tests/reshape/test_reshape.py

+14
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,20 @@ def test_get_dummies_dont_sparsify_all_columns(self, sparse):
465465

466466
tm.assert_frame_equal(df[['GDP']], df2)
467467

468+
def test_get_dummies_duplicate_columns(self, df):
469+
df.columns = ["A", "A", "A"]
470+
result = get_dummies(df).sort_index(axis=1)
471+
472+
expected = DataFrame([[1, 1, 0, 1, 0],
473+
[2, 0, 1, 1, 0],
474+
[3, 1, 0, 0, 1]],
475+
columns=['A', 'A_a', 'A_b', 'A_b', 'A_c'],
476+
dtype=np.uint8).sort_index(axis=1)
477+
478+
expected = expected.astype({"A": np.int64})
479+
480+
tm.assert_frame_equal(result, expected)
481+
468482

469483
class TestCategoricalReshape(object):
470484

0 commit comments

Comments
 (0)