Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-jafari committed Oct 30, 2024
1 parent 01ae238 commit 6749442
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/pseudopeople/configuration/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ def _format_misreport_age_perturbations(
if not user_perturbations:
continue
formatted = {}
default_perturbations: dict[int, float] = default_config.get_tree(dataset_schema).get_tree(Keys.COLUMN_NOISE).get_tree("age").get_tree(NOISE_TYPES.misreport_age.name).get(Keys.POSSIBLE_AGE_DIFFERENCES).to_dict()
default_perturbations: dict[int, float] = (
default_config.get_tree(dataset_schema)
.get_tree(Keys.COLUMN_NOISE)
.get_tree("age")
.get_tree(NOISE_TYPES.misreport_age.name)
.get(Keys.POSSIBLE_AGE_DIFFERENCES)
.to_dict()
)
# Replace default configuration with 0 probabilities
for perturbation in default_perturbations:
formatted[perturbation] = 0.0
Expand Down
4 changes: 2 additions & 2 deletions src/pseudopeople/configuration/noise_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, config: LayeredConfigTree):

def to_dict(self) -> dict:
# TODO: remove ignore when dropping support for Python 3.9
config_dict: dict = self._config.to_dict() # type: ignore [assignment]
config_dict: dict = self._config.to_dict() # type: ignore [assignment]
return config_dict

def get_value(
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_value(
noise_value: int | float | LayeredConfigTree = parameter_tree.get(parameter_name)
converted_noise_value: int | float | dict = (
# not sure how to tell mypy the types in this dict
noise_value.to_dict() # type: ignore [assignment]
noise_value.to_dict() # type: ignore [assignment]
if isinstance(noise_value, LayeredConfigTree)
else noise_value
)
Expand Down
27 changes: 19 additions & 8 deletions src/pseudopeople/configuration/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def validate_overrides(overrides: Any, default_config: LayeredConfigTree) -> Non
default_dataset_config, key, "configuration key", dataset_name
)

default_row_noise_config: LayeredConfigTree = default_dataset_config.get_tree(Keys.ROW_NOISE)
default_column_noise_config: LayeredConfigTree = default_dataset_config.get_tree(Keys.COLUMN_NOISE)
default_row_noise_config: LayeredConfigTree = default_dataset_config.get_tree(
Keys.ROW_NOISE
)
default_column_noise_config: LayeredConfigTree = default_dataset_config.get_tree(
Keys.COLUMN_NOISE
)

row_noise_config = dataset_config.get(Keys.ROW_NOISE, {})
if not isinstance(row_noise_config, dict):
Expand Down Expand Up @@ -346,19 +350,26 @@ def validate_noise_level_proportions(
# Note: Using pd.isnull here and above because np.isnan does not work on strings
if NOISE_TYPES.duplicate_with_guardian in dataset_schema.row_noise_types:
# Config level for guardian duplication group
config_noise_level = configuration_tree.get_tree(row["dataset"]).get_tree(Keys.ROW_NOISE).get_tree(
NOISE_TYPES.duplicate_with_guardian.name
).get(row["noise_type"])
config_noise_level = (
configuration_tree.get_tree(row["dataset"])
.get_tree(Keys.ROW_NOISE)
.get_tree(NOISE_TYPES.duplicate_with_guardian.name)
.get(row["noise_type"])
)
entity_type = Keys.ROW_NOISE
else:
# I have preloaded the metadata for ACS and CPS to have the duplicate with
# guardian metadata but we are not using it right now.
continue
else:
# Config level for each column noise type
config_noise_level = configuration_tree.get_tree(row["dataset"]).get_tree(Keys.COLUMN_NOISE).get_tree(
row["column"]
).get_tree(row["noise_type"]).get(Keys.CELL_PROBABILITY)
config_noise_level = (
configuration_tree.get_tree(row["dataset"])
.get_tree(Keys.COLUMN_NOISE)
.get_tree(row["column"])
.get_tree(row["noise_type"])
.get(Keys.CELL_PROBABILITY)
)
entity_type = Keys.COLUMN_NOISE
max_noise_level = row["proportion"]
if config_noise_level > max_noise_level:
Expand Down

0 comments on commit 6749442

Please sign in to comment.