posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.44k stars 50 forks source link

Docs: rename variables in the Oceania example #263

Closed sergiolaverde0 closed 3 months ago

sergiolaverde0 commented 3 months ago

Prework

Proposal

Describe the new feature clearly and concisely. If applicable, write a minimal example in Python or in pseudo-code to show input, usage, and desired output.

While looking through the examples available at the website I noticed this (in my opinion) confusing snippet of code on the example with the countries of Oceania:

countries = {
    "Australasia": ["AU", "NZ"],
    "Melanesia": ["NC", "PG", "SB", "VU"],
    "Micronesia": ["FM", "GU", "KI", "MH", "MP", "NR", "PW"],
    "Polynesia": ["PF", "WS", "TO", "TV"],
}

# Create a dictionary mapping region to country (e.g. AU -> Australasia)
region_to_country = {
    region: country for country, regions in countries.items() for region in regions
}

My first thought was that this code would create a shorted dictionary with only four regions and their last listed country because of the region: country in the comprehension. However when I tested it, it ran perfectly. Several minutes later I noticed what was happening on the part of country, regions in countries.items(), which is confusing since country actually contains the four regions and regions is a list of countries.

While I understand this is not the main point of what the library does, and the code works as intended, I still think this should be changed to make it more intuitive to the reader. Since this is very mundane and the maintainer already spend the best part of a minute reading this far, I will be opening a PR to fix this myself have opened PR #264.

rich-iannone commented 3 months ago

Thank you! I’ll look at the PR shortly :)