Skip to content

Commit 445dcdf

Browse files
committed
TST: fixed test for multiple NaNs in index
1 parent 30bd5ca commit 445dcdf

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pandas/tests/frame/test_constructors.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1657,19 +1657,20 @@ 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:
1662+
if len(indexer) == 0:
1663+
def f():
1664+
df.loc[:, np.nan]
1665+
pytest.raises(TypeError, f)
1666+
elif len(indexer) == 1:
16641667
tm.assert_series_equal(df.iloc[:, indexer[0]],
16651668
df.loc[:, np.nan])
16661669

1667-
# multiple nans should fail
1670+
# multiple nans should result in DataFrame
16681671
else:
1669-
1670-
def f():
1671-
df.loc[:, np.nan]
1672-
pytest.raises(TypeError, f)
1672+
tm.assert_frame_equal(df.iloc[:, indexer],
1673+
df.loc[:, np.nan])
16731674

16741675
df = DataFrame([[1, 2, 3], [4, 5, 6]], index=[1, np.nan])
16751676
check(df)
@@ -1685,6 +1686,11 @@ def f():
16851686
columns=[np.nan, 1.1, 2.2, np.nan])
16861687
check(df)
16871688

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

0 commit comments

Comments
 (0)