Skip to content

Commit 5bd6eb8

Browse files
committed
TST: fixed test for multiple NaNs in index
1 parent 837104b commit 5bd6eb8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pandas/tests/frame/test_constructors.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1657,19 +1657,21 @@ def check(df):
16571657
for i in range(len(df.columns)):
16581658
df.iloc[:, i]
16591659

1660-
# allow single nans to succeed
16611660
indexer = np.arange(len(df.columns))[isna(df.columns)]
16621661

1663-
if len(indexer) == 1:
1664-
tm.assert_series_equal(df.iloc[:, indexer[0]],
1665-
df.loc[:, np.nan])
1666-
1667-
# multiple nans should fail
1668-
else:
1669-
1662+
# No NaN found -> error
1663+
if len(indexer) == 0:
16701664
def f():
16711665
df.loc[:, np.nan]
16721666
pytest.raises(TypeError, f)
1667+
# single nan should result in Series
1668+
elif len(indexer) == 1:
1669+
tm.assert_series_equal(df.iloc[:, indexer[0]],
1670+
df.loc[:, np.nan])
1671+
# multiple nans should result in DataFrame
1672+
else:
1673+
tm.assert_frame_equal(df.iloc[:, indexer],
1674+
df.loc[:, np.nan])
16731675

16741676
df = DataFrame([[1, 2, 3], [4, 5, 6]], index=[1, np.nan])
16751677
check(df)
@@ -1685,6 +1687,11 @@ def f():
16851687
columns=[np.nan, 1.1, 2.2, np.nan])
16861688
check(df)
16871689

1690+
# GH 21428 (non-unique columns)
1691+
df = DataFrame([[0.0, 1, 2, 3.0], [4, 5, 6, 7]],
1692+
columns=[np.nan, 1, 2, 2])
1693+
check(df)
1694+
16881695
def test_constructor_lists_to_object_dtype(self):
16891696
# from #1074
16901697
d = DataFrame({'a': [np.nan, False]})

0 commit comments

Comments
 (0)