Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📜 table.format #2902

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/catalog/owid/catalog/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ def format(

This includes underscoring column names, setting index, verifying there is only one entry per index, sorting by index.

Underscoring is the first step, so make sure to use correct values in `keys` (e.g. use 'country' if original table had 'Country').

```
tb.format(["country", "year"])
```
Expand Down Expand Up @@ -761,7 +763,16 @@ def format(
# Set index
if keys is None:
keys = ["country", "year"]
t = t.set_index(keys, verify_integrity=verify_integrity)
## Sanity check
try:
t = t.set_index(keys, verify_integrity=verify_integrity)
except KeyError as e:
if underscore:
raise KeyError(
f"Make sure that you are using valid column names! Note that the column names have been underscored! Available column names are: {t.columns}. You used {keys}."
)
else:
raise e
if sort_columns:
t = t.sort_index(axis=1)
# Sort rows
Expand Down
Loading