utils

utils#

Utility functions for anonymization algorithms.

Functions

generalize_column(values: list | ndarray | Series, hierarchy: Hierarchy, level_from: int, level_to: int)#

Generalize a column of data.

Parameters:
  • values (list, numpy.ndarray, or pandas.Series) – The input data to be generalized.

  • hierarchy (Hierarchy) – Hierarchy definition for the input data.

  • level_from (int) – The current generalization level of the input data.

  • level_to (int) – The target generalization level to transform the input data into.

Returns:

tuple(generalized_values, is_suppressed)

generalized_valueslist, numpy.ndarray, or pandas.Series

The generalized data in the same format as the input.

is_suppressedbool

Whether the data has been suppressed (replaced all values with ‘*’).

Raises:

AssertionError – If level_from is not lower than level_to, or if they exceed the height of the hierarchy.