From 82f8d2758b4b899be03c102f4fdf23c47e58828f Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Mon, 6 Apr 2020 19:02:40 -0400 Subject: [PATCH 01/11] fix #GH32383 --- pandas/tests/io/json/test_json_table_schema.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index c0d40048a72fe..9e6492a6193fc 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -237,6 +237,23 @@ def test_build_series(self): assert result == expected + def test_read_json(self): + # GH32383 + df = pd.DataFrame( + { + "_id": {"0": "0"}, + "category": {"0": "Goods"}, + "recommender_id": {"0": "3"}, + "recommender_name_en": {"0": "Urata"}, + "name_en": {"0": "Hakata Dolls Matsuo"}, + } + ) + df_json = df.to_json() + df_dict = json.loads(df_json) + result = pd.read_json(df_json) + expected = pd.read_json(df_json) + tm.assert_frame_equal(result, expected) + def test_to_json(self): df = self.df.copy() df.index.name = "idx" From 01a13606398d43e1663a78ea2ef03aeba302bae0 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Mon, 6 Apr 2020 19:30:26 -0400 Subject: [PATCH 02/11] typo --- pandas/tests/io/json/test_json_table_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 9e6492a6193fc..901e8266f2358 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -251,7 +251,7 @@ def test_read_json(self): df_json = df.to_json() df_dict = json.loads(df_json) result = pd.read_json(df_json) - expected = pd.read_json(df_json) + expected = pd.DataFrame().from_dict(df_dict) tm.assert_frame_equal(result, expected) def test_to_json(self): From f59cc3e1f10dc1ded980db5961537b91e5208991 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Mon, 6 Apr 2020 21:36:04 -0400 Subject: [PATCH 03/11] index type mismatch --- pandas/tests/io/json/test_json_table_schema.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 901e8266f2358..ef777f66240e9 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -238,7 +238,7 @@ def test_build_series(self): assert result == expected def test_read_json(self): - # GH32383 + # GH 32383 df = pd.DataFrame( { "_id": {"0": "0"}, @@ -250,7 +250,8 @@ def test_read_json(self): ) df_json = df.to_json() df_dict = json.loads(df_json) - result = pd.read_json(df_json) + result = pd.read_json(df_json, dtype=False) + result.index = result.index.astype(str) expected = pd.DataFrame().from_dict(df_dict) tm.assert_frame_equal(result, expected) From aba624fe311913859c55380782200883d4017b7d Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Tue, 7 Apr 2020 00:56:04 -0400 Subject: [PATCH 04/11] fix names --- pandas/tests/io/json/test_json_table_schema.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index ef777f66240e9..f2e2432e22c27 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -237,14 +237,16 @@ def test_build_series(self): assert result == expected - def test_read_json(self): + def test_read_json_from_to_json_results(self): # GH 32383 df = pd.DataFrame( { "_id": {"0": "0"}, "category": {"0": "Goods"}, "recommender_id": {"0": "3"}, + "recommender_name_jp": {"0": "浦田"}, "recommender_name_en": {"0": "Urata"}, + "name_jp": {"0": "博多人形(松尾吉将まつお よしまさ)"}, "name_en": {"0": "Hakata Dolls Matsuo"}, } ) @@ -252,7 +254,7 @@ def test_read_json(self): df_dict = json.loads(df_json) result = pd.read_json(df_json, dtype=False) result.index = result.index.astype(str) - expected = pd.DataFrame().from_dict(df_dict) + expected = pd.DataFrame.from_dict(df_dict) tm.assert_frame_equal(result, expected) def test_to_json(self): From 32aaafe510cb5ecac31888b2b7056d31d29e5fb0 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Tue, 7 Apr 2020 11:52:46 -0400 Subject: [PATCH 05/11] remove expected df --- pandas/tests/io/json/test_json_table_schema.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index f2e2432e22c27..aa6ea9e080e16 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -251,11 +251,9 @@ def test_read_json_from_to_json_results(self): } ) df_json = df.to_json() - df_dict = json.loads(df_json) - result = pd.read_json(df_json, dtype=False) + result = pd.read_json(df_json) result.index = result.index.astype(str) - expected = pd.DataFrame.from_dict(df_dict) - tm.assert_frame_equal(result, expected) + tm.assert_frame_equal(result, df) def test_to_json(self): df = self.df.copy() From 9ea2cdebbb6cb9df9efcf0dc095195e1777ce76f Mon Sep 17 00:00:00 2001 From: Benjamin Beier Liu Date: Tue, 7 Apr 2020 12:36:55 -0400 Subject: [PATCH 06/11] Update pandas/tests/io/json/test_json_table_schema.py Co-Authored-By: Simon Hawkins --- pandas/tests/io/json/test_json_table_schema.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index aa6ea9e080e16..b72f9ec85c0ff 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -250,8 +250,7 @@ def test_read_json_from_to_json_results(self): "name_en": {"0": "Hakata Dolls Matsuo"}, } ) - df_json = df.to_json() - result = pd.read_json(df_json) + result = pd.read_json(df.to_json()) result.index = result.index.astype(str) tm.assert_frame_equal(result, df) From 202ef6cabfe4367d81041a1290ca46d9960ca8a6 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Tue, 7 Apr 2020 13:29:07 -0400 Subject: [PATCH 07/11] type converion mess up --- pandas/tests/io/json/test_json_table_schema.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index aa6ea9e080e16..33af24f11538d 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -251,9 +251,11 @@ def test_read_json_from_to_json_results(self): } ) df_json = df.to_json() + df_dict = json.loads(df_json) result = pd.read_json(df_json) result.index = result.index.astype(str) - tm.assert_frame_equal(result, df) + expected = pd.DataFrame.from_dict(df_dict) + tm.assert_frame_equal(result, expected) def test_to_json(self): df = self.df.copy() From 339523eb4ca403f109595b546ba4b9aad2b38596 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Tue, 7 Apr 2020 15:29:36 -0400 Subject: [PATCH 08/11] fix type error --- pandas/tests/io/json/test_json_table_schema.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 33af24f11538d..803620fc0487f 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -241,21 +241,18 @@ def test_read_json_from_to_json_results(self): # GH 32383 df = pd.DataFrame( { - "_id": {"0": "0"}, + "_id": {"0": 0}, "category": {"0": "Goods"}, - "recommender_id": {"0": "3"}, + "recommender_id": {"0": 3}, "recommender_name_jp": {"0": "浦田"}, "recommender_name_en": {"0": "Urata"}, "name_jp": {"0": "博多人形(松尾吉将まつお よしまさ)"}, "name_en": {"0": "Hakata Dolls Matsuo"}, } ) - df_json = df.to_json() - df_dict = json.loads(df_json) - result = pd.read_json(df_json) - result.index = result.index.astype(str) - expected = pd.DataFrame.from_dict(df_dict) - tm.assert_frame_equal(result, expected) + result = pd.read_json(df.to_json()) + df.index = df.index.astype(int) + tm.assert_frame_equal(result, df) def test_to_json(self): df = self.df.copy() From 98498207ecc231d48e70171209c72a73aabbb5a9 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Fri, 10 Apr 2020 12:52:29 -0400 Subject: [PATCH 09/11] simplify code --- pandas/tests/io/json/test_json_table_schema.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 803620fc0487f..023b5d0d9d8b7 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -241,17 +241,16 @@ def test_read_json_from_to_json_results(self): # GH 32383 df = pd.DataFrame( { - "_id": {"0": 0}, - "category": {"0": "Goods"}, - "recommender_id": {"0": 3}, - "recommender_name_jp": {"0": "浦田"}, - "recommender_name_en": {"0": "Urata"}, - "name_jp": {"0": "博多人形(松尾吉将まつお よしまさ)"}, - "name_en": {"0": "Hakata Dolls Matsuo"}, + "_id": {0: 0}, + "category": {0: "Goods"}, + "recommender_id": {0: 3}, + "recommender_name_jp": {0: "浦田"}, + "recommender_name_en": {0: "Urata"}, + "name_jp": {0: "博多人形(松尾吉将まつお よしまさ)"}, + "name_en": {0: "Hakata Dolls Matsuo"}, } ) result = pd.read_json(df.to_json()) - df.index = df.index.astype(int) tm.assert_frame_equal(result, df) def test_to_json(self): From f0727eba759c435b469ec366c4eeb6001bc68a99 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Fri, 10 Apr 2020 18:01:00 -0400 Subject: [PATCH 10/11] remove space --- pandas/tests/io/json/test_json_table_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 023b5d0d9d8b7..e77e0244f938a 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -238,7 +238,7 @@ def test_build_series(self): assert result == expected def test_read_json_from_to_json_results(self): - # GH 32383 + # GH32383 df = pd.DataFrame( { "_id": {0: 0}, From ca50ff9194b05bb8be9d03bf0a7281ee4093e923 Mon Sep 17 00:00:00 2001 From: BenjaminLiu Date: Sun, 12 Apr 2020 00:31:35 -0400 Subject: [PATCH 11/11] rec changes by jreback --- .../tests/io/json/test_json_table_schema.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index e77e0244f938a..a379771fc60e2 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -241,17 +241,19 @@ def test_read_json_from_to_json_results(self): # GH32383 df = pd.DataFrame( { - "_id": {0: 0}, - "category": {0: "Goods"}, - "recommender_id": {0: 3}, - "recommender_name_jp": {0: "浦田"}, - "recommender_name_en": {0: "Urata"}, - "name_jp": {0: "博多人形(松尾吉将まつお よしまさ)"}, - "name_en": {0: "Hakata Dolls Matsuo"}, + "_id": {"row_0": 0}, + "category": {"row_0": "Goods"}, + "recommender_id": {"row_0": 3}, + "recommender_name_jp": {"row_0": "浦田"}, + "recommender_name_en": {"row_0": "Urata"}, + "name_jp": {"row_0": "博多人形(松尾吉将まつお よしまさ)"}, + "name_en": {"row_0": "Hakata Dolls Matsuo"}, } ) - result = pd.read_json(df.to_json()) - tm.assert_frame_equal(result, df) + result1 = pd.read_json(df.to_json()) + result2 = pd.DataFrame.from_dict(json.loads(df.to_json())) + tm.assert_frame_equal(result1, df) + tm.assert_frame_equal(result2, df) def test_to_json(self): df = self.df.copy()