From c21e21edfc8ea2aba5f0a208a0e4e84e8c5c282a Mon Sep 17 00:00:00 2001 From: Dario Hett Date: Wed, 21 Dec 2022 14:22:04 +0100 Subject: [PATCH 1/5] feat: add `table` to JsonSeriesOrient Literals --- pandas-stubs/_typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 5e6e64cba..e46f4e739 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -318,7 +318,7 @@ MergeHow: TypeAlias = Union[JoinHow, Literal["cross"]] JsonFrameOrient: TypeAlias = Literal[ "split", "records", "index", "columns", "values", "table" ] -JsonSeriesOrient: TypeAlias = Literal["split", "records", "index"] +JsonSeriesOrient: TypeAlias = Literal["split", "records", "index", "table"] TimestampConvention: TypeAlias = Literal["start", "end", "s", "e"] From d8d9c20ef7389548698bd41f8e4a861df29bf148 Mon Sep 17 00:00:00 2001 From: Dario Hett Date: Sat, 24 Dec 2022 12:14:08 +0100 Subject: [PATCH 2/5] TST: add all series.to_json orient parameters (#482) --- tests/test_io.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_io.py b/tests/test_io.py index aeb3c392a..afb99f7e3 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -387,12 +387,12 @@ def test_json(): check(assert_type(read_json(bin_json), DataFrame), DataFrame) -def test_json_series(): +@pytest.mark.parametrize("orient", [None, "split", "records", "index", "table"]) +def test_json_series(orient): s = DF["a"] with ensure_clean() as path: - check(assert_type(s.to_json(path), None), type(None)) - check(assert_type(read_json(path, typ="series"), Series), Series) - check(assert_type(DF.to_json(), str), str) + check(assert_type(s.to_json(path, orient=orient), None), type(None)) + check(assert_type(read_json(path, typ="series", orient=orient), Series), Series) def test_json_chunk(): From 012a9b81a44cb68c3966da220fee53e536a8a62c Mon Sep 17 00:00:00 2001 From: Dario Hett Date: Sat, 24 Dec 2022 17:21:01 +0100 Subject: [PATCH 3/5] TST: Series.to_json explicit orient tests --- tests/test_io.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/test_io.py b/tests/test_io.py index afb99f7e3..d34270473 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -387,12 +387,39 @@ def test_json(): check(assert_type(read_json(bin_json), DataFrame), DataFrame) -@pytest.mark.parametrize("orient", [None, "split", "records", "index", "table"]) def test_json_series(orient): s = DF["a"] - with ensure_clean() as path: - check(assert_type(s.to_json(path, orient=orient), None), type(None)) - check(assert_type(read_json(path, typ="series", orient=orient), Series), Series) + check( + assert_type( + read_json(s.to_json(orient=None), typ="series", orient=None), Series + ), + Series, + ) + check( + assert_type( + read_json(s.to_json(orient="split"), typ="series", orient="split"), Series + ), + Series, + ) + check( + assert_type( + read_json(s.to_json(orient="records"), typ="series", orient="records"), + Series, + ), + Series, + ) + check( + assert_type( + read_json(s.to_json(orient="index"), typ="series", orient="index"), Series + ), + Series, + ) + check( + assert_type( + read_json(s.to_json(orient="table"), typ="series", orient="table"), Series + ), + Series, + ) def test_json_chunk(): From 4ee6f9ab29a475740e7d1c178c7a42ac166b7421 Mon Sep 17 00:00:00 2001 From: Dario Hett Date: Sun, 25 Dec 2022 08:11:43 +0100 Subject: [PATCH 4/5] TST: Series.to_json drop unused argument --- tests/test_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_io.py b/tests/test_io.py index d34270473..86062d870 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -387,7 +387,7 @@ def test_json(): check(assert_type(read_json(bin_json), DataFrame), DataFrame) -def test_json_series(orient): +def test_json_series(): s = DF["a"] check( assert_type( From d7591290fca9ac663af7ae38367498d059b6d2fa Mon Sep 17 00:00:00 2001 From: Dario Hett Date: Tue, 27 Dec 2022 16:00:59 +0100 Subject: [PATCH 5/5] TST: series.to_json() path parameter --- tests/test_io.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_io.py b/tests/test_io.py index 86062d870..2817b170d 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -389,6 +389,10 @@ def test_json(): def test_json_series(): s = DF["a"] + with ensure_clean() as path: + check(assert_type(s.to_json(path), None), type(None)) + check(assert_type(read_json(path, typ="series"), Series), Series) + check(assert_type(DF.to_json(), str), str) check( assert_type( read_json(s.to_json(orient=None), typ="series", orient=None), Series