wadi.infotable module

class wadi.infotable.InfoTable(df, format, c_dict, units, datatypes, extract_units_from_feature_name)

Bases: UserDict

Nested dictionary that stores information about the imported data. Note that the keys of the level-0 dictionary are referred to as key_0. The level-1 dictionaries is referred to as dict_1 and their keys as key_1.

Each dict in the InfoTable will contain the following items:
  • name: the name of the feature

  • unit: the feature’s units

  • sampleids (only for stacked data): the sample identifiers

  • values: a view to the (concentration) values in self.df

  • datatype: to indicate if the data are for a feature or sampleinfo

  • alias_n: the name alias

  • alias_u: the unit alias

  • u_str: the string parsed by str2pint in the UnitConverter

__init__(df, format, c_dict, units, datatypes, extract_units_from_feature_name)

Initialization method. Creates a nested dict with information about the imported data.

Parameters:
  • df (DataFrame) – The DataFrame of the DataObject class instance

  • format (str) – The format of the data. Must be in VALID_FORMATS defined in reader.py.

  • c_dict (dict) – Dictionary that maps the column names of a stacked-format data file to the compulsory column names in WaDI as defined in REQUIRED_COLUMNS_S in reader.py.

  • units (list of strings) – List with the units for each feature (or sampleinfo data). This list is created by the ‘_read_file’ function based on the unit_row kwarg passed by the user to read_data.

  • datatypes (list of strings) – List with the datatype for each feature (or sampleinfo data). This list is created by the ‘_read_file’ function based on the datatype kwarg passed by the user to read_data. Datatypes must all be in VALID_DATATYPES.

  • extract_units_from_feature_name (bool) – Indicates if the feature name also contains the units.

list_dict1_item(item)

This function iterates over all the (sub-)dictionaries in the InfoTable and retrieves the value of element ‘item’. All items are collected in a list using list comprehension.

Parameters:

item (str) – The name of the key in the dictionary to be retrieved.

Returns:

result – List of the values stored in element ‘item’ in the (sub-)dictionaries of the InfoTable.

Return type:

list

list_keys()

This function returns the level-0 keys (key0) as a list.

Returns:

result – List of the level-0 keys of the InfoTable.

Return type:

list

update_items(a_dict)

This method iterates over the level-0 items of the dictionary and updates the level-1 dictionaries with the items in a_dict.

Parameters:

a_dict (dict) – Nested dictionary of which they keys correspond to the level-0 keys of the current dictionary. Its values are level-1 dictionaries. The level-1 items of the current dictionary will be updated with those from a_dict. The item values of the current dictionary are not overwritten if an item_value in a_dict is None.