jorisvandenbossche commented on code in PR #13199:
URL: https://github.com/apache/arrow/pull/13199#discussion_r881414255
##########
python/pyarrow/dataset.py:
##########
@@ -622,26 +624,75 @@ def dataset(source, schema=None, format=None,
filesystem=None,
Examples
--------
+ Creating an example Table:
+
+ >>> import pyarrow as pa
+ >>> import pyarrow.parquet as pq
+ >>> table = pa.table({'year': [2020, 2022, 2021, 2022, 2019, 2021],
+ ... 'n_legs': [2, 2, 4, 4, 5, 100],
+ ... 'animal': ["Flamingo", "Parrot", "Dog", "Horse",
+ ... "Brittle stars", "Centipede"]})
+ >>> pq.write_table(table, "file.parquet")
+
Opening a single file:
- >>> dataset("path/to/file.parquet", format="parquet")
+ >>> import pyarrow.dataset as ds
+ >>> dataset = ds.dataset("file.parquet", format="parquet")
+ >>> dataset.to_table()
+ pyarrow.Table
+ year: int64
+ n_legs: int64
+ animal: string
+ ----
+ year: [[2020,2022,2021,2022,2019,2021]]
+ n_legs: [[2,2,4,4,5,100]]
+ animal: [["Flamingo","Parrot","Dog","Horse","Brittle stars","Centipede"]]
Opening a single file with an explicit schema:
- >>> dataset("path/to/file.parquet", schema=myschema, format="parquet")
+ >>> myschema = pa.schema([
+ ... ('n_legs', pa.int64()),
+ ... ('animal', pa.string())])
+ >>> dataset = ds.dataset("file.parquet", schema=myschema, format="parquet")
+ >>> dataset.to_table()
+ pyarrow.Table
+ n_legs: int64
+ animal: string
+ ----
+ n_legs: [[2,2,4,4,5,100]]
+ animal: [["Flamingo","Parrot","Dog","Horse","Brittle stars","Centipede"]]
Opening a dataset for a single directory:
- >>> dataset("path/to/nyc-taxi/", format="parquet")
- >>> dataset("s3://mybucket/nyc-taxi/", format="parquet")
+ >>> ds.write_dataset(table, "partitioned_dataset", format="parquet",
+ ... partitioning=['year'])
+ >>> dataset = ds.dataset("partitioned_dataset", format="parquet")
+ >>> dataset.to_table()
+ pyarrow.Table
+ n_legs: int64
+ animal: string
+ ----
+ n_legs: [[5],[2],[4,100],[2,4]]
+ animal: [["Brittle stars"],["Flamingo"],...["Parrot","Horse"]]
+
+ For a single directory from a S3 bucket:
+
+ >>> ds.dataset("s3://mybucket/nyc-taxi/", format="parquet")# doctest: +SKIP
Review Comment:
```suggestion
>>> ds.dataset("s3://mybucket/nyc-taxi/", format="parquet") # doctest:
+SKIP
```
##########
python/pyarrow/dataset.py:
##########
@@ -155,18 +155,21 @@ def partitioning(schema=None, field_names=None,
flavor=None,
Specify the Schema for paths like "/2009/June":
- >>> partitioning(pa.schema([("year", pa.int16()), ("month", pa.string())]))
+ >>> import pyarrow as pa
+ >>> import pyarrow.dataset as ds
+ >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+ ... ("month", pa.string())]))
Review Comment:
```suggestion
>>> part = ds.partitioning(pa.schema([("year", pa.int16()),
... ("month", pa.string())]))
```
##########
python/pyarrow/conftest.py:
##########
@@ -0,0 +1,226 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+from pyarrow import Codec
+
+groups = [
+ 'brotli',
+ 'bz2',
+ 'cython',
+ 'dataset',
+ 'hypothesis',
+ 'fastparquet',
+ 'gandiva',
+ 'gdb',
+ 'gzip',
+ 'hdfs',
+ 'large_memory',
+ 'lz4',
+ 'memory_leak',
+ 'nopandas',
+ 'orc',
+ 'pandas',
+ 'parquet',
+ 'parquet_encryption',
+ 'plasma',
+ 's3',
+ 'snappy',
+ 'substrait',
+ 'tensorflow',
+ 'flight',
+ 'slow',
+ 'requires_testing_data',
+ 'zstd',
+]
+
+defaults = {
+ 'brotli': Codec.is_available('brotli'),
+ 'bz2': Codec.is_available('bz2'),
+ 'cython': False,
+ 'dataset': False,
+ 'fastparquet': False,
+ 'flight': False,
+ 'gandiva': False,
+ 'gdb': True,
+ 'gzip': Codec.is_available('gzip'),
+ 'hdfs': False,
+ 'hypothesis': False,
+ 'large_memory': False,
+ 'lz4': Codec.is_available('lz4'),
+ 'memory_leak': False,
+ 'nopandas': False,
+ 'orc': False,
+ 'pandas': False,
+ 'parquet': False,
+ 'parquet_encryption': False,
+ 'plasma': False,
+ 'requires_testing_data': True,
+ 's3': False,
+ 'slow': False,
+ 'snappy': Codec.is_available('snappy'),
+ 'substrait': False,
+ 'tensorflow': False,
+ 'zstd': Codec.is_available('zstd'),
+}
+
+try:
+ import cython # noqa
+ defaults['cython'] = True
+except ImportError:
+ pass
+
+try:
+ import fastparquet # noqa
+ defaults['fastparquet'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.gandiva # noqa
+ defaults['gandiva'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.dataset # noqa
+ defaults['dataset'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.orc # noqa
+ defaults['orc'] = True
+except ImportError:
+ pass
+
+try:
+ import pandas # noqa
+ defaults['pandas'] = True
+except ImportError:
+ defaults['nopandas'] = True
+
+try:
+ import pyarrow.parquet # noqa
+ defaults['parquet'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.parquet.encryption # noqa
+ defaults['parquet_encryption'] = True
+except ImportError:
+ pass
+
+
+try:
+ import pyarrow.plasma # noqa
+ defaults['plasma'] = True
+except ImportError:
+ pass
+
+try:
+ import tensorflow # noqa
+ defaults['tensorflow'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.flight # noqa
+ defaults['flight'] = True
+except ImportError:
+ pass
+
+try:
+ from pyarrow.fs import S3FileSystem # noqa
+ defaults['s3'] = True
+except ImportError:
+ pass
+
+try:
+ from pyarrow.fs import HadoopFileSystem # noqa
+ defaults['hdfs'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.substrait # noqa
+ defaults['substrait'] = True
+except ImportError:
+ pass
+
+
+# Doctest should ignore files for the modules that are not built
+def pytest_ignore_collect(path, config):
+ if config.option.doctestmodules:
+ # don't try to run doctests on the /tests directory
+ if "/pyarrow/tests/" in str(path):
+ return True
+
+ doctest_groups = [
+ 'dataset',
+ 'orc',
+ 'parquet',
+ 'plasma',
+ 'flight',
+ ]
+
+ # handle cuda, flight, etc
+ for group in doctest_groups:
+ if 'pyarrow/{}'.format(group) in str(path) and \
+ not defaults[group]:
+ return True
Review Comment:
```suggestion
if 'pyarrow/{}'.format(group) in str(path):
if not defaults[group]:
return True
```
Possible alternative formatting (which avoids the `\` and the strange
indentation)
##########
python/pyarrow/conftest.py:
##########
@@ -0,0 +1,226 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+from pyarrow import Codec
+
+groups = [
+ 'brotli',
+ 'bz2',
+ 'cython',
+ 'dataset',
+ 'hypothesis',
+ 'fastparquet',
+ 'gandiva',
+ 'gdb',
+ 'gzip',
+ 'hdfs',
+ 'large_memory',
+ 'lz4',
+ 'memory_leak',
+ 'nopandas',
+ 'orc',
+ 'pandas',
+ 'parquet',
+ 'parquet_encryption',
+ 'plasma',
+ 's3',
+ 'snappy',
+ 'substrait',
+ 'tensorflow',
+ 'flight',
+ 'slow',
+ 'requires_testing_data',
+ 'zstd',
+]
+
+defaults = {
+ 'brotli': Codec.is_available('brotli'),
+ 'bz2': Codec.is_available('bz2'),
+ 'cython': False,
+ 'dataset': False,
+ 'fastparquet': False,
+ 'flight': False,
+ 'gandiva': False,
+ 'gdb': True,
+ 'gzip': Codec.is_available('gzip'),
+ 'hdfs': False,
+ 'hypothesis': False,
+ 'large_memory': False,
+ 'lz4': Codec.is_available('lz4'),
+ 'memory_leak': False,
+ 'nopandas': False,
+ 'orc': False,
+ 'pandas': False,
+ 'parquet': False,
+ 'parquet_encryption': False,
+ 'plasma': False,
+ 'requires_testing_data': True,
+ 's3': False,
+ 'slow': False,
+ 'snappy': Codec.is_available('snappy'),
+ 'substrait': False,
+ 'tensorflow': False,
+ 'zstd': Codec.is_available('zstd'),
+}
+
+try:
+ import cython # noqa
+ defaults['cython'] = True
+except ImportError:
+ pass
+
+try:
+ import fastparquet # noqa
+ defaults['fastparquet'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.gandiva # noqa
+ defaults['gandiva'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.dataset # noqa
+ defaults['dataset'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.orc # noqa
+ defaults['orc'] = True
+except ImportError:
+ pass
+
+try:
+ import pandas # noqa
+ defaults['pandas'] = True
+except ImportError:
+ defaults['nopandas'] = True
+
+try:
+ import pyarrow.parquet # noqa
+ defaults['parquet'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.parquet.encryption # noqa
+ defaults['parquet_encryption'] = True
+except ImportError:
+ pass
+
+
+try:
+ import pyarrow.plasma # noqa
+ defaults['plasma'] = True
+except ImportError:
+ pass
+
+try:
+ import tensorflow # noqa
+ defaults['tensorflow'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.flight # noqa
+ defaults['flight'] = True
+except ImportError:
+ pass
+
+try:
+ from pyarrow.fs import S3FileSystem # noqa
+ defaults['s3'] = True
+except ImportError:
+ pass
+
+try:
+ from pyarrow.fs import HadoopFileSystem # noqa
+ defaults['hdfs'] = True
+except ImportError:
+ pass
+
+try:
+ import pyarrow.substrait # noqa
+ defaults['substrait'] = True
+except ImportError:
+ pass
+
+
+# Doctest should ignore files for the modules that are not built
+def pytest_ignore_collect(path, config):
+ if config.option.doctestmodules:
+ # don't try to run doctests on the /tests directory
+ if "/pyarrow/tests/" in str(path):
+ return True
+
+ doctest_groups = [
+ 'dataset',
+ 'orc',
+ 'parquet',
+ 'plasma',
+ 'flight',
+ ]
+
+ # handle cuda, flight, etc
+ for group in doctest_groups:
+ if 'pyarrow/{}'.format(group) in str(path) and \
+ not defaults[group]:
+ return True
+
+ if 'pyarrow/parquet/encryption' in str(path) and \
+ not defaults['parquet_encryption']:
+ return True
+
+ if 'pyarrow/cuda' in str(path):
+ try:
+ import pyarrow.cuda # noqa
+ return False
+ except ImportError:
+ return True
+
+ if 'pyarrow/fs' in str(path):
+ try:
+ from pyarrow.fs import S3FileSystem # noqa
+ return False
+ except ImportError:
+ return True
+
+ return False
+
+
+# Save output files from doctest examples into temp dir
[email protected](autouse=True)
+def _docdir(request):
+
+ # Trigger ONLY for the doctests.
+ doctest_plugin = request.config.pluginmanager.getplugin("doctest")
Review Comment:
Would `request.config.option.doctestmodules` work here as well? (to keep it
similar as how we checked for it above)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]