From 08c4163c648ebf559c76c6f4ef9f51d80c4652c3 Mon Sep 17 00:00:00 2001 From: Con Date: Mon, 15 May 2023 11:55:00 -0400 Subject: [PATCH 1/4] TST: Added test coverage for pd.read_json index type --- pandas/tests/io/json/test_pandas.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index e93cd836fa307..3822bd394b883 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1398,6 +1398,15 @@ def test_read_json_table_dtype_raises(self, dtype): with pytest.raises(ValueError, match=msg): read_json(dfjson, orient="table", dtype=dtype) + @pytest.mark.parametrize("orient", ["index", "columns", "records", "values"]) + def test_read_json_table_empty_dtype(self, orient): + # GH 28558 + + df = DataFrame() + dfjson = read_json("{}", orient=orient, convert_axes=True) + + assert df.index.dtype == dfjson.index.dtype + def test_read_json_table_convert_axes_raises(self): # GH25433 GH25435 df = DataFrame([[1, 2], [3, 4]], index=[1.0, 2.0], columns=["1.", "2."]) From 954864f4c4913f29bd625c07772d96967733a2d4 Mon Sep 17 00:00:00 2001 From: Conrad Mcgee Stocks Date: Tue, 16 May 2023 12:55:27 -0300 Subject: [PATCH 2/4] Update pandas/tests/io/json/test_pandas.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/tests/io/json/test_pandas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 3822bd394b883..b1330865e0a7e 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1399,7 +1399,7 @@ def test_read_json_table_dtype_raises(self, dtype): read_json(dfjson, orient="table", dtype=dtype) @pytest.mark.parametrize("orient", ["index", "columns", "records", "values"]) - def test_read_json_table_empty_dtype(self, orient): + def test_read_json_table_empty_axes_dtype(self, orient): # GH 28558 df = DataFrame() From e3f9ef00cdaecee51307f814126146b5f27985fe Mon Sep 17 00:00:00 2001 From: Con Date: Tue, 16 May 2023 21:42:26 -0300 Subject: [PATCH 3/4] add coverage for entire index and columns. --- pandas/tests/io/json/test_pandas.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index b1330865e0a7e..ea6c0b0d69dfc 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1400,12 +1400,13 @@ def test_read_json_table_dtype_raises(self, dtype): @pytest.mark.parametrize("orient", ["index", "columns", "records", "values"]) def test_read_json_table_empty_axes_dtype(self, orient): - # GH 28558 + # GH28558 - df = DataFrame() - dfjson = read_json("{}", orient=orient, convert_axes=True) + expected = DataFrame() + result = read_json("{}", orient=orient, convert_axes=True) - assert df.index.dtype == dfjson.index.dtype + tm.assert_index_equal(result.index, expected.index) + tm.assert_equal(result.columns, expected.columns) def test_read_json_table_convert_axes_raises(self): # GH25433 GH25435 From 578a908922dbc8abc7e69573d4c44445d5698595 Mon Sep 17 00:00:00 2001 From: Conrad Mcgee Stocks Date: Wed, 17 May 2023 14:01:59 -0300 Subject: [PATCH 4/4] Update pandas/tests/io/json/test_pandas.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/tests/io/json/test_pandas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index ea6c0b0d69dfc..1fc51a70c6614 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1406,7 +1406,7 @@ def test_read_json_table_empty_axes_dtype(self, orient): result = read_json("{}", orient=orient, convert_axes=True) tm.assert_index_equal(result.index, expected.index) - tm.assert_equal(result.columns, expected.columns) + tm.assert_index_equal(result.columns, expected.columns) def test_read_json_table_convert_axes_raises(self): # GH25433 GH25435