Skip to content

GH1179 Add WriteBuffer[bytes] to to_json method #1183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down