From 44298d9a1906c2e000a8873dad555295a5350c9d Mon Sep 17 00:00:00 2001 From: Bela Stoyan Date: Tue, 10 Sep 2024 10:26:27 +0200 Subject: [PATCH] use IO[bytes] instead of BytesIO --- py-polars/polars/dataframe/frame.py | 2 +- py-polars/tests/unit/io/test_parquet.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index 2d8710b9f431..00fe52cba54a 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -3638,7 +3638,7 @@ def write_ipc_stream( def write_parquet( self, - file: str | Path | BytesIO, + file: str | Path | IO[bytes], *, compression: ParquetCompression = "zstd", compression_level: int | None = None, diff --git a/py-polars/tests/unit/io/test_parquet.py b/py-polars/tests/unit/io/test_parquet.py index 3da465561bd1..170cc2a015be 100644 --- a/py-polars/tests/unit/io/test_parquet.py +++ b/py-polars/tests/unit/io/test_parquet.py @@ -1891,3 +1891,16 @@ def test_concat_multiple_inmem() -> None: assert_frame_equal(pl.read_parquet([fb, gb]), dfs) assert_frame_equal(pl.read_parquet([fb, gb], use_pyarrow=True), dfs) + + +@pytest.mark.write_disk +def test_write_binary_open_file(tmp_path: Path) -> None: + df = pl.DataFrame({"a": [1, 2, 3]}) + + path = tmp_path / "test.parquet" + + with path.open("wb") as f_write: + df.write_parquet(f_write) + + out = pl.read_parquet(path) + assert_frame_equal(out, df)