packflow.utils package

Subpackages

Submodules

packflow.utils.data module

packflow.utils.data.flatten_dict(obj, delimiter='.', flatten_lists=False)[source]

Create a flattened dictionary from a nested object.

Parameters:
  • obj (dict)

  • delimiter (str) – Default ‘.’

  • flatten_lists (bool) – Default False

Returns:

Flattened dictionary.

Return type:

dict

packflow.utils.data.flatten_records(records, delimiter='.', flatten_lists=False)[source]

Flatten a list of dictionaries

Parameters:
  • records (List[dict])

  • delimiter (str) – Default ‘.’

  • flatten_lists (bool) – Default False

Returns:

Flattened records.

Return type:

List[dict]

packflow.utils.data.get_nested_field(obj, field, delimiter=None)[source]

Retrieves a single nested field from a dictionary given a field name.

Example: get_nested_field({“foo”: {“bar”: 5}}, ‘foo.bar’) -> 5

Parameters:
  • obj (dict) – An arbitrary dictionary of data

  • field (str) – The key name to retrieve where subfields are split by $delimiter

Returns:

The value retrieved from the nested key

Return type:

Any

packflow.utils.data.records_to_ndarray(records, feature_names, dtype=None, delimiter=None)[source]

Converts records to a numpy nd array

Example

in: [{“num”: 1, “num2”: 1}, {“num”: 2, “num”: 2}] args: feature_names=[“num”, “num2”] out: np.array([[1, 1], [2, 2]])

Parameters:
  • records (List[Dict]) – A list of dictionary items to be converted

  • feature_names (List[str]) – The values to extract for each row

  • dtype (str) – The numpy data type to coerce the array to. Defaults to ‘float32’

Return type:

numpy.ndarray

Module contents