Data#

class zfit.data.Data(dataset, obs=None, name=None, weights=None, iterator_feed_dict=None, dtype=None)[source]#

Bases: zfit.util.cache.GraphCachable, zfit.core.interfaces.ZfitUnbinnedData, zfit.core.dimension.BaseDimensional, zfit.core.baseobject.BaseObject, zfit.core.tensorlike.OverloadableMixin

Create a data holder from a dataset used to feed into models.

Parameters
  • dataset (tf.data.Dataset | LightDataset) – A dataset storing the actual values

  • obs (ztyping.ObsTypeInput) – Observables where the data is defined in

  • name (str) – Name of the Data

  • iterator_feed_dict (dict) –

  • dtype (tf.DType) – The DType of the return value. Defaults to the zfit default (usually float64).

set_weights(weights)[source]#

Set (temporarily) the weights of the dataset. (deprecated)

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Do not set the weights on a data set, create a new one instead.

Parameters

weights (Union[Tensor, None, ndarray]) –

classmethod from_pandas(df, obs=None, weights=None, name=None, dtype=None)[source]#

Create a Data from a pandas DataFrame. If obs is None, columns are used as obs.

Parameters
  • df (pd.DataFrame) – pandas DataFrame that contains the data. If obs is None, columns are used as obs. Can be a superset of obs.

  • obs (ztyping.ObsTypeInput) – obs to use for the data. obs have to be the columns in the data frame. If None, columns are used as obs.

  • weights (ztyping.WeightsInputType | str) – Weights of the data. Has to be 1-D and match the shape of the data (nevents) or a string that is a column in the dataframe.

  • name (str) –

classmethod from_root(cls, path, treepath, obs=None, *, weights=None, obs_alias=None, name=None, dtype=None, root_dir_options=None, branches=None, branches_alias=None)[source]#

Create a Data from a ROOT file. Arguments are passed to uproot. (deprecated arguments) (deprecated arguments)

Warning: SOME ARGUMENTS ARE DEPRECATED: (branches). They will be removed in a future version. Instructions for updating: Use obs instead.

Warning: SOME ARGUMENTS ARE DEPRECATED: (branches_alias). They will be removed in a future version. Instructions for updating: Use obs_alias instead and make sure to invert the logic! I.e. it’s a mapping from the observable name to the actual branch name.

The arguments are passed to uproot directly.

Parameters
  • path – Path to the root file.

  • treepath – Name of the tree in the root file.

  • obs – Observables of the data. This will also be the columns of the data if not obs_alias is given.

  • weights – Weights of the data. Has to be 1-D and match the shape of the data (nevents). Can be a column of the ROOT file by using a string corresponding to a column.

  • obs_alias – A mapping from the obs (as keys) to the actual branches (as values) in the root file. This allows to have different observable names, independent of the branch name in the file.

  • name

  • root_dir_options

Returns

A Data object containing the unbinned data.

Return type

zfit.Data

classmethod from_numpy(obs, array, weights=None, name=None, dtype=None)[source]#

Create Data from a np.array.

Parameters
  • obs (Union[str, Iterable[str], Space]) – Observables of the data. They will be matched to the data in the same order.

  • array (ndarray) – Numpy array containing the data.

  • weights (Union[Tensor, None, ndarray]) – Weights of the data. Has to be 1-D and match the shape of the data (nevents).

  • name (Optional[str]) –

Returns

A Data object containing the unbinned data.

Return type

zfit.Data

classmethod from_tensor(obs, tensor, weights=None, name=None, dtype=None)[source]#

Create a Data from a tf.Tensor. Value simply returns the tensor (in the right order).

Parameters
  • obs (Union[str, Iterable[str], Space]) – Observables of the data. They will be matched to the data in the same order.

  • tensor (Tensor) – Tensor containing the data.

  • weights (Union[Tensor, None, ndarray]) – Weights of the data. Has to be 1-D and match the shape of the data (nevents).

  • name (Optional[str]) – Name of the data.

Returns

A Data object containing the unbinned data.

Return type

zfit.Data

to_pandas(obs=None)[source]#

Create a pd.DataFrame from obs as columns and return it.

Parameters

obs (Union[str, Iterable[str], Space, None]) – The observables to use as columns. If None, all observables are used.

Returns:

unstack_x(obs=None, always_list=False)[source]#

Return the unstacked data: a list of tensors or a single Tensor.

Parameters
  • obs (Union[str, Iterable[str], Space, None]) – which observables to return

  • always_list (bool) – If True, always return a list (also if length 1)

Returns

List(tf.Tensor)

add_cache_deps(cache_deps, allow_non_cachable=True)#

Add dependencies that render the cache invalid if they change.

Parameters
  • cache_deps (Union[zfit.core.interfaces.ZfitGraphCachable, Iterable[zfit.core.interfaces.ZfitGraphCachable]]) –

  • allow_non_cachable (bool) – If True, allow cache_dependents to be non-cachables. If False, any cache_dependents that is not a ZfitGraphCachable will raise an error.

Raises

TypeError – if one of the cache_dependents is not a ZfitGraphCachable _and_ allow_non_cachable if False.

property name: str#

The name of the object.

Return type

str

register_cacher(cacher)#

Register a cacher that caches values produces by this instance; a dependent.

Parameters

cacher (Union[zfit.core.interfaces.ZfitGraphCachable, Iterable[zfit.core.interfaces.ZfitGraphCachable]]) –

reset_cache_self()#

Clear the cache of self and all dependent cachers.