| 420 | |
| 421 | |
| 422 | def _markdown_to_pandas(table_def: str, split_on_whitespace: bool = True): |
| 423 | table_def = table_def.lstrip("\n") |
| 424 | if split_on_whitespace: |
| 425 | sep = r"(?:\s*\|\s*)|\s+" |
| 426 | else: |
| 427 | sep = r"\s*\|\s*" |
| 428 | header = table_def.partition("\n")[0].strip() |
| 429 | column_names = re.split(sep, header) |
| 430 | for index, name in enumerate(column_names): |
| 431 | if name in ("", "id"): |
| 432 | index_col = index |
| 433 | break |
| 434 | else: |
| 435 | index_col = None |
| 436 | return pd.read_table( |
| 437 | io.StringIO(table_def), |
| 438 | sep=sep, |
| 439 | index_col=index_col, |
| 440 | engine="python", |
| 441 | na_values=("", "None", "NaN", "nan", "NA", "NULL"), |
| 442 | keep_default_na=False, |
| 443 | ).convert_dtypes() |
| 444 | |
| 445 | |
| 446 | def table_from_markdown( |