Skip to content

Reverse best place type selection logic#6421

Open
nick-nlb wants to merge 5 commits into
datacommonsorg:masterfrom
nick-nlb:fix-best-place-ranking
Open

Reverse best place type selection logic#6421
nick-nlb wants to merge 5 commits into
datacommonsorg:masterfrom
nick-nlb:fix-best-place-ranking

Conversation

@nick-nlb

@nick-nlb nick-nlb commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Issue

b/530339277

Description

This issue manifests in two places: maps being dropped in explore pages (just showing ranking charts), and the map tool being unable to load charts for certain places.

This can be seen at the following link:

https://dev.datacommons.org/tools/map#%26sv%3DUnemploymentRate_Person%26pc%3D0%26denom%3DCount_Person%26pd%3DgeoId%2F34%26ept%3DCounty

The problem became symptomatic with the introduction of a data problem: places like the US, Canada, New Jersey now have "Place" as a placeType in addition to "Country", "Country" and "State" respectively.

While this data ingestion issue needs to be separately fixed, it highlighted an issue in the way that website prioritized order.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where incorrect place type selection was causing display problems in explore pages and map tools. By reversing the sorting logic for place types, the system now correctly prioritizes more specific classifications (like City or State) over generic ones (like Place), ensuring consistent data rendering even when multiple types are associated with a single entity.

Highlights

  • Logic Update: Updated the _get_best_type function to prioritize more specific place types by sorting with lower ranks first, rather than higher ranks.
  • Type Handling: Improved handling of unknown types by assigning them a lower priority (math.inf) and adjusted the sorting logic to prefer standard names over 'AdministrativeArea' variants.
  • Test Coverage: Updated migration verification tests to include additional place types, ensuring the new sorting logic behaves correctly with multiple type definitions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the _get_best_type helper function in server/services/datacommons.py to prioritize more specific place types (lower non-zero ranks) and place unrecognized types last, updating the associated unit tests accordingly. Feedback on this change points out a typo in the updated docstring and suggests using min() instead of sorted() to find the best type more efficiently in O(N) time.

Comment thread server/services/datacommons.py Outdated
@nick-nlb nick-nlb marked this pull request as ready for review July 2, 2026 02:41
@nick-nlb nick-nlb requested review from SandeepTuniki and juliawu July 2, 2026 02:42

@juliawu juliawu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for also updating the docstring and tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants