| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/pyarrow.dataset.InMemoryDataset.html | [Back] [Original] |
Bases: Dataset
A Dataset wrapping in-memory data.
RecordBatch, Table, list, tupleThe data for this dataset. Can be a RecordBatch, Table, list of RecordBatch/Table, iterable of RecordBatch, or a RecordBatchReader If an iterable is provided, the schema must also be provided.
Schema, optionalOnly required if passing an iterable as the source
Methods
|
|
|
Count rows matching the scanner filter. |
|
Apply a row filter to the dataset. |
|
Returns an iterator over the fragments in this dataset. |
|
Load the first N rows of the dataset. |
|
Perform a join between this dataset and another one. |
|
Perform an asof join between this dataset and another one. |
|
Return a copy of this Dataset with a different schema. |
|
Build a scan operation against the dataset. |
|
Sort the Dataset by one or multiple columns. |
|
Select rows of data by index. |
|
Read the dataset as materialized record batches. |
|
Read the dataset to an Arrow table. |
Attributes
An Expression which evaluates to true for all data viewed by this Dataset. |
|
The common schema of the full Dataset |
Count rows matching the scanner filter.
Expression, default NoneScan will return only the rows matching the filter. If possible the predicate will be pushed down to exploit the partition information or internal metadata found in the data source, e.g. Parquet statistics. Otherwise filters the loaded RecordBatches before yielding them.
int, default 131_072The maximum row count for scanned record batches. If scanned record batches are overflowing memory then this method can be called to reduce their size.
int, default 16The number of batches to read ahead in a file. This might not work for all file formats. Increasing this number will increase RAM usage but could also improve IO utilization.
int, default 4The number of files to read ahead. Increasing this number will increase RAM usage but could also improve IO utilization.
FragmentScanOptions, default NoneOptions specific to a particular scan and fragment type, which can change between different scans of the same dataset.
TrueIf enabled, then maximum parallelism will be used determined by the number of available CPU cores.
TrueIf enabled, metadata may be cached when scanning to speed up repeated scans.
MemoryPool, default NoneFor memory allocations, if required. If not specified, uses the default pool.
intApply a row filter to the dataset.
ExpressionThe filter that should be applied to the dataset.
Returns an iterator over the fragments in this dataset.
Expression, default NoneReturn fragments matching the optional filter, either using the partition_expression or internal information like Parquets statistics.
FragmentLoad the first N rows of the dataset.
intThe number of rows to load.
list of str, default NoneThe columns to project. This can be a list of column names to include (order and duplicates will be preserved), or a dictionary with {new_column_name: expression} values for more advanced projections.
The list of columns or expressions may use the special fields __batch_index (the index of the batch within the fragment), __fragment_index (the index of the fragment within the dataset), __last_in_fragment (whether the batch is last in fragment), and __filename (the name of the source file or a description of the source fragment).
The columns will be passed down to Datasets and corresponding data fragments to avoid loading, copying, and deserializing columns that will not be required further down the compute chain. By default all of the available columns are projected. Raises an exception if any of the referenced column names does not exist in the datasets Schema.
Expression, default NoneScan will return only the rows matching the filter. If possible the predicate will be pushed down to exploit the partition information or internal metadata found in the data source, e.g. Parquet statistics. Otherwise filters the loaded RecordBatches before yielding them.
int, default 131_072The maximum row count for scanned record batches. If scanned record batches are overflowing memory then this method can be called to reduce their size.
int, default 16The number of batches to read ahead in a file. This might not work for all file formats. Increasing this number will increase RAM usage but could also improve IO utilization.
int, default 4The number of files to read ahead. Increasing this number will increase RAM usage but could also improve IO utilization.
FragmentScanOptions, default NoneOptions specific to a particular scan and fragment type, which can change between different scans of the same dataset.
TrueIf enabled, then maximum parallelism will be used determined by the number of available CPU cores.
TrueIf enabled, metadata may be cached when scanning to speed up repeated scans.
MemoryPool, default NoneFor memory allocations, if required. If not specified, uses the default pool.
TablePerform a join between this dataset and another one.
Result of the join will be a new dataset, where further operations can be applied.
The dataset to join to the current one, acting as the right dataset in the join operation.
str or list[str]The columns from current dataset that should be used as keys of the join operation left side.
str or list[str], default NoneThe columns from the right_dataset that should be used as keys
on the join operation right side.
When None use the same key names as the left dataset.
str, default left outerThe kind of join that should be performed, one of (left semi, right semi, left anti, right anti, inner, left outer, right outer, full outer)
str, default NoneWhich suffix to add to right column names. This prevents confusion when the columns in left and right datasets have colliding names.
str, default NoneWhich suffix to add to the left column names. This prevents confusion when the columns in left and right datasets have colliding names.
TrueIf the duplicated keys should be omitted from one of the sides in the join result.
TrueWhenever to use multithreading or not.
Perform an asof join between this dataset and another one.
This is similar to a left-join except that we match on nearest key rather than equal keys. Both datasets must be sorted by the key. This type of join is most useful for time series data that are not perfectly aligned.
Optionally match on equivalent keys with by before searching with on.
Result of the join will be a new Dataset, where further operations can be applied.
The dataset to join to the current one, acting as the right dataset in the join operation.
strThe column from current dataset that should be used as the on key of the join operation left side.
An inexact match is used on the on key, i.e. a row is considered a
match if and only if right.on - left.on is in the range
[min(0, tolerance), max(0, tolerance)].
The input table must be sorted by the on key. Must be a single field of a common type.
Currently, the on key must be an integer, date, or timestamp type.
str or list[str]The columns from current dataset that should be used as the keys of the join operation left side. The join operation is then done only for the matches in these columns.
intThe tolerance for inexact on key matching. A right row is considered
a match with a left row if right.on - left.on is in the range
[min(0, tolerance), max(0, tolerance)]. tolerance may be:
negative, in which case a past-as-of-join occurs
(match iff tolerance <= right.on - left.on <= 0);
or positive, in which case a future-as-of-join occurs
(match iff 0 <= right.on - left.on <= tolerance);
or zero, in which case an exact-as-of-join occurs
(match iff right.on == left.on).
The tolerance is interpreted in the same units as the on key.
str or list[str], default NoneThe columns from the right_dataset that should be used as the on key
on the join operation right side.
When None use the same key name as the left dataset.
str or list[str], default NoneThe columns from the right_dataset that should be used as by keys
on the join operation right side.
When None use the same key names as the left dataset.
An Expression which evaluates to true for all data viewed by this Dataset.
Return a copy of this Dataset with a different schema.
The copy will view the same Fragments. If the new schema is not compatible with the original datasets schema then an error will be raised.
SchemaThe new dataset schema.
Build a scan operation against the dataset.
Data is not loaded immediately. Instead, this produces a Scanner, which exposes further operations (e.g. loading all data as a table, counting rows).
See the Scanner.from_dataset() method for further information.
list of str, default NoneThe columns to project. This can be a list of column names to include (order and duplicates will be preserved), or a dictionary with {new_column_name: expression} values for more advanced projections.
The list of columns or expressions may use the special fields __batch_index (the index of the batch within the fragment), __fragment_index (the index of the fragment within the dataset), __last_in_fragment (whether the batch is last in fragment), and __filename (the name of the source file or a description of the source fragment).
The columns will be passed down to Datasets and corresponding data fragments to avoid loading, copying, and deserializing columns that will not be required further down the compute chain. By default all of the available columns are projected. Raises an exception if any of the referenced column names does not exist in the datasets Schema.
Expression, default NoneScan will return only the rows matching the filter. If possible the predicate will be pushed down to exploit the partition information or internal metadata found in the data source, e.g. Parquet statistics. Otherwise filters the loaded RecordBatches before yielding them.
int, default 131_072The maximum row count for scanned record batches. If scanned record batches are overflowing memory then this method can be called to reduce their size.
int, default 16The number of batches to read ahead in a file. This might not work for all file formats. Increasing this number will increase RAM usage but could also improve IO utilization.
int, default 4The number of files to read ahead. Increasing this number will increase RAM usage but could also improve IO utilization.
FragmentScanOptions, default NoneOptions specific to a particular scan and fragment type, which can change between different scans of the same dataset.
TrueIf enabled, then maximum parallelism will be used determined by the number of available CPU cores.
TrueIf enabled, metadata may be cached when scanning to speed up repeated scans.
MemoryPool, default NoneFor memory allocations, if required. If not specified, uses the default pool.
ScannerExamples
>>> import pyarrow as pa
>>> 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"]})
>>>
>>> import pyarrow.parquet as pq
>>> pq.write_table(table, "dataset_scanner.parquet")
>>> import pyarrow.dataset as ds
>>> dataset = ds.dataset("dataset_scanner.parquet")
Selecting a subset of the columns:
>>> dataset.scanner(columns=["year", "n_legs"]).to_table()
pyarrow.Table
year: int64
n_legs: int64
----
year: [[2020,2022,2021,2022,2019,2021]]
n_legs: [[2,2,4,4,5,100]]
Projecting selected columns using an expression:
>>> dataset.scanner(columns={
... "n_legs_uint": ds.field("n_legs").cast("uint8"),
... }).to_table()
pyarrow.Table
n_legs_uint: uint8
----
n_legs_uint: [[2,2,4,4,5,100]]
Filtering rows while scanning:
>>> dataset.scanner(filter=ds.field("year") > 2020).to_table()
pyarrow.Table
year: int64
n_legs: int64
animal: string
----
year: [[2022,2021,2022,2021]]
n_legs: [[2,4,4,100]]
animal: [["Parrot","Dog","Horse","Centipede"]]
The common schema of the full Dataset
Sort the Dataset by one or multiple columns.
str or list[tuple(name, order, null_placement)]Name of the column to use to sort (ascending), or a list of multiple sorting conditions where each entry is a tuple with column name and sorting order (ascending or descending) and nulls and NaNs are placed at the start or at the end (at_start or at_end)
dict, optionalAdditional sorting options.
As allowed by SortOptions
InMemoryDatasetA new dataset sorted according to the sort keys.
Select rows of data by index.
Array or array-likeindices of rows to select in the dataset.
list of str, default NoneThe columns to project. This can be a list of column names to include (order and duplicates will be preserved), or a dictionary with {new_column_name: expression} values for more advanced projections.
The list of columns or expressions may use the special fields __batch_index (the index of the batch within the fragment), __fragment_index (the index of the fragment within the dataset), __last_in_fragment (whether the batch is last in fragment), and __filename (the name of the source file or a description of the source fragment).
The columns will be passed down to Datasets and corresponding data fragments to avoid loading, copying, and deserializing columns that will not be required further down the compute chain. By default all of the available columns are projected. Raises an exception if any of the referenced column names does not exist in the datasets Schema.
Expression, default NoneScan will return only the rows matching the filter. If possible the predicate will be pushed down to exploit the partition information or internal metadata found in the data source, e.g. Parquet statistics. Otherwise filters the loaded RecordBatches before yielding them.
int, default 131_072The maximum row count for scanned record batches. If scanned record batches are overflowing memory then this method can be called to reduce their size.
int, default 16The number of batches to read ahead in a file. This might not work for all file formats. Increasing this number will increase RAM usage but could also improve IO utilization.
int, default 4The number of files to read ahead. Increasing this number will increase RAM usage but could also improve IO utilization.
FragmentScanOptions, default NoneOptions specific to a particular scan and fragment type, which can change between different scans of the same dataset.
TrueIf enabled, then maximum parallelism will be used determined by the number of available CPU cores.
TrueIf enabled, metadata may be cached when scanning to speed up repeated scans.
MemoryPool, default NoneFor memory allocations, if required. If not specified, uses the default pool.
TableRead the dataset as materialized record batches.
list of str, default NoneThe columns to project. This can be a list of column names to include (order and duplicates will be preserved), or a dictionary with {new_column_name: expression} values for more advanced projections.
The list of columns or expressions may use the special fields __batch_index (the index of the batch within the fragment), __fragment_index (the index of the fragment within the dataset), __last_in_fragment (whether the batch is last in fragment), and __filename (the name of the source file or a description of the source fragment).
The columns will be passed down to Datasets and corresponding data fragments to avoid loading, copying, and deserializing columns that will not be required further down the compute chain. By default all of the available columns are projected. Raises an exception if any of the referenced column names does not exist in the datasets Schema.
Expression, default NoneScan will return only the rows matching the filter. If possible the predicate will be pushed down to exploit the partition information or internal metadata found in the data source, e.g. Parquet statistics. Otherwise filters the loaded RecordBatches before yielding them.
int, default 131_072The maximum row count for scanned record batches. If scanned record batches are overflowing memory then this method can be called to reduce their size.
int, default 16The number of batches to read ahead in a file. This might not work for all file formats. Increasing this number will increase RAM usage but could also improve IO utilization.
int, default 4The number of files to read ahead. Increasing this number will increase RAM usage but could also improve IO utilization.
FragmentScanOptions, default NoneOptions specific to a particular scan and fragment type, which can change between different scans of the same dataset.
TrueIf enabled, then maximum parallelism will be used determined by the number of available CPU cores.
TrueIf enabled, metadata may be cached when scanning to speed up repeated scans.
MemoryPool, default NoneFor memory allocations, if required. If not specified, uses the default pool.
RecordBatchRead the dataset to an Arrow table.
Note that this method reads all the selected data from the dataset into memory.
list of str, default NoneThe columns to project. This can be a list of column names to include (order and duplicates will be preserved), or a dictionary with {new_column_name: expression} values for more advanced projections.
The list of columns or expressions may use the special fields __batch_index (the index of the batch within the fragment), __fragment_index (the index of the fragment within the dataset), __last_in_fragment (whether the batch is last in fragment), and __filename (the name of the source file or a description of the source fragment).
The columns will be passed down to Datasets and corresponding data fragments to avoid loading, copying, and deserializing columns that will not be required further down the compute chain. By default all of the available columns are projected. Raises an exception if any of the referenced column names does not exist in the datasets Schema.
Expression, default NoneScan will return only the rows matching the filter. If possible the predicate will be pushed down to exploit the partition information or internal metadata found in the data source, e.g. Parquet statistics. Otherwise filters the loaded RecordBatches before yielding them.
int, default 131_072The maximum row count for scanned record batches. If scanned record batches are overflowing memory then this method can be called to reduce their size.
int, default 16The number of batches to read ahead in a file. This might not work for all file formats. Increasing this number will increase RAM usage but could also improve IO utilization.
int, default 4The number of files to read ahead. Increasing this number will increase RAM usage but could also improve IO utilization.
FragmentScanOptions, default NoneOptions specific to a particular scan and fragment type, which can change between different scans of the same dataset.
TrueIf enabled, then maximum parallelism will be used determined by the number of available CPU cores.
TrueIf enabled, metadata may be cached when scanning to speed up repeated scans.
MemoryPool, default NoneFor memory allocations, if required. If not specified, uses the default pool.
Table| Web Proxy Viewer | New URL | Original Page |