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/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" 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: