holoviews.core.data package#
Submodules#
- holoviews.core.data.array module
- holoviews.core.data.cudf module
- holoviews.core.data.dask module
- holoviews.core.data.dictionary module
- holoviews.core.data.grid module
- holoviews.core.data.ibis module
- holoviews.core.data.image module
- holoviews.core.data.interface module
- holoviews.core.data.multipath module
- holoviews.core.data.pandas module
- holoviews.core.data.spatialpandas module
SpatialPandasInterface
SpatialPandasInterface.applies()
SpatialPandasInterface.as_dframe()
SpatialPandasInterface.base_interface
SpatialPandasInterface.isscalar()
SpatialPandasInterface.length()
SpatialPandasInterface.loaded()
SpatialPandasInterface.select()
SpatialPandasInterface.select_mask()
SpatialPandasInterface.shape()
SpatialPandasInterface.split()
SpatialPandasInterface.values()
from_multi()
from_shapely()
geom_array_to_array()
geom_to_array()
geom_to_holes()
get_geom_type()
get_value_array()
to_geom_dict()
to_spatialpandas()
- holoviews.core.data.spatialpandas_dask module
- holoviews.core.data.util module
- holoviews.core.data.xarray module
Module contents#
- class holoviews.core.data.DataConversion(element)[source]#
Bases:
object
DataConversion is a very simple container object which can be given an existing Dataset Element and provides methods to convert the Dataset into most other Element types.
- class holoviews.core.data.Dataset(data=None, kdims=None, vdims=None, **kwargs)[source]#
Bases:
Element
Dataset provides a general baseclass for Element types that contain structured data and supports a range of data formats.
The Dataset class supports various methods offering a consistent way of working with the stored data regardless of the storage format used. These operations include indexing, selection and various ways of aggregating or collapsing the data with a supplied function.
Parameter Definitions
Parameters inherited from:
holoviews.core.dimension.LabelledData
: labelholoviews.core.dimension.Dimensioned
: cdims, kdims, vdimsgroup = String(constant=True, default='Dataset', label='Group')
A string describing the data wrapped by the object.
datatype = List(bounds=(0, None), default=['dataframe', 'dictionary', 'grid', 'xarray', 'multitabular', 'spatialpandas', 'dask_spatialpandas', 'dask', 'cuDF', 'array', 'ibis'], label='Datatype')
A priority list of the data types to be used for storage on the .data attribute. If the input supplied to the element constructor cannot be put into the requested format, the next format listed will be used until a suitable format is found (or the data fails to be understood).
- add_dimension(dimension, dim_pos, dim_val, vdim=False, **kwargs)[source]#
Adds a dimension and its values to the Dataset
Requires the dimension name or object, the desired position in the key dimensions and a key value scalar or array of values, matching the length or shape of the Dataset.
Parameters#
- dimension
Dimension or dimension spec to add
- dim_posint
Integer index to insert dimension at
- dim_valscalar or ndarray
Dimension value(s) to add
- vdim
Disabled, this type does not have value dimensions
- **kwargs
Keyword arguments passed to the cloned element
Returns#
Cloned object containing the new dimension
- aggregate(dimensions=None, function=None, spreadfn=None, **kwargs)[source]#
Aggregates data on the supplied dimensions.
Aggregates over the supplied key dimensions with the defined function or dim_transform specified as a tuple of the transformed dimension name and dim transform.
Parameters#
- dimensions
Dimension(s) to aggregate on Default to all key dimensions
- function
Aggregation function or transform to apply Supports both simple functions and dimension transforms
- spreadfn
Secondary reduction to compute value spread Useful for computing a confidence interval, spread, or standard deviation.
- **kwargs
Keyword arguments either passed to the aggregation function or to create new names for the transformed variables
Returns#
Returns the aggregated Dataset
- clone(data=None, shared_data=True, new_type=None, link=True, *args, **overrides)[source]#
Clones the object, overriding data and parameters.
Parameters#
- data
New data replacing the existing data
- shared_databool, optional
Whether to use existing data
- new_typeoptional
Type to cast object to
- linkbool, optional
Whether clone should be linked Determines whether Streams and Links attached to original object will be inherited.
- *args
Additional arguments to pass to constructor
- **overrides
New keyword arguments to pass to constructor
Returns#
Cloned object
- closest(coords=None, **kwargs)[source]#
Snaps coordinate(s) to closest coordinate in Dataset
Parameters#
- coords
List of coordinates expressed as tuples
- **kwargs
Coordinates defined as keyword pairs
Returns#
List of tuples of the snapped coordinates
Raises#
- NotImplementedError
Raised if snapping is not supported
- columns(dimensions=None)[source]#
Convert dimension values to a dictionary.
Returns a dictionary of column arrays along each dimension of the element.
Parameters#
- dimensions
Dimensions to return as columns
Returns#
Dictionary of arrays for each dimension
- compute()[source]#
Computes the data to a data format that stores the daata in memory, e.g. a Dask dataframe or array is converted to a Pandas DataFrame or NumPy array.
Returns#
Dataset with the data stored in in-memory format
- property dataset#
The Dataset that this object was created from
- dframe(dimensions=None, multi_index=False)[source]#
Convert dimension values to DataFrame.
Returns a pandas dataframe of columns along each dimension, either completely flat or indexed by key dimensions.
Parameters#
- dimensions
Dimensions to return as columns
- multi_index
Convert key dimensions to (multi-)index
Returns#
DataFrame of columns corresponding to each dimension
- dimension_values(dimension, expanded=True, flat=True)[source]#
Return the values along the requested dimension.
Parameters#
- dimension
The dimension to return values for
- expandedbool, optional
Whether to expand values Whether to return the expanded values, behavior depends on the type of data:
Columnar: If false returns unique values
Geometry: If false returns scalar values per geometry
Gridded: If false returns 1D coordinates
- flatbool, optional
Whether to flatten array
Returns#
NumPy array of values along the requested dimension
- get_dimension_type(dim)[source]#
Get the type of the requested dimension.
Type is determined by Dimension.type attribute or common type of the dimension values, otherwise None.
Parameters#
- dimension
Dimension to look up by name or by index
Returns#
Declared type of values along the dimension
- groupby(dimensions=None, container_type=<class 'holoviews.core.spaces.HoloMap'>, group_type=None, dynamic=False, **kwargs)[source]#
Groups object by one or more dimensions
Applies groupby operation over the specified dimensions returning an object of type container_type (expected to be dictionary-like) containing the groups.
Parameters#
- dimensions
Dimension(s) to group by
- container_type
Type to cast group container to
- group_type
Type to cast each group to
- dynamic
Whether to return a DynamicMap
- **kwargs
Keyword arguments to pass to each group
Returns#
Returns object of supplied container_type containing the groups. If dynamic=True returns a DynamicMap instead.
- property iloc#
Returns iloc indexer with support for columnar indexing.
Returns an iloc object providing a convenient interface to slice and index into the Dataset using row and column indices. Allow selection by integer index, slice and list of integer indices and boolean arrays.
Examples :
Index the first row and column:
dataset.iloc[0, 0]
Select rows 1 and 2 with a slice:
dataset.iloc[1:3, :]
Select with a list of integer coordinates:
dataset.iloc[[0, 2, 3]]
- map(map_fn, specs=None, clone=True)[source]#
Map a function to all objects matching the specs
Recursively replaces elements using a map function when the specs apply, by default applies to all objects, e.g. to apply the function to all contained Curve objects:
dmap.map(fn, hv.Curve)
Parameters#
map_fn : Function to apply to each object specs : List of specs to match
List of types, functions or type[.group][.label] specs to select objects to return, by default applies to all objects.
- clone
Whether to clone the object or transform inplace
Returns#
Returns the object after the map_fn has been applied
- property ndloc#
Returns ndloc indexer with support for gridded indexing.
Returns an ndloc object providing nd-array like indexing for gridded datasets. Follows NumPy array indexing conventions, allowing for indexing, slicing and selecting a list of indices on multi-dimensional arrays using integer indices. The order of array indices is inverted relative to the Dataset key dimensions, e.g. an Image with key dimensions ‘x’ and ‘y’ can be indexed with
image.ndloc[iy, ix]
, whereiy
andix
are integer indices along the y and x dimensions.Examples :
Index value in 2D array:
dataset.ndloc[3, 1]
Slice along y-axis of 2D array:
dataset.ndloc[2:5, :]
Vectorized (non-orthogonal) indexing along x- and y-axes:
dataset.ndloc[[1, 2, 3], [0, 2, 3]]
- options(*args, clone=True, **kwargs)[source]#
Applies simplified option definition returning a new object.
Applies options on an object or nested group of objects in a flat format returning a new object with the options applied. If the options are to be set directly on the object a simple format may be used, e.g.:
obj.options(cmap=’viridis’, show_title=False)
If the object is nested the options must be qualified using a type[.group][.label] specification, e.g.:
obj.options(‘Image’, cmap=’viridis’, show_title=False)
or using:
obj.options({‘Image’: dict(cmap=’viridis’, show_title=False)})
Identical to the .opts method but returns a clone of the object by default.
Parameters#
- *args: Sets of options to apply to object
Supports a number of formats including lists of Options objects, a type[.group][.label] followed by a set of keyword options to apply and a dictionary indexed by type[.group][.label] specs.
- backendoptional
Backend to apply options to Defaults to current selected backend
- clonebool, optional
Whether to clone object Options can be applied inplace with clone=False
- **kwargs: Keywords of options
Set of options to apply to the object
Returns#
Returns the cloned object with the options applied
- persist()[source]#
Persists the results of a lazy data interface to memory to speed up data manipulation and visualization. If the particular data backend already holds the data in memory this is a no-op. Unlike the compute method this maintains the same data type.
Returns#
Dataset with the data persisted to memory
- property pipeline#
Chain operation that evaluates the sequence of operations that was used to create this object, starting with the Dataset stored in dataset property
- range(dim, data_range=True, dimension_range=True)[source]#
Return the lower and upper bounds of values along dimension.
Parameters#
- dim
The dimension to compute the range on.
- data_rangebool
Compute range from data values
- dimension_rangebool
Include Dimension ranges Whether to include Dimension range and soft_range in range calculation
Returns#
Tuple containing the lower and upper bound
- reduce(dimensions=None, function=None, spreadfn=None, **reductions)[source]#
Applies reduction along the specified dimension(s).
Allows reducing the values along one or more key dimension with the supplied function. Supports two signatures:
Reducing with a list of dimensions, e.g.:
ds.reduce([‘x’], np.mean)
Defining a reduction using keywords, e.g.:
ds.reduce(x=np.mean)
Parameters#
- dimensions
Dimension(s) to apply reduction on Defaults to all key dimensions
- function
Reduction operation to apply, e.g. numpy.mean
- spreadfn
Secondary reduction to compute value spread Useful for computing a confidence interval, spread, or standard deviation.
- **reductions
Keyword argument defining reduction Allows reduction to be defined as keyword pair of dimension and function
Returns#
The Dataset after reductions have been applied.
- reindex(kdims=None, vdims=None)[source]#
Reindexes Dataset dropping static or supplied kdims
Creates a new object with a reordered or reduced set of key dimensions. By default drops all non-varying key dimensions.x
Parameters#
- kdimsoptional
New list of key dimensionsx
- vdimsoptional
New list of value dimensions
Returns#
Reindexed object
- relabel(label=None, group=None, depth=0)[source]#
Clone object and apply new group and/or label.
Applies relabeling to children up to the supplied depth.
Parameters#
- labelstr, optional
New label to apply to returned object
- groupstr, optional
New group to apply to returned object
- depthint, optional
Depth to which relabel will be applied If applied to container allows applying relabeling to contained objects up to the specified depth
Returns#
Returns relabelled object
- sample(samples=None, bounds=None, closest=True, **kwargs)[source]#
Samples values at supplied coordinates.
Allows sampling of element with a list of coordinates matching the key dimensions, returning a new object containing just the selected samples. Supports multiple signatures:
Sampling with a list of coordinates, e.g.:
ds.sample([(0, 0), (0.1, 0.2), …])
Sampling a range or grid of coordinates, e.g.:
1D : ds.sample(3) 2D : ds.sample((3, 3))
Sampling by keyword, e.g.:
ds.sample(x=0)
Parameters#
samples : List of nd-coordinates to sample bounds
Bounds of the region to sample Defined as two-tuple for 1D sampling and four-tuple for 2D sampling.
- closest
Whether to snap to closest coordinates
- **kwargs
Coordinates specified as keyword pairs Keywords of dimensions and scalar coordinates
Returns#
Element containing the sampled coordinates
- select(selection_expr=None, selection_specs=None, **selection)[source]#
Applies selection by dimension name
Applies a selection along the dimensions of the object using keyword arguments. The selection may be narrowed to certain objects using selection_specs. For container objects the selection will be applied to all children as well.
Selections may select a specific value, slice or set of values:
- value: Scalar values will select rows along with an exact
match, e.g.:
ds.select(x=3)
- slice: Slices may be declared as tuples of the upper and
lower bound, e.g.:
ds.select(x=(0, 3))
- values: A list of values may be selected using a list or
set, e.g.:
ds.select(x=[0, 1, 2])
predicate expression: A holoviews.dim expression, e.g.:
from holoviews import dim ds.select(selection_expr=dim(‘x’) % 2 == 0)
Parameters#
- selection_exprholoviews.dim predicate expression
specifying selection.
- selection_specsList of specs to match on
A list of types, functions, or type[.group][.label] strings specifying which objects to apply the selection on.
- **selection: Dictionary declaring selections by dimension
Selections can be scalar values, tuple ranges, lists of discrete values and boolean arrays
Returns#
Returns an Dimensioned object containing the selected data or a scalar if a single value was selected
- property shape#
Returns the shape of the data.
- sort(by=None, reverse=False)[source]#
Sorts the data by the values along the supplied dimensions.
Parameters#
- by
Dimension(s) to sort by
- reversebool, optional
Reverse sort order
Returns#
Sorted Dataset
- property to#
Returns the conversion interface with methods to convert Dataset
- transform(*args, **kwargs)[source]#
Transforms the Dataset according to a dimension transform.
Transforms may be supplied as tuples consisting of the dimension(s) and the dim transform to apply or keyword arguments mapping from dimension(s) to dim transforms. If the arg or kwarg declares multiple dimensions the dim transform should return a tuple of values for each.
A transform may override an existing dimension or add a new one in which case it will be added as an additional value dimension.
Parameters#
- args
Specify the output arguments and transforms as a tuple of dimension specs and dim transforms
- dropbool
Whether to drop all variables not part of the transform
- keep_indexbool
- Whether to keep indexes
Whether to apply transform on datastructure with index, e.g. pandas.Series or xarray.DataArray, (important for dask datastructures where index may be required to align datasets).
- kwargs
Specify new dimensions in the form new_dim=dim_transform
Returns#
Transformed dataset with new dimensions
- class holoviews.core.data.PipelineMeta(classname, bases, classdict)[source]#
Bases:
ParameterizedMetaclass
- holoviews.core.data.concat(datasets, datatype=None)[source]#
Concatenates collection of datasets along NdMapping dimensions.
Concatenates multiple datasets wrapped in an NdMapping type along all of its dimensions. Before concatenation all datasets are cast to the same datatype, which may be explicitly defined or implicitly derived from the first datatype that is encountered. For columnar data concatenation adds the columns for the dimensions being concatenated along and then concatenates all the old and new columns. For gridded data a new axis is created for each dimension being concatenated along and then hierarchically concatenates along each dimension.
Parameters#
- datasets
NdMapping of Datasets to concatenate
- datatype
Datatype to cast data to before concatenation
Returns#
Concatenated dataset