Dataset API#

Constructor#

Dataset

A Dataset is a distributed data collection for data loading and processing.

Basic Transformations#

Dataset.map

Apply the given function to each row of this dataset.

Dataset.map_batches

Apply the given function to batches of data.

Dataset.flat_map

Apply the given function to each row and then flatten results.

Dataset.filter

Filter out rows that don't satisfy the given predicate.

Dataset.add_column

Add the given column to the dataset.

Dataset.drop_columns

Drop one or more columns from the dataset.

Dataset.select_columns

Select one or more columns from the dataset.

Dataset.random_sample

Returns a new Dataset containing a random fraction of the rows.

Dataset.limit

Truncate the dataset to the first limit rows.

Sorting, Shuffling, Repartitioning#

Dataset.sort

Sort the dataset by the specified key column or key function.

Dataset.random_shuffle

Randomly shuffle the rows of this Dataset.

Dataset.randomize_block_order

Randomly shuffle the blocks of this Dataset.

Dataset.repartition

Repartition the Dataset into exactly this number of blocks.

Splitting and Merging Datasets#

Dataset.split

Materialize and split the dataset into n disjoint pieces.

Dataset.split_at_indices

Materialize and split the dataset at the given indices (like np.split).

Dataset.split_proportionately

Materialize and split the dataset using proportions.

Dataset.streaming_split

Returns n DataIterators that can be used to read disjoint subsets of the dataset in parallel.

Dataset.train_test_split

Materialize and split the dataset into train and test subsets.

Dataset.union

Concatenate Datasets across rows.

Dataset.zip

Materialize and zip the columns of this dataset with the columns of another.

Grouped and Global Aggregations#

Dataset.groupby

Group rows of a Dataset according to a column.

Dataset.unique

List the unique elements in a given column.

Dataset.aggregate

Aggregate values using one or more functions.

Dataset.sum

Compute the sum of one or more columns.

Dataset.min

Return the minimum of one or more columns.

Dataset.max

Return the maximum of one or more columns.

Dataset.mean

Compute the mean of one or more columns.

Dataset.std

Compute the standard deviation of one or more columns.

Consuming Data#

Dataset.show

Print up to the given number of rows from the Dataset.

Dataset.take

Return up to limit rows from the Dataset.

Dataset.take_batch

Return up to batch_size rows from the Dataset in a batch.

Dataset.take_all

Return all of the rows in this Dataset.

Dataset.iterator

Return a DataIterator over this dataset.

Dataset.iter_rows

Return an iterable over the rows in this dataset.

Dataset.iter_batches

Return an iterable over batches of data.

Dataset.iter_torch_batches

Return an iterable over batches of data represented as Torch tensors.

Dataset.iter_tf_batches

Return an iterable over batches of data represented as TensorFlow tensors.

I/O and Conversion#

Dataset.write_parquet

Writes the Dataset to parquet files under the provided path.

Dataset.write_json

Writes the Dataset to JSON and JSONL files.

Dataset.write_csv

Writes the Dataset to CSV files.

Dataset.write_numpy

Writes a column of the Dataset to .npy files.

Dataset.write_tfrecords

Write the Dataset to TFRecord files.

Dataset.write_webdataset

Writes the dataset to WebDataset files.

Dataset.write_mongo

Writes the Dataset to a MongoDB database.

Dataset.write_datasource

Writes the dataset to a custom Datasource.

Dataset.to_torch

Return a Torch IterableDataset over this Dataset.

Dataset.to_tf

Return a TensorFlow Dataset over this Dataset.

Dataset.to_dask

Convert this Dataset into a Dask DataFrame.

Dataset.to_mars

Convert this Dataset into a Mars DataFrame.

Dataset.to_modin

Convert this Dataset into a Modin DataFrame.

Dataset.to_spark

Convert this Dataset into a Spark DataFrame.

Dataset.to_pandas

Convert this Dataset to a single pandas DataFrame.

Dataset.to_pandas_refs

Converts this Dataset into a distributed set of Pandas dataframes.

Dataset.to_numpy_refs

Converts this Dataset into a distributed set of NumPy ndarrays or dictionary of NumPy ndarrays.

Dataset.to_arrow_refs

Convert this Dataset into a distributed set of PyArrow tables.

Inspecting Metadata#

Dataset.count

Count the number of records in the dataset.

Dataset.columns

Returns the columns of this Dataset.

Dataset.schema

Return the schema of the dataset.

Dataset.num_blocks

Return the number of blocks of this Dataset.

Dataset.size_bytes

Return the in-memory size of the dataset.

Dataset.input_files

Return the list of input files for the dataset.

Dataset.stats

Returns a string containing execution timing information.

Dataset.get_internal_block_refs

Get a list of references to the underlying blocks of this dataset.

Execution#

Dataset.materialize

Execute and materialize this dataset into object store memory.

Internals#

block.Block

alias of Union[pyarrow.Table, pandas.DataFrame]

block.BlockExecStats

Execution stats for this block.

block.BlockMetadata

Metadata about the block.

block.BlockAccessor

Provides accessor methods for a specific block.