Skip to content

Commit 9fe83d7

Browse files
Doug McNeilDoug McNeil
Doug McNeil
authored and
Doug McNeil
committed
TST: NaN in MultiIndex should not become a string (pandas-dev#7031)
1 parent 10c17d4 commit 9fe83d7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/indexes/test_multi.py

+21
Original file line numberDiff line numberDiff line change
@@ -2858,3 +2858,24 @@ def test_tuples_with_name_string(self):
28582858
pd.Index(li, name='abc')
28592859
with pytest.raises(ValueError):
28602860
pd.Index(li, name='a')
2861+
2862+
def test_nan_stays_float(self):
2863+
2864+
# GH 7031
2865+
idx0 = pd.MultiIndex(levels=[["A", "B"], []],
2866+
labels=[[1, 0], [-1, -1]],
2867+
names=[0, 1])
2868+
idx1 = pd.MultiIndex(levels=[["C"], ["D"]],
2869+
labels=[[0], [0]],
2870+
names=[0, 1])
2871+
idxm = idx0.join(idx1, how='outer')
2872+
assert pd.isnull(idx0.get_level_values(1)).all()
2873+
# the following failed in 0.14.1
2874+
assert pd.isnull(idxm.get_level_values(1)[:-1]).all()
2875+
2876+
df0 = pd.DataFrame([[1, 2]], index=idx0)
2877+
df1 = pd.DataFrame([[3, 4]], index=idx1)
2878+
dfm = df0 - df1
2879+
assert pd.isnull(df0.index.get_level_values(1)).all()
2880+
# the following failed in 0.14.1
2881+
assert pd.isnull(dfm.index.get_level_values(1)[:-1]).all()

0 commit comments

Comments
 (0)