Skip to content
Open
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
22 changes: 22 additions & 0 deletions docs/source/python/dataset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ needed, it only crawls the directory to find all the files:
b: double
c: int64

Note that the schema is inferred from a single file only, it is not unified
across all files. A column that holds only nulls in that file becomes
null-typed for the whole dataset, and reading the other files can then fail
with an ``ArrowTypeError`` if the column has values there. Passing an
explicit ``schema`` avoids this:

.. code-block:: python

>>> pq.write_table(pa.table({"a": [None, None]}),
... base / "null.parquet")
>>> pq.write_table(pa.table({"a": ["x", "y"]}),
... base / "str.parquet")
>>> dataset = ds.dataset([base / "null.parquet", base / "str.parquet"],
... format="parquet")
>>> dataset.schema
a: null
>>> dataset = ds.dataset([base / "null.parquet", base / "str.parquet"],
... format="parquet",
... schema=pa.schema([("a", pa.string())]))
>>> dataset.schema
a: string

Using the :meth:`Dataset.to_table` method we can read the dataset (or a portion
of it) into a pyarrow Table (note that depending on the size of your dataset
this can require a lot of memory, see below on filtering / iterative loading):
Expand Down
6 changes: 5 additions & 1 deletion python/pyarrow/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,11 @@ def dataset(source, schema=None, format=None, filesystem=None,
attempts will raise an error.
schema : Schema, optional
Optionally provide the Schema for the Dataset, in which case it will
not be inferred from the source.
not be inferred from the source. Otherwise the schema is inferred
from a single fragment only: a column that is all null in that
fragment becomes null-typed for the whole dataset, and scanning
files where the column has values can fail with an ArrowTypeError.
Pass ``schema`` explicitly to avoid this.
format : FileFormat or str
Currently "parquet", "ipc"/"arrow"/"feather", "csv", "json", and "orc" are
supported. For Feather, only version 2 files are supported.
Expand Down