Skip to content

Commit

Permalink
📜 table.format (#2902)
Browse files Browse the repository at this point in the history
* 📜 table.format

* improve error message
  • Loading branch information
lucasrodes committed Jun 26, 2024
1 parent 11d2df7 commit a7d468f
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit a7d468f

Please sign in to comment.