2222from .utils import list_to_md_table , logger
2323
2424SCHEMA_TO_PANDAS_TYPES = {
25- "integer" : "int64 " ,
26- "number" : "float " ,
25+ "integer" : "Int64 " ,
26+ "number" : "Float64 " ,
2727 "string" : "string" ,
2828 "any" : "object" ,
29- "boolean" : "bool " ,
29+ "boolean" : "boolean " ,
3030}
3131
3232FORMAT_TO_REGEX = {
3737}
3838
3939
40+ def read_schema_for_resource (resource_df : pd .DataFrame , table_name : str , raise_error : bool ) -> dict :
41+ """
42+ Read in schema from schema json file and returns as dictionary.
43+
44+ ##TODO validate schema itself
45+
46+ Args:
47+ schema_file: File location of the schema json file.
48+
49+ Returns: The schema as a dictionary
50+ """
51+ matching_schema_paths = resource_df .loc [resource_df ["name" ] == table_name , "fullpath_schema" ]
52+ if matching_schema_paths .empty :
53+ msg = f"FAIL. Could not find schema path for table { table_name } "
54+ logger .error (msg )
55+ if raise_error :
56+ raise Exception (msg )
57+ return dict ()
58+ return read_schema (schema_file = matching_schema_paths .iloc [0 ])
59+
60+
4061def read_schema (schema_file : str ) -> dict :
4162 """
4263 Read in schema from schema json file and returns as dictionary.
@@ -90,7 +111,7 @@ def read_config(config_file: str, data_dir: str = "", schema_dir: str = "") -> p
90111 ## todo validate config
91112
92113 resource_df = pd .DataFrame (config ["resources" ])
93- resource_df ["required" ].fillna (False , inplace = True )
114+ resource_df ["required" ] = resource_df [ "required" ] .fillna (False )
94115
95116 logger .info (str (resource_df ))
96117
@@ -105,15 +126,15 @@ def read_config(config_file: str, data_dir: str = "", schema_dir: str = "") -> p
105126 resource_df ["fullpath_schema" ] = resource_df ["schema" ].apply (lambda x : join (schema_dir , x ))
106127 logger .info (str (resource_df ))
107128
108- resource_df .set_index ("name" , drop = False , inplace = True )
129+ resource_df = resource_df .set_index ("name" , drop = False )
109130 return resource_df
110131
111132
112133def document_schemas_to_md (schema_path : str = None , out_path : str = None ) -> str :
113134 """Create markdown for each **.schema.json file in schema_path.
114135
115136 Args:
116- schema_path (str, optional): Path fo tlook for schema files.
137+ schema_path (str, optional): Path to look for schema files.
117138 Defaults to join(dirname(realpath(__file__)), "spec")
118139 out_path (str, optional): If specified, will write out resulting markdown to this file.
119140 Defaults to None.
0 commit comments