Skip to content

Latest commit

 

History

History
81 lines (67 loc) · 2.42 KB

README.md

File metadata and controls

81 lines (67 loc) · 2.42 KB

Smartnoise Synth Logger

Logger for Smartnoise Synth Transformers

License: MIT Python ci tests

Serialize and deserialize Smartnoise Synth constraints to and from JSON. Constraints as specified in the Smartnoise Synth Transforms documentation: https://docs.smartnoise.org/synth/transforms/index.html with tt = TableTransformer(constraint).

Installation

Install with pip:

pip install smartnoise-synth-logger

Example

from snsynth.transform import (
    AnonymizationTransformer,
    BinTransformer,
    ChainTransformer,
    ClampTransformer,
    DropTransformer,
    LabelTransformer,
    LogTransformer,
    MinMaxTransformer,
    OneHotEncoder,
    StandardScaler,
)
from snsynth.transform.datetime import DateTimeTransformer


constraints = {
    "id": AnonymizationTransformer("uuid4"),
    "email": "email", # also possible
    "income": ChainTransformer(
        [
            LogTransformer(),
            BinTransformer(bins=20, lower=0, upper=50),
        ]
    ),
    "height": ChainTransformer(
        [
            StandardScaler(lower=0, upper=1),
            BinTransformer(bins=20, lower=0, upper=1),
        ]
    ),
    "weight": ChainTransformer(
        [ClampTransformer(lower=10, upper=200), BinTransformer(bins=20)]
    ),
    "age": MinMaxTransformer(lower=0, upper=100),
    "sex": ChainTransformer(
        [LabelTransformer(nullable=True), OneHotEncoder()]
    ),
    "rank": LabelTransformer(nullable=False),
    "job": DropTransformer(),
    "date": DateTimeTransformer(epoch="1993-06-04"),
}

Serialise

from smartnoise_synth_logger import serialise_constraints

serialised_constraints = serialise_constraints(constraints)

Deserialise

from smartnoise_synth_logger import deserialise_constraints

deserialised_constraints = deserialise_constraints(serialised_constraints)
tt = TableTransformer(deserialised_constraints)

It can now be expected that the deserialised_constraints has the same constraints as constraints.

NOTE: lambda function in AnonymizationTransformer are not supported.