Skip to content

Commit 2a0d375

Browse files
authored
Fix WriteExcelBuffer to be compatible with io.BinaryIO. (#912)
1 parent d89824b commit 2a0d375

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pandas-stubs/_typing.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class ReadCsvBuffer(ReadBuffer[AnyStr_cov], Protocol[AnyStr_cov]):
432432
def closed(self) -> bool: ...
433433

434434
class WriteExcelBuffer(WriteBuffer[bytes], Protocol):
435-
def truncate(self, size: int | None = ...) -> int: ...
435+
def truncate(self, size: int | None = ..., /) -> int: ...
436436

437437
FilePath: TypeAlias = str | PathLike[str]
438438

tests/test_io.py

+10
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,16 @@ def test_excel_writer():
10331033
check(assert_type(ef.close(), None), type(None))
10341034

10351035

1036+
def test_excel_writer_io():
1037+
buffer = io.BytesIO()
1038+
with pd.ExcelWriter(buffer) as writer:
1039+
DF.to_excel(writer, sheet_name="A")
1040+
1041+
ef = pd.ExcelFile(buffer)
1042+
check(assert_type(ef, pd.ExcelFile), pd.ExcelFile)
1043+
check(assert_type(read_excel(ef, sheet_name="A"), DataFrame), DataFrame)
1044+
1045+
10361046
def test_excel_writer_engine():
10371047
with ensure_clean(".xlsx") as path:
10381048
with pd.ExcelWriter(path, engine="auto") as ew:

0 commit comments

Comments
 (0)