Skip to content

fix(chart): updates counties of kenya map#38019

Merged
rusackas merged 4 commits into
apache:masterfrom
drzackyll:drzackyll/fix/kenya-map-geography
Jul 22, 2026
Merged

fix(chart): updates counties of kenya map#38019
rusackas merged 4 commits into
apache:masterfrom
drzackyll:drzackyll/fix/kenya-map-geography

Conversation

@drzackyll

Copy link
Copy Markdown
Contributor

SUMMARY

This PR updates the administrative areas of the Kenya country map visualization to reflect redrawn counties as of 2010. As discussed here, Natural Earth has not been updated in quite some time and it seems best to adjust the map in this way.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
Screenshot 2026-02-16 at 7 27 16 PM

After:
Screenshot 2026-02-16 at 7 33 04 PM

TESTING INSTRUCTIONS

Access a dataset with modern ISO 3166-2:KE codes and attempt to plot data on the Kenya country map.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@bito-code-review

bito-code-review Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Bito Review Skipped - No Changes Detected

Bito didn't review this pull request because we did not detect any changes in the pull request to review.

@dosubot dosubot Bot added the viz:charts:map Related to Map charts label Feb 16, 2026
@rusackas

Copy link
Copy Markdown
Member

Thanks for picking this up — the old map really was broken (per #34100), and aligning with ISO 3166-2:KE (KE-01KE-47) is clearly the right direction.

Two things I'd like to nail down before approving:

  1. Data provenance / licensing. The notebook reads from https://raw.githubusercontent.com/drzackyll/kenya-counties/main/counties.geojson, which is a personal repo. For an Apache release we should be sourcing the boundaries from an authoritative, clearly-licensed dataset (e.g. Kenya NBS, OCHA HDX, GADM, or Natural Earth if/when they update). Could you confirm the original provenance and license of that GeoJSON, and point the notebook at the upstream source directly? A short note in the notebook (or a README alongside it) citing the source and license would be ideal.

  2. Breaking change heads-up. This swaps the key space from the old province codes (KE-110, KE-200, …, KE-800) to the 47 county codes. Any dashboard currently joining on the old codes will break silently after upgrade. Would you mind adding a short entry to UPDATING.md under the next release so users know to re-key their Kenya data to ISO 3166-2:KE?

Once those are addressed I'm happy to approve.

@drzackyll
drzackyll force-pushed the drzackyll/fix/kenya-map-geography branch from af9dc2e to 04c606e Compare May 21, 2026 13:18
drzackyll added a commit to drzackyll/superset that referenced this pull request May 21, 2026
- Update Kenya GeoJSON source in notebook to geoBoundaries (CC BY 4.0),
  pinned to commit 9469f09 for reproducibility, replacing the previous
  personal GitHub repo URL with an authoritative, licensed source
- Add column rename (shapeName→name, shapeISO→iso_3166_2) to match the
  save_geojson() function expected schema
- Add UPDATING.md entry documenting the key-space change from old province
  codes (KE-110…KE-800) to ISO 3166-2:KE county codes (KE-01…KE-47)

Addresses reviewer feedback on PR apache#38019.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drzackyll

Copy link
Copy Markdown
Contributor Author

@rusackas branch is updated!

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but technically a breaking change for anyone who has maps with the current countries. Will add this ton the proposals for the 7.0 breaking change window, happening imminently.

@rusackas rusackas moved this to Propose for Lazy Consensus in Apache Superset 7.0 Jun 15, 2026
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.15%. Comparing base (60a7c18) to head (ceecb75).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #38019   +/-   ##
=======================================
  Coverage   65.15%   65.15%           
=======================================
  Files        2789     2789           
  Lines      157543   157543           
  Branches    35864    35864           
=======================================
  Hits       102644   102644           
  Misses      52931    52931           
  Partials     1968     1968           
Flag Coverage Δ
javascript 71.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas

Copy link
Copy Markdown
Member

Breaking window is now open, so we can merge this! But... the notebook is conflicting again. If you see a clean way to update/rebase it so both your changes and the upstream changes survive here, I'm happy to merge.

I can try to do so soon-ish, but probably won't be immediate... I'd appreciate the help.

devin-ai-integration Bot pushed a commit to raymondtangsc/superset that referenced this pull request Jul 20, 2026
- Update Kenya GeoJSON source in notebook to geoBoundaries (CC BY 4.0),
  pinned to commit 9469f09 for reproducibility, replacing the previous
  personal GitHub repo URL with an authoritative, licensed source
- Add column rename (shapeName→name, shapeISO→iso_3166_2) to match the
  save_geojson() function expected schema
- Add UPDATING.md entry documenting the key-space change from old province
  codes (KE-110…KE-800) to ISO 3166-2:KE county codes (KE-01…KE-47)

Addresses reviewer feedback on PR apache#38019.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@villebro villebro moved this from Propose for Lazy Consensus to Lazy Consensus Reached in Apache Superset 7.0 Jul 20, 2026
@rusackas
rusackas force-pushed the drzackyll/fix/kenya-map-geography branch from 04c606e to c544e1d Compare July 21, 2026 18:27
rusackas pushed a commit to drzackyll/superset that referenced this pull request Jul 21, 2026
- Update Kenya GeoJSON source in notebook to geoBoundaries (CC BY 4.0),
  pinned to commit 9469f09 for reproducibility, replacing the previous
  personal GitHub repo URL with an authoritative, licensed source
- Add column rename (shapeName→name, shapeISO→iso_3166_2) to match the
  save_geojson() function expected schema
- Add UPDATING.md entry documenting the key-space change from old province
  codes (KE-110…KE-800) to ISO 3166-2:KE county codes (KE-01…KE-47)

Addresses reviewer feedback on PR apache#38019.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "kenya_copy = df[df.admin == 'Kenya'].copy()\n# Source: geoBoundaries Kenya ADM1 (CC BY 4.0) via OCHA HDX\n# https://data.humdata.org/dataset/geoboundaries-admin-boundaries-for-kenya\nkenya_geojson_url = \"https://github.com/wmgeolab/geoBoundaries/raw/9469f09/releaseData/gbOpen/KEN/ADM1/geoBoundaries-KEN-ADM1.geojson\"\n\ntry:\n kenya_gdf = gpd.read_file(kenya_geojson_url)\n kenya_gdf = kenya_gdf.rename(columns={'shapeName': 'name', 'shapeISO': 'iso_3166_2'})\n kenya_copy = gpd.GeoDataFrame(\n kenya_gdf,\n geometry='geometry',\n crs=kenya_gdf.crs\n )\n \n print(\"GeoJSON file for Kenya downloaded and loaded successfully.\")\nexcept Exception as e:\n print(f\"Unable to download or load the GeoJSON file for Kenya. Error: {str(e)}\")\n print(\"Please download the file from the URL and try again.\")\n\nnot speed_run and kenya_copy.plot(**plot_styles)"

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.

Suggestion: The error handler catches all exceptions and then continues execution, which means Kenya will silently fall back to the old Natural Earth geometry if the download/load fails, defeating this fix while still producing output. Fail fast (or explicitly stop adding Kenya to the mapping) when the new GeoJSON cannot be loaded. [logic error]

Severity Level: Major ⚠️
- ❌ Kenya legacy country map may retain outdated boundaries.
- ⚠️ Generated Kenya GeoJSON inconsistent with 2010 counties.
- ⚠️ Notebook run appears successful despite Kenya data failure.
Steps of Reproduction ✅
1. Open the Jupyter notebook at
`superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON
Generator.ipynb` and run cells up to the Kenya section defined at line 2397 (cell with
`kenya_copy = df[df.admin == 'Kenya'].copy()` and the `try`/`except` around
`gpd.read_file(kenya_geojson_url)`).

2. Execute this Kenya cell in an environment where the GitHub URL
`geoBoundaries-KEN-ADM1.geojson` is unreachable (e.g., no internet or blocked GitHub),
causing `gpd.read_file(kenya_geojson_url)` in the `try` block at line 2397 to raise an
exception.

3. Observe that the `except Exception as e:` block at line 2397 catches the error, prints
the failure messages, and then completes the cell without modifying `kenya_copy`, which
still holds the original Natural Earth geometry from `df[df.admin == 'Kenya'].copy()`.

4. Run the later cell that builds the country mapping dictionary at lines 3954–3957, where
`"kenya": kenya_copy,` is added; subsequently running the export cells (below this hunk in
the notebook) will generate GeoJSON for Kenya using the stale Natural Earth boundaries
while the notebook execution appears successful.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb
**Line:** 2397:2397
**Comment:**
	*Logic Error: The error handler catches all exceptions and then continues execution, which means Kenya will silently fall back to the old Natural Earth geometry if the download/load fails, defeating this fix while still producing output. Fail fast (or explicitly stop adding Kenya to the mapping) when the new GeoJSON cannot be loaded.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch, fixed. The except now re-raises instead of silently falling back to the old Natural Earth geometry.

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The current implementation catches exceptions during the GeoJSON download and load process but continues execution, resulting in the use of stale Natural Earth geometry. To resolve this, you should raise an exception or explicitly clear the kenya_copy variable in the except block to ensure the notebook fails or stops if the new data cannot be loaded.

superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb

except Exception as e:
    print(f"Unable to download or load the GeoJSON file for Kenya. Error: {str(e)}")
    raise e

@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 5fe0e8c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a60347b7274c60009f7b715
😎 Deploy Preview https://deploy-preview-38019--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@rusackas

Copy link
Copy Markdown
Member

Looking good to me, but double checking if we can safely use this data under the source's licensing.

rusackas pushed a commit to drzackyll/superset that referenced this pull request Jul 22, 2026
- Update Kenya GeoJSON source in notebook to geoBoundaries (CC BY 4.0),
  pinned to commit 9469f09 for reproducibility, replacing the previous
  personal GitHub repo URL with an authoritative, licensed source
- Add column rename (shapeName→name, shapeISO→iso_3166_2) to match the
  save_geojson() function expected schema
- Add UPDATING.md entry documenting the key-space change from old province
  codes (KE-110…KE-800) to ISO 3166-2:KE county codes (KE-01…KE-47)

Addresses reviewer feedback on PR apache#38019.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rusackas
rusackas force-pushed the drzackyll/fix/kenya-map-geography branch from 1636d6f to 5fe0e8c Compare July 22, 2026 03:09
rusackas pushed a commit to drzackyll/superset that referenced this pull request Jul 22, 2026
- Update Kenya GeoJSON source in notebook to geoBoundaries (CC BY 4.0),
  pinned to commit 9469f09 for reproducibility, replacing the previous
  personal GitHub repo URL with an authoritative, licensed source
- Add column rename (shapeName→name, shapeISO→iso_3166_2) to match the
  save_geojson() function expected schema
- Add UPDATING.md entry documenting the key-space change from old province
  codes (KE-110…KE-800) to ISO 3166-2:KE county codes (KE-01…KE-47)

Addresses reviewer feedback on PR apache#38019.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rusackas
rusackas force-pushed the drzackyll/fix/kenya-map-geography branch from ceecb75 to 916016a Compare July 22, 2026 10:31
Zack Adams and others added 4 commits July 22, 2026 08:57
- Update Kenya GeoJSON source in notebook to geoBoundaries (CC BY 4.0),
  pinned to commit 9469f09 for reproducibility, replacing the previous
  personal GitHub repo URL with an authoritative, licensed source
- Add column rename (shapeName→name, shapeISO→iso_3166_2) to match the
  save_geojson() function expected schema
- Add UPDATING.md entry documenting the key-space change from old province
  codes (KE-110…KE-800) to ISO 3166-2:KE county codes (KE-01…KE-47)

Addresses reviewer feedback on PR apache#38019.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Re-raise the download/load error instead of silently swallowing it,
so the notebook doesn't produce stale Natural Earth boundaries for
Kenya while looking like it succeeded.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The notebook and code comment claimed the geoBoundaries Kenya ADM1
boundaries are CC BY 4.0. geoBoundaries' own per-boundary metadata
(https://www.geoboundaries.org/api/current/gbOpen/KEN/ADM1/) lists this
specific dataset as Public Domain, sourced from RCMRD / Africa GeoPortal,
not geoBoundaries' project-wide CC BY 4.0 terms.

Also corrects a county name geoBoundaries truncates ("Tharaka" ->
"Tharaka-Nithi"), and adds an explicit simplify factor for Kenya so the
generated file lands in the same size range as comparable countries
(previously ballooned to ~8MB unsimplified since Kenya's bounding-box
size narrowly misses the notebook's existing simplification threshold).
kenya.geojson is regenerated accordingly (160KB, 47 valid counties).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rusackas
rusackas force-pushed the drzackyll/fix/kenya-map-geography branch from 916016a to 05e2e91 Compare July 22, 2026 15:59
@rusackas
rusackas merged commit be5744c into apache:master Jul 22, 2026
62 checks passed
@rusackas

Copy link
Copy Markdown
Member

Thanks for this PR! It'll be in Superset 7.0 :D

@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

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

Labels

Projects

Status: Lazy Consensus Reached

Development

Successfully merging this pull request may close these issues.

3 participants