holoviews.core.data.grid module#

class holoviews.core.data.grid.GridInterface(*, name)[source]#

Bases: DictInterface

Interface for simple dictionary-based dataset format using a compressed representation that uses the cartesian product between key dimensions. As with DictInterface, the dictionary keys correspond to the column (i.e. dimension) names and the values are NumPy arrays representing the values in that column.

To use this compressed format, the key dimensions must be orthogonal to one another with each key dimension specifying an axis of the multidimensional space occupied by the value dimension data. For instance, given an temperature recordings sampled regularly across the earth surface, a list of N unique latitudes and M unique longitudes can specify the position of NxM temperature samples.

Methods

add_dimension(dataset, dimension, dim_pos, ...)

Returns a copy of the data with the dimension values added.

assign(dataset, new_data)

Adds a dictionary containing data for multiple new dimensions to a copy of the dataset.data.

canonicalize(dataset, data[, data_coords, ...])

Canonicalize takes an array of values as input and reorients and transposes it to match the canonical format expected by plotting functions.

compute(dataset)

Converts a lazy Dataset to a non-lazy, in-memory format.

coords(dataset, dim[, ordered, expanded, edges])

Returns the coordinates along a dimension.

dtype(dataset, dimension)

Returns the dtype for the selected dimension.

iloc(dataset, index)

Implements integer indexing on the rows and columns of the data.

isscalar(dataset, dim)

Whether the selected dimension is a scalar value.

length(dataset)

Returns the number of rows in the Dataset.

persist(dataset)

Persists the data backing the Dataset in memory.

range(dataset, dimension)

Computes the minimum and maximum value along a dimension.

reindex(dataset, kdims, vdims)

Reindexes data given new key and value dimensions.

sample(dataset[, samples])

Samples the gridded data into dataset of samples.

shape(dataset[, gridded])

Returns the shape of the data.

validate(dataset[, vdims])

Validation runs after the Dataset has been constructed and should validate that the Dataset is correctly formed and contains all declared dimensions.

values(dataset, dim[, expanded, flat, ...])

Returns the values along a dimension of the dataset.

aggregate

concat

concat_dim

dimension_type

groupby

init

invert_index

irregular

key_select_mask

mask

ndloc

packed

select

sort

Parameter Definitions


classmethod add_dimension(dataset, dimension, dim_pos, values, vdim)[source]#

Returns a copy of the data with the dimension values added.

Parameters:
datasetDataset

The Dataset to add the dimension to

dimensionDimension

The dimension to add

dim_posint

The position in the data to add it to

valuesarray_like

The array of values to add

vdimbool

Whether the data is a value dimension

Returns:
data

A copy of the data with the new dimension

classmethod assign(dataset, new_data)[source]#

Adds a dictionary containing data for multiple new dimensions to a copy of the dataset.data.

Parameters:
datasetDataset

The Dataset to add the dimension to

new_datadict

Dictionary containing new data to add to the Dataset

Returns:
data

A copy of the data with the new data dimensions added

classmethod canonicalize(dataset, data, data_coords=None, virtual_coords=None)[source]#

Canonicalize takes an array of values as input and reorients and transposes it to match the canonical format expected by plotting functions. In certain cases the dimensions defined via the kdims of an Element may not match the dimensions of the underlying data. A set of data_coords may be passed in to define the dimensionality of the data, which can then be used to np.squeeze the data to remove any constant dimensions. If the data is also irregular, i.e. contains multi-dimensional coordinates, a set of virtual_coords can be supplied, required by some interfaces (e.g. xarray) to index irregular datasets with a virtual integer index. This ensures these coordinates are not simply dropped.

classmethod compute(dataset)[source]#

Converts a lazy Dataset to a non-lazy, in-memory format.

Parameters:
datasetDataset

The dataset to compute

Returns:
Dataset

Dataset with non-lazy data

Notes

This is a no-op if the data is already non-lazy.

classmethod coords(dataset, dim, ordered=False, expanded=False, edges=False)[source]#

Returns the coordinates along a dimension. Ordered ensures coordinates are in ascending order and expanded creates ND-array matching the dimensionality of the dataset.

classmethod dtype(dataset, dimension)[source]#

Returns the dtype for the selected dimension.

Parameters:
datasetDataset

The dataset to query

dimensionstr or Dimension

Dimension to return the dtype for

Returns:
numpy.dtype

The dtype of the selected dimension

classmethod iloc(dataset, index)[source]#

Implements integer indexing on the rows and columns of the data.

Parameters:
datasetDataset

The dataset to apply the indexing operation on

indextuple or int

Index specification (row_index, col_index) or row_index

Returns:
data

Indexed data

Notes

Only implement for tabular interfaces.

classmethod isscalar(dataset, dim)[source]#

Whether the selected dimension is a scalar value.

Parameters:
datasetDataset

The dataset to query

dimstr or Dimension

Dimension to check for scalar value

Returns:
bool

Whether the dimension is scalar

classmethod length(dataset)[source]#

Returns the number of rows in the Dataset.

Parameters:
datasetDataset

The dataset to get the length from

Returns:
int

Length of the data

classmethod persist(dataset)[source]#

Persists the data backing the Dataset in memory.

Parameters:
datasetDataset

The dataset to persist

Returns:
Dataset

Dataset with the data persisted to memory

Notes

This is a no-op if the data is already in memory.

classmethod range(dataset, dimension)[source]#

Computes the minimum and maximum value along a dimension.

Parameters:
datasetDataset

The dataset to query

dimensionstr or Dimension

Dimension to compute the range on

Returns:
tuple[Any, Any]

Tuple of (min, max) values

Notes

In the past categorical and string columns were handled by sorting the values and taking the first and last value. This behavior is deprecated and will be removed in 2.0. In future the range for these columns will be returned as (None, None).

classmethod reindex(dataset, kdims, vdims)[source]#

Reindexes data given new key and value dimensions.

classmethod sample(dataset, samples=None)[source]#

Samples the gridded data into dataset of samples.

classmethod shape(dataset, gridded=False)[source]#

Returns the shape of the data.

Parameters:
datasetDataset

The dataset to get the shape from

Returns:
tuple[int, int]

The shape of the data (rows, cols)

classmethod validate(dataset, vdims=True)[source]#

Validation runs after the Dataset has been constructed and should validate that the Dataset is correctly formed and contains all declared dimensions.

classmethod values(dataset, dim, expanded=True, flat=True, compute=True, keep_index=False, canonicalize=True)[source]#

Returns the values along a dimension of the dataset.

Parameters:
datasetDataset

The dataset to query

dimensionstr or Dimension

Dimension to return the values for

expandedbool, default True

When false returns unique values along the dimension

flatbool, default True

Whether to flatten the array

computebool, default True

Whether to load lazy data into memory as a NumPy array

keep_indexbool, default False

Whether to return the data with an index (if present)

Returns:
array_like

Dimension values in the requested format

Notes

The expanded keyword has different behavior for gridded interfaces where it determines whether 1D coordinates are expanded into a multi-dimensional array.