Skip to content

Commit ba974f1

Browse files
committed
TST: Added test of unstacking two levels with NaN.
1 parent 3f24b87 commit ba974f1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pandas/tests/test_frame.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -12407,7 +12407,8 @@ def verify(df):
1240712407
# GH7403
1240812408
df = pd.DataFrame({'A': list('aaaabbbb'),'B':range(8), 'C':range(8)})
1240912409
df.iloc[3, 1] = np.NaN
12410-
left = df.set_index(['A', 'B']).unstack(0)
12410+
dfs = df.set_index(['A', 'B'])
12411+
left = dfs.unstack(0)
1241112412

1241212413
vals = [[3, 0, 1, 2, nan, nan, nan, nan],
1241312414
[nan, nan, nan, nan, 4, 5, 6, 7]]
@@ -12420,6 +12421,23 @@ def verify(df):
1242012421
right = DataFrame(vals, columns=cols, index=idx)
1242112422
assert_frame_equal(left, right)
1242212423

12424+
12425+
left = dfs.unstack([0, 1])
12426+
data = [3, 0, 1, 2, 4, 5, 6, 7]
12427+
idx = MultiIndex(levels=[['C'], ['a', 'b'], [0, 1, 2, 4, 5, 6, 7]],
12428+
labels=[[0, 0, 0, 0, 0, 0, 0, 0],
12429+
[0, 0, 0, 0, 1, 1, 1, 1],
12430+
[-1, 0, 1, 2, 3, 4, 5, 6]],
12431+
names=[None, 'A', 'B'])
12432+
right = Series(data, index=idx, dtype=dfs.dtypes[0])
12433+
print("dfs=")
12434+
print(dfs)
12435+
print("\nleft=")
12436+
print(left)
12437+
print("\nright=")
12438+
print(right)
12439+
assert_series_equal(left, right)
12440+
1242312441
df = DataFrame({'A': list('aaaabbbb'), 'B':list(range(4))*2,
1242412442
'C':range(8)})
1242512443
df.iloc[2,1] = np.NaN

0 commit comments

Comments
 (0)