tlo.logging.helpers module

set_logging_levels(custom_levels: Dict[str, int]) None[source]

Set custom logging levels for disease modules

Parameters:

custom_levels – Dictionary of modules and their level, ‘*’ can be used as a key for all modules

get_dataframe_row_as_dict_for_logging(dataframe: DataFrame, row_label: int | str, columns: Iterable[str] | None = None) dict[source]

Get row of a pandas dataframe in a format suitable for logging.

Retrieves entries for all or a subset of columns for a particular row in a dataframe and returns a dict keyed by column name, with values NumPy or pandas extension types which should be the same for all rows in dataframe.

Parameters:
  • dataframe – Population properties dataframe to get properties from.

  • row_label – Unique index label identifying row in dataframe.

  • columns – Set of column names to extract - if None, the default, all column values will be returned.

Returns:

Dictionary with column names as keys and corresponding entries in row as values.

grouped_counts_with_all_combinations(dataframe: DataFrame, group_by_columns: List[str], column_possible_values: Dict[str, Collection] | None = None) Series[source]

Perform group-by count in which all combinations of column values are included.

As all combinations are included irrespective of whether they are present in data (and so have a non-zero count), this gives a multi-index series output of fixed structure suitable for logging.

Attempts to convert all columns to categorical datatype, with bool(ean) columns automatically converted, and other non-categorical columns needing to have set of possible values specified (which requires that this set is finite).

Parameters:
  • dataframe – Dataframe to perform group-by counts on.

  • group_by_columns – Columns to perform grouping on.

  • column_possible_values – Dictionary mapping from column names to set of possible values for all columns not of categorical or bool(ean) data type.

Returns:

Multi-index series with values corresponding to grouped counts.