Skip to content
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

Bugfix: check for file-like objects in from_parquet #923

Merged
merged 3 commits into from
Jun 15, 2021
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
6 changes: 5 additions & 1 deletion src/awkward/operations/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,11 @@ def from_parquet(
relative_to = source
source = sorted(glob.glob(source + "/**/*.parquet", recursive=True))

if not isinstance(source, str) and isinstance(source, Iterable):
if (
not isinstance(source, str)
and isinstance(source, Iterable)
and not hasattr(source, "read")
):
source = [_regularize_path(x) for x in source]
if relative_to is None:
relative_to = os.path.commonpath(source)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_0921-parquet-from-file-like.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

from __future__ import absolute_import

import io
import pytest # noqa: F401
import numpy as np # noqa: F401
import awkward as ak # noqa: F401


pytest.importorskip("pyarrow.parquet")


def test():
array = ak.Array([1, 2, 3])
file_ = io.BytesIO()
ak.to_parquet(array, file_)
file_.seek(0)

array_from_file = ak.from_parquet(file_)
assert ak.to_list(array) == ak.to_list(array_from_file)