From d7a90d9682bd2b466be28c0191ab254609fc0e6e Mon Sep 17 00:00:00 2001 From: qubixes <44498096+qubixes@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:04:30 +0100 Subject: [PATCH] Remove general from toml specification (#261) --- docs/source/usage/cli.rst | 1 - examples/example_config.toml | 3 +-- metasyn/config.py | 11 +++++------ tests/data/example_config.toml | 2 -- tests/data/no_data_config.toml | 2 -- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/docs/source/usage/cli.rst b/docs/source/usage/cli.rst index 5d91b38c..6d882923 100644 --- a/docs/source/usage/cli.rst +++ b/docs/source/usage/cli.rst @@ -147,7 +147,6 @@ column is ``data_free``. It is also required to set the number of rows under the .. code-block:: toml - [general] n_rows = 100 diff --git a/examples/example_config.toml b/examples/example_config.toml index be9c4c7d..7e3d6fdb 100644 --- a/examples/example_config.toml +++ b/examples/example_config.toml @@ -1,9 +1,8 @@ # Example toml file as input for metasyn -[general] dist_providers = ["builtin", "metasyn-disclosure"] -[general.privacy] +[privacy] name = "disclosure" parameters = {n_avg = 11} diff --git a/metasyn/config.py b/metasyn/config.py index aff515e4..30363dd1 100644 --- a/metasyn/config.py +++ b/metasyn/config.py @@ -80,14 +80,13 @@ def from_toml(cls, config_fp: Union[str, Path]) -> MetaConfig: """ with open(config_fp, "rb") as handle: config_dict = tomllib.load(handle) - general = config_dict.get("general", {}) var_list = config_dict.pop("var", []) - n_rows = general.pop("n_rows", None) - dist_providers = general.pop("dist_providers", ["builtin"]) - privacy = general.pop("privacy", {"name": "none", "parameters": {}}) - if len(general) > 0: + n_rows = config_dict.pop("n_rows", None) + dist_providers = config_dict.pop("dist_providers", ["builtin"]) + privacy = config_dict.pop("privacy", {"name": "none", "parameters": {}}) + if len(config_dict) > 0: raise ValueError(f"Error parsing configuration file '{config_fp}'." - f" Unknown keys detected: '{list(general)}'") + f" Unknown keys detected: '{list(config_dict)}'") return cls(var_list, dist_providers, privacy, n_rows=n_rows) def to_dict(self) -> dict: diff --git a/tests/data/example_config.toml b/tests/data/example_config.toml index dab20a81..3dd07deb 100644 --- a/tests/data/example_config.toml +++ b/tests/data/example_config.toml @@ -1,6 +1,4 @@ # Example toml file as input for metasyn - -[general] dist_providers = ["builtin"] diff --git a/tests/data/no_data_config.toml b/tests/data/no_data_config.toml index d86c8263..51219d01 100644 --- a/tests/data/no_data_config.toml +++ b/tests/data/no_data_config.toml @@ -1,6 +1,4 @@ # Example toml file as input for metasyn - -[general] n_rows = 100