codeant-ai-for-open-source[bot] commented on code in PR #45607:
URL: https://github.com/apache/superset/pull/45607#discussion_r4357055321


##########
superset-frontend/plugins/plugin-chart-country-map/scripts/maps/assemble.py:
##########
@@ -0,0 +1,84 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Combines the plain country catalog with the registered per-country
+module overrides into the final set of maps to ship, matching the
+notebook's `get_gdf()` + purge-single-subdivision-countries cells.
+"""
+
+from __future__ import annotations
+
+import geopandas as gpd
+
+from .catalog import COUNTRIES, COUNTRY_NAME_ALIASES
+from .context import BuildContext
+
+
+def get_gdf(
+    ctx: BuildContext, built: dict[str, gpd.GeoDataFrame], name: str
+) -> gpd.GeoDataFrame:
+    """Resolves a single country/map name to its GeoDataFrame: a
+    registered module's output if one exists, otherwise a plain Natural
+    Earth lookup by (aliased) admin name.
+    """
+    if name in built:
+        return built[name].copy()
+
+    alias = COUNTRY_NAME_ALIASES.get(name, name)
+    return ctx.df[ctx.df["admin"].str.lower() == alias].copy()
+
+
+def validate_catalog(ctx: BuildContext, built: dict[str, gpd.GeoDataFrame]) -> 
None:
+    """Raises if a plain catalog entry doesn't resolve to any Natural
+    Earth rows (and isn't covered by a registered module instead).
+    """
+    admins = set(ctx.df["admin"].str.lower().unique())
+    invalid = [
+        name
+        for name in COUNTRIES
+        if name not in built and COUNTRY_NAME_ALIASES.get(name, name) not in 
admins
+    ]
+    if invalid:
+        raise ValueError(f"Following country names are not valid: {invalid}")
+
+
+def purged_countries(
+    ctx: BuildContext, built: dict[str, gpd.GeoDataFrame]
+) -> list[str]:
+    """Plain catalog entries with one subdivision or fewer - useless as a
+    choropleth, so dropped from the output (and any stale file for one
+    should be deleted, in case upstream data used to have more).
+    """
+    return [
+        name
+        for name in COUNTRIES
+        if get_gdf(ctx, built, name)["iso_3166_2"].nunique() <= 1
+    ]
+
+
+def resolve_all(
+    ctx: BuildContext, built: dict[str, gpd.GeoDataFrame]
+) -> dict[str, gpd.GeoDataFrame]:
+    """Returns the final {name: GeoDataFrame} map to save: every plain
+    catalog entry with more than one subdivision (others are dropped -
+    they'd be useless as a choropleth), plus every registered module
+    output (region-variant maps included, even though they aren't in
+    the plain catalog at all).
+    """
+    purged = set(purged_countries(ctx, built))
+    kept_plain = [name for name in COUNTRIES if name not in purged]
+    all_names = sorted(set(kept_plain) | set(built.keys()))

Review Comment:
   **Suggestion:** With `--countries`, unbuilt module-managed countries remain 
in `kept_plain` and are resolved from raw Natural Earth data, overwriting their 
corrected maps.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Often` ยท ๐Ÿท๏ธ `Logic error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d2d2a49d5e194232b0076f19f5672c8a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d2d2a49d5e194232b0076f19f5672c8a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/plugin-chart-country-map/scripts/maps/assemble.py
   **Line:** 83:83
   **Comment:**
        *Logic Error: With `--countries`, unbuilt module-managed countries 
remain in `kept_plain` and are resolved from raw Natural Earth data, 
overwriting their corrected maps.
   
   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
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45607&comment_hash=f8dfa6df8e6c44b55f8ce7f1e19af11503a59778eb85311e93fc4aa8d6dd49f6&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45607&comment_hash=f8dfa6df8e6c44b55f8ce7f1e19af11503a59778eb85311e93fc4aa8d6dd49f6&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to