Skip to content

Commit

Permalink
test_pivot_columns_is_none
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins committed Nov 18, 2024
1 parent 181c7e5 commit 2cad97c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2664,18 +2664,21 @@ def test_pivot_columns_not_given(self):
with pytest.raises(TypeError, match="missing 1 required keyword-only argument"):
df.pivot()

@pytest.mark.xfail(
using_string_dtype(), reason="TODO(infer_string) None is cast to NaN"
)
def test_pivot_columns_is_none(self):
# GH#48293
df = DataFrame({None: [1], "b": 2, "c": 3})
df = DataFrame([[1, 2, 3]], columns=Index([None, "b", "c"], dtype="object"))
result = df.pivot(columns=None)
expected = DataFrame({("b", 1): [2], ("c", 1): 3})
expected.columns = expected.columns.set_levels(
expected.columns.levels[0].astype(object), level=0
)
tm.assert_frame_equal(result, expected)

result = df.pivot(columns=None, index="b")
expected = DataFrame({("c", 1): 3}, index=Index([2], name="b"))
expected.columns = expected.columns.set_levels(
expected.columns.levels[0].astype(object), level=0
)
tm.assert_frame_equal(result, expected)

result = df.pivot(columns=None, index="b", values="c")
Expand Down

0 comments on commit 2cad97c

Please sign in to comment.