Skip to content

Commit 53b0e0e

Browse files
rushabh-vjreback
authored andcommitted
Add test for multiindex json (pandas-dev#31307)
1 parent 839e7f1 commit 53b0e0e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tests/io/json/test_pandas.py

+15
Original file line numberDiff line numberDiff line change
@@ -1647,3 +1647,18 @@ def test_frame_int_overflow(self):
16471647
expected = DataFrame({"col": ["31900441201190696999", "Text"]})
16481648
result = read_json(encoded_json)
16491649
tm.assert_frame_equal(result, expected)
1650+
1651+
@pytest.mark.parametrize(
1652+
"dataframe,expected",
1653+
[
1654+
(
1655+
pd.DataFrame({"x": [1, 2, 3], "y": ["a", "b", "c"]}),
1656+
'{"(0, \'x\')":1,"(0, \'y\')":"a","(1, \'x\')":2,'
1657+
'"(1, \'y\')":"b","(2, \'x\')":3,"(2, \'y\')":"c"}',
1658+
)
1659+
],
1660+
)
1661+
def test_json_multiindex(self, dataframe, expected):
1662+
series = dataframe.stack()
1663+
result = series.to_json(orient="index")
1664+
assert result == expected

0 commit comments

Comments
 (0)