-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for update_undocumented_columns_with_prior_knowledge
- Loading branch information
Showing
7 changed files
with
334 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import re | ||
from typing import Any, Dict | ||
|
||
ColumnLevelKnowledge = Dict[str, Any] | ||
Knowledge = Dict[str, ColumnLevelKnowledge] | ||
|
||
|
||
def get_prior_knowledge( | ||
knowledge: Knowledge, | ||
column: str, | ||
) -> ColumnLevelKnowledge: | ||
camel_column = re.sub("_(.)", lambda m: m.group(1).upper(), column) | ||
prior_knowledge_candidates = list( | ||
filter( | ||
lambda k: k, | ||
[ | ||
knowledge.get(column), | ||
knowledge.get(column.lower()), | ||
knowledge.get(camel_column), | ||
], | ||
) | ||
) | ||
sorted_prior_knowledge_candidates_sources = sorted( | ||
[k for k in prior_knowledge_candidates if k["progenitor"].startswith("source")], | ||
key=lambda k: k["generation"], | ||
reverse=True, | ||
) | ||
sorted_prior_knowledge_candidates_models = sorted( | ||
[k for k in prior_knowledge_candidates if k["progenitor"].startswith("model")], | ||
key=lambda k: k["generation"], | ||
reverse=True, | ||
) | ||
sorted_prior_knowledge_candidates = ( | ||
sorted_prior_knowledge_candidates_sources + sorted_prior_knowledge_candidates_models | ||
) | ||
prior_knowledge = ( | ||
sorted_prior_knowledge_candidates[0] if sorted_prior_knowledge_candidates else {} | ||
) | ||
return prior_knowledge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.