From 9de43528842eafd7734504f5517913a9aa0c4cad Mon Sep 17 00:00:00 2001 From: Olexandr Balyk Date: Tue, 27 Feb 2024 12:53:23 -0500 Subject: [PATCH] Add info on the required cols for each tag to Config --- xl2times/datatypes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xl2times/datatypes.py b/xl2times/datatypes.py index 79d4633..ab35b3e 100644 --- a/xl2times/datatypes.py +++ b/xl2times/datatypes.py @@ -188,6 +188,10 @@ class Config: veda_attr_defaults: Dict[str, Dict[str, list]] # Known columns for each tag known_columns: Dict[Tag, Set[str]] + # Query columns for each tag + query_columns: Dict[Tag, Set[str]] + # Required columns for each tag + required_columns: Dict[Tag, Set[str]] # Names of regions to include in the model; if empty, all regions are included. filter_regions: Set[str] times_sets: Dict[str, List[str]] @@ -214,6 +218,7 @@ def __init__( self.discard_if_empty, self.query_columns, self.known_columns, + self.required_columns, ) = Config._read_veda_tags_info(veda_tags_file) self.veda_attr_defaults, self.attr_aliases = Config._read_veda_attr_defaults( veda_attr_defaults_file @@ -371,6 +376,7 @@ def _read_veda_tags_info( Iterable[Tag], Dict[Tag, Set[str]], Dict[Tag, Set[str]], + Dict[Tag, Set[str]], ]: def to_tag(s: str) -> Tag: # The file stores the tag name in lowercase, and without the ~ @@ -393,6 +399,7 @@ def to_tag(s: str) -> Tag: discard_if_empty = [] query_cols = defaultdict(set) known_cols = defaultdict(set) + required_cols = defaultdict(set) for tag_info in veda_tags_info: tag_name = to_tag(tag_info["tag_name"]) @@ -415,6 +422,10 @@ def to_tag(s: str) -> Tag: if valid_field["query_field"]: query_cols[tag_name].add(field_name) + + if valid_field["remove_any_row_if_absent"]: + required_cols[tag_name].add(field_name) + known_cols[tag_name].add(field_name) for valid_field_name in valid_field_names: @@ -443,6 +454,7 @@ def to_tag(s: str) -> Tag: discard_if_empty, query_cols, known_cols, + required_cols, ) @staticmethod