ts_ids_core.mapping_table.convert module

exception TableError[source]

Bases: Exception

Error class for table errors

exception UnexpectedJsonError[source]

Bases: Exception

Error class for incorrect JSON formats

dataframe_to_markdown_lines(table: DataFrame) List[str][source]

Format the mapping table string to our readme conventions.

pandas.DataFrame.to_markdown() automatically pads each column to be the width of the widest cell in the column. This leads to a lot of unnecessary whitespace in many rows. To aid readability we use to_csv() with a | separator, and then add a single space padding to each cell manually.

format_table_lines(table_lines: List[str]) List[str][source]

Format the lines of the markdown table

In markdown tables, any whitespace or a leading/trailing | are ignored, so we strip these characters from the start and end of each line with a regex.

json_string_to_dict(json_string: str) dict[source]

Dereference a json string & ensure it is a dict

mapping_table_to_markdown_lines(mapping_table: MappingTable) List[str][source]

Convert the MappingTable instance to markdown table lines

markdown_table_lines_to_dataframe(markdown_table_lines: List[str]) DataFrame[source]

Convert markdown table lines to a pandas dataframe

readme_lines_to_mapping_table(readme_lines: List[str], mapping_table_section_heading: str = 'Raw to IDS Mapping') MappingTable[source]

Extract and convert mapping table lines from readme lines to a MappingTable instance.

Arguments:

readme_lines – list of lines from the readme

Keyword Arguments:

mapping_table_section_heading – heading of the mapping table section

readme_to_mapping_table(readme_path: Path, mapping_table_section_heading: str = 'Raw to IDS Mapping') MappingTable[source]

Convert a mapping table in a readme file to a MappingTable instance

Arguments:

readme_path – path to the readme file

Keyword Arguments:

mapping_table_section_heading – heading of the mapping table section