Skip to content

Commit

Permalink
fix(python): Allow passing files opened by fsspec in read_parquet (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Apr 19, 2024
1 parent 0c89c71 commit db456e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/io/parquet/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def read_parquet(
memory_map=memory_map,
)

# Read binary types using `read_parquet`
elif isinstance(source, (io.BufferedIOBase, io.RawIOBase, bytes)):
# Read file and bytes inputs using `read_parquet`
elif isinstance(source, (io.IOBase, bytes)):
return _read_parquet_binary(
source,
columns=columns,
Expand Down
15 changes: 15 additions & 0 deletions py-polars/tests/unit/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from decimal import Decimal
from typing import TYPE_CHECKING, cast

import fsspec
import numpy as np
import pandas as pd
import pyarrow as pa
Expand Down Expand Up @@ -680,6 +681,20 @@ def test_read_parquet_binary_file_io(tmp_path: Path) -> None:
assert_frame_equal(out, df)


# https://github.com/pola-rs/polars/issues/15760
@pytest.mark.write_disk()
def test_read_parquet_binary_fsspec(tmp_path: Path) -> None:
tmp_path.mkdir(exist_ok=True)

df = pl.DataFrame({"a": [1, 2, 3]})
file_path = tmp_path / "test.parquet"
df.write_parquet(file_path)

with fsspec.open(file_path) as f:
out = pl.read_parquet(f)
assert_frame_equal(out, df)


def test_read_parquet_binary_bytes_io() -> None:
df = pl.DataFrame({"a": [1, 2, 3]})
f = io.BytesIO()
Expand Down

0 comments on commit db456e1

Please sign in to comment.