Skip to content

Commit 602401a

Browse files
GH1179 Add WriteBuffer[bytes] to to_json method (#1183)
* GH1179 Add WriteBuffer[bytes] to to_json method * GH1179 Lock in pyright version for now
1 parent 59e8c0a commit 602401a

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

pandas-stubs/core/frame.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
22912291
@overload
22922292
def to_json(
22932293
self,
2294-
path_or_buf: FilePath | WriteBuffer[str],
2294+
path_or_buf: FilePath | WriteBuffer[str] | WriteBuffer[bytes],
22952295
orient: JsonFrameOrient | None = ...,
22962296
date_format: Literal["epoch", "iso"] | None = ...,
22972297
double_precision: int = ...,

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
594594
@overload
595595
def to_json(
596596
self,
597-
path_or_buf: FilePath | WriteBuffer[str],
597+
path_or_buf: FilePath | WriteBuffer[str] | WriteBuffer[bytes],
598598
orient: JsonSeriesOrient | None = ...,
599599
date_format: Literal["epoch", "iso"] | None = ...,
600600
double_precision: int = ...,

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mypy = "1.15.0"
3939
pandas = "2.2.3"
4040
pyarrow = ">=10.0.1"
4141
pytest = ">=7.1.2"
42-
pyright = ">=1.1.396,!=1.1.398"
42+
pyright = "1.1.397"
4343
poethepoet = ">=0.16.5"
4444
loguru = ">=0.6.0"
4545
typing-extensions = ">=4.4.0"

tests/test_io.py

+16
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,22 @@ def test_json():
452452
check(assert_type(read_json(bin_json), DataFrame), DataFrame)
453453

454454

455+
def test_json_dataframe_bytes():
456+
"""Test DataFrame.to_json with bytesIO buffer."""
457+
buffer = io.BytesIO()
458+
df = pd.DataFrame()
459+
check(assert_type(df.to_json(buffer, compression="gzip"), None), type(None))
460+
check(assert_type(df.to_json(buffer), None), type(None))
461+
462+
463+
def test_json_series_bytes():
464+
"""Test Series.to_json with bytesIO buffer."""
465+
buffer = io.BytesIO()
466+
sr = pd.Series()
467+
check(assert_type(sr.to_json(buffer, compression="gzip"), None), type(None))
468+
check(assert_type(sr.to_json(buffer), None), type(None))
469+
470+
455471
def test_json_series():
456472
s = DF["a"]
457473
with ensure_clean() as path:

0 commit comments

Comments
 (0)