From 89870f39276da5527d54a86cfa1d7659335b7674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Sat, 12 Apr 2025 12:31:41 -0400 Subject: [PATCH 1/2] GH1179 Add WriteBuffer[bytes] to to_json method --- pandas-stubs/core/frame.pyi | 2 +- pandas-stubs/core/series.pyi | 2 +- tests/test_io.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index cbaa3096..b3c162da 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -2291,7 +2291,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): @overload def to_json( self, - path_or_buf: FilePath | WriteBuffer[str], + path_or_buf: FilePath | WriteBuffer[str] | WriteBuffer[bytes], orient: JsonFrameOrient | None = ..., date_format: Literal["epoch", "iso"] | None = ..., double_precision: int = ..., diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index c6b7f8d5..4137ea2e 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -594,7 +594,7 @@ class Series(IndexOpsMixin[S1], NDFrame): @overload def to_json( self, - path_or_buf: FilePath | WriteBuffer[str], + path_or_buf: FilePath | WriteBuffer[str] | WriteBuffer[bytes], orient: JsonSeriesOrient | None = ..., date_format: Literal["epoch", "iso"] | None = ..., double_precision: int = ..., diff --git a/tests/test_io.py b/tests/test_io.py index 0397629e..e32f48d4 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -452,6 +452,22 @@ def test_json(): check(assert_type(read_json(bin_json), DataFrame), DataFrame) +def test_json_dataframe_bytes(): + """Test DataFrame.to_json with bytesIO buffer.""" + buffer = io.BytesIO() + df = pd.DataFrame() + check(assert_type(df.to_json(buffer, compression="gzip"), None), type(None)) + check(assert_type(df.to_json(buffer), None), type(None)) + + +def test_json_series_bytes(): + """Test Series.to_json with bytesIO buffer.""" + buffer = io.BytesIO() + sr = pd.Series() + check(assert_type(sr.to_json(buffer, compression="gzip"), None), type(None)) + check(assert_type(sr.to_json(buffer), None), type(None)) + + def test_json_series(): s = DF["a"] with ensure_clean() as path: From 52722b32ad56d0615361d93515f6569e5edc1d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Sat, 12 Apr 2025 13:45:28 -0400 Subject: [PATCH 2/2] GH1179 Lock in pyright version for now --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c22fd5b6..c1477adf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ mypy = "1.15.0" pandas = "2.2.3" pyarrow = ">=10.0.1" pytest = ">=7.1.2" -pyright = ">=1.1.396,!=1.1.398" +pyright = "1.1.397" poethepoet = ">=0.16.5" loguru = ">=0.6.0" typing-extensions = ">=4.4.0"