From 3a3301ed504077a2fb14b0b1c5144090fa61a8b2 Mon Sep 17 00:00:00 2001 From: Rushabh Vasani Date: Sat, 25 Jan 2020 18:04:21 +0530 Subject: [PATCH 1/2] add test for multiindex json --- pandas/tests/io/json/test_pandas.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 638bcaa21bdf9..c76466fb59cdc 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1647,3 +1647,16 @@ def test_frame_int_overflow(self): expected = DataFrame({"col": ["31900441201190696999", "Text"]}) result = read_json(encoded_json) tm.assert_frame_equal(result, expected) + + @pytest.mark.parametrize( + "dataframe,expected", + [ + (pd.DataFrame({'x': [1, 2, 3], 'y': ['a', 'b', 'c']}), + '{"(0, \'x\')":1,"(0, \'y\')":"a","(1, \'x\')":2,' + '"(1, \'y\')":"b","(2, \'x\')":3,"(2, \'y\')":"c"}') + ] + ) + def test_json_multiindex(self, dataframe, expected): + series = dataframe.stack() + result = series.to_json(orient="index") + assert result==expected From f1bb461d20f23d2d912e794cbd2a1819b3237bba Mon Sep 17 00:00:00 2001 From: Rushabh Vasani Date: Sat, 25 Jan 2020 18:08:43 +0530 Subject: [PATCH 2/2] run black pandas --- pandas/tests/io/json/test_pandas.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index c76466fb59cdc..94d51589023c4 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1651,12 +1651,14 @@ def test_frame_int_overflow(self): @pytest.mark.parametrize( "dataframe,expected", [ - (pd.DataFrame({'x': [1, 2, 3], 'y': ['a', 'b', 'c']}), - '{"(0, \'x\')":1,"(0, \'y\')":"a","(1, \'x\')":2,' - '"(1, \'y\')":"b","(2, \'x\')":3,"(2, \'y\')":"c"}') - ] + ( + pd.DataFrame({"x": [1, 2, 3], "y": ["a", "b", "c"]}), + '{"(0, \'x\')":1,"(0, \'y\')":"a","(1, \'x\')":2,' + '"(1, \'y\')":"b","(2, \'x\')":3,"(2, \'y\')":"c"}', + ) + ], ) def test_json_multiindex(self, dataframe, expected): series = dataframe.stack() result = series.to_json(orient="index") - assert result==expected + assert result == expected