Skip to content

Commit af9b72a

Browse files
authored
Add test to check crosstab supports Float64 formats (#50459)
1 parent 2e224c7 commit af9b72a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/reshape/test_crosstab.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,32 @@ def test_margin_normalize_multiple_columns(self):
795795
expected.index.name = "C"
796796
tm.assert_frame_equal(result, expected)
797797

798+
def test_margin_support_Float(self):
799+
# GH 50313
800+
# use Float64 formats and function aggfunc with margins
801+
df = DataFrame(
802+
{"A": [1, 2, 2, 1], "B": [3, 3, 4, 5], "C": [-1.0, 10.0, 1.0, 10.0]},
803+
dtype="Float64",
804+
)
805+
result = crosstab(
806+
df["A"],
807+
df["B"],
808+
values=df["C"],
809+
aggfunc="sum",
810+
margins=True,
811+
)
812+
expected = DataFrame(
813+
[
814+
[-1.0, pd.NA, 10.0, 9.0],
815+
[10.0, 1.0, pd.NA, 11.0],
816+
[9.0, 1.0, 10.0, 20.0],
817+
],
818+
index=Index([1.0, 2.0, "All"], dtype="object", name="A"),
819+
columns=Index([3.0, 4.0, 5.0, "All"], dtype="object", name="B"),
820+
dtype="Float64",
821+
)
822+
tm.assert_frame_equal(result, expected)
823+
798824

799825
@pytest.mark.parametrize("a_dtype", ["category", "int64"])
800826
@pytest.mark.parametrize("b_dtype", ["category", "int64"])

0 commit comments

Comments
 (0)