Skip to content

Commit f56c72f

Browse files
committed
TST: fixed test for multiple NaNs in index
1 parent 62bfad9 commit f56c72f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pandas/tests/frame/test_constructors.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1655,19 +1655,21 @@ def check(df):
16551655
for i in range(len(df.columns)):
16561656
df.iloc[:, i]
16571657

1658-
# allow single nans to succeed
16591658
indexer = np.arange(len(df.columns))[isna(df.columns)]
16601659

1661-
if len(indexer) == 1:
1660+
if len(indexer) == 0:
1661+
def f():
1662+
df.loc[:, np.nan]
1663+
pytest.raises(TypeError, f)
1664+
elif len(indexer) == 1:
16621665
tm.assert_series_equal(df.iloc[:, indexer[0]],
16631666
df.loc[:, np.nan])
16641667

1665-
# multiple nans should fail
1668+
# multiple nans should result in DataFrame
16661669
else:
1670+
tm.assert_frame_equal(df.iloc[:, indexer],
1671+
df.loc[:, np.nan])
16671672

1668-
def f():
1669-
df.loc[:, np.nan]
1670-
pytest.raises(TypeError, f)
16711673

16721674
df = DataFrame([[1, 2, 3], [4, 5, 6]], index=[1, np.nan])
16731675
check(df)
@@ -1683,6 +1685,11 @@ def f():
16831685
columns=[np.nan, 1.1, 2.2, np.nan])
16841686
check(df)
16851687

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

0 commit comments

Comments
 (0)