pygsti.tools.nameddict

The NamedDict class

Module Contents

Classes

NamedDict

A dictionary that also holds category names and types.

class pygsti.tools.nameddict.NamedDict(keyname=None, keytype=None, valname=None, valtype=None, items=())

Bases: dict, pygsti.baseobjs.nicelyserializable.NicelySerializable

A dictionary that also holds category names and types.

This dict-derived class holds a catgory name applicable to its keys, and key and value type names indicating the types of its keys and values.

The main purpose of this class is to utilize its :method:`to_dataframe` method.

Parameters
  • keyname (str, optional) – A category name for the keys of this dict. For example, if the dict contained the keys “dog” and “cat”, this might be “animals”. This becomes a column header if this dict is converted to a data frame.

  • keytype ({"float", "int", "category", None}, optional) – The key-type, in correspondence with different pandas series types.

  • valname (str, optional) – A category name for the keys of this dict. This becomse a column header if this dict is converted to a data frame.

  • valtype ({"float", "int", "category", None}, optional) – The value-type, in correspondence with different pandas series types.

  • items (list or dict, optional) – Initial items, used in serialization.

classmethod create_nested(cls, key_val_type_list, inner)

Creates a nested NamedDict.

Parameters
  • key_val_type_list (list) – A list of (key, value, type) tuples, one per nesting layer.

  • inner (various) – The value that will be set to the inner-most nested dictionary’s value, supplying any additional layers of nesting (if inner is a NamedDict) or the value contained in all of the nested layers.

__reduce__(self)

Helper for pickle.

_to_nice_serialization(self)
classmethod _from_nice_serialization(cls, state)
to_dataframe(self)

Render this dict as a pandas data frame.

Returns

pandas.DataFrame

_add_to_columns(self, columns, seriestypes, row_prefix)