Skip to content

Fix KeyError in The_national_map_USGS.prodFormats - #1353

Merged
giswqs merged 4 commits into
opengeos:masterfrom
SojaSurfer:fix-national-map-usgs-keyerror
Aug 8, 2026
Merged

Fix KeyError in The_national_map_USGS.prodFormats #1353
giswqs merged 4 commits into
opengeos:masterfrom
SojaSurfer:fix-national-map-usgs-keyerror

Conversation

@SojaSurfer

@SojaSurfer SojaSurfer commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #1352

The Request response object of the dataset Imagery - NAIP (1 meter to .5 foot) does not include a "formats" key, causing a KeyError when the set comprehension assumed it always existed.

  • The set comprehension in prodFormats now checks if a "formats" key exists before accessing it.
  • Changed the return type annotation of the prodFormats and datasets properties from list to set to match their actual (unchanged) runtime return type
  • Updated the docstring of the datasets property to match the actual return type
  • Fixed docstring typo in Map.remove method

Summary by CodeRabbit

  • Bug Fixes

    • Improved dataset handling so entries without format information are skipped safely.
    • Corrected the reported return types for dataset and format listings.
  • Documentation

    • Fixed wording in a map-removal description for clearer, more accurate text.

Copilot AI lite review requested due to automatic review settings August 5, 2026 13:24
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cc42d30f-08fe-40d4-8a04-55aaa0ca91e8

📥 Commits

Reviewing files that changed from the base of the PR and between 68b31f9 and 26b7e3d.

📒 Files selected for processing (1)
  • leafmap/common.py

📝 Walkthrough

Walkthrough

The PR updates USGS property annotations to return sets, prevents prodFormats from accessing missing formats keys, and corrects the Map.remove docstring.

Changes

USGS API and documentation

Layer / File(s) Summary
USGS property contracts and format filtering
leafmap/common.py
prodFormats and datasets now declare set return types. prodFormats skips dataset entries without a formats field.
Map.remove documentation
leafmap/leafmap.py
The Map.remove docstring now says “removes a widget from the map.”

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: giswqs, steps-re

Poem

A rabbit checks the formats with care,
Skips missing keys in open air.
Sets now match what properties provide,
“From the map” makes wording right.
Hop, hop—clean code arrives!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: fixing the KeyError in The_national_map_USGS.prodFormats.
Linked Issues check ✅ Passed The PR prevents the reported KeyError by checking for the formats key before accessing it in prodFormats.
Out of Scope Changes check ✅ Passed The type annotation, docstring, and wording updates are related to the reported fix and stated PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Copilot AI 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.

Pull request overview

This PR fixes a KeyError in The_national_map_USGS.prodFormats when The National Map API returns dataset entries that omit the "formats" key, and aligns the Python type hints/docstrings with the properties’ actual return types.

Changes:

  • Guarded prodFormats against missing "formats" keys in dataset entries.
  • Updated return type annotations for prodFormats and datasets from list to set (and adjusted the datasets docstring accordingly).
  • Corrected a docstring typo in Map.remove.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
leafmap/leafmap.py Docstring correction for Map.remove.
leafmap/common.py Fixes prodFormats KeyError on missing "formats"; updates type hints/docstrings to match set return types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread leafmap/common.py Outdated
Comment thread leafmap/common.py Outdated
giswqs and others added 2 commits August 8, 2026 17:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@giswqs
giswqs merged commit 0dbd2c2 into opengeos:master Aug 8, 2026
20 of 21 checks passed
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.

KeyError: "formats" in The_national_map_USGS.prodFormats when a dataset entry lacks a formats key

3 participants