Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

Summary

  • Replace cartopy gridliner monkey-patching with local _CartopyGridliner/_CartopyLabel subclasses and a gridlines() override.
  • Unify cartopy/basemap gridliner behavior via adapters, shared side-mapping, and adapter-owned tick positions.
  • Split GeoAxes.format into focused helpers for clarity and extensibility; add format flow comment.
  • Preserve legacy gridliner toggle behavior for empty label arrays (fixes test_cartesian_and_geo).

User API is the same.

Copy link
Contributor

Copilot AI left a comment

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 refactors the GeoAxes gridliner handling to eliminate cartopy monkey-patching in favor of local subclasses and introduces a unified adapter pattern for both cartopy and basemap backends. The core changes improve code maintainability and extensibility by creating clear abstraction boundaries.

Changes:

  • Replaced cartopy monkey-patching with _CartopyGridliner and _CartopyLabel subclasses
  • Introduced _GridlinerAdapter protocol with backend-specific implementations (_CartopyGridlinerAdapter and _BasemapGridlinerAdapter)
  • Split the large GeoAxes.format() method into focused helper methods for improved clarity
  • Added comprehensive type hints throughout the geographic axes implementation

Reviewed changes

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

File Description
ultraplot/tests/test_geographic.py Added comprehensive tests for gridliner label handling, adapter refresh, tick positions, and tick_params updates across both cartopy and basemap backends
ultraplot/axes/geo.py Major refactoring: introduced adapter pattern, removed monkey patches, split format() into focused helpers, added type hints, and unified backend handling
Comments suppressed due to low confidence (4)

ultraplot/axes/geo.py:3141

  • For loop variable 'obj' is not used in the loop body.
                        for obj in feat:

ultraplot/axes/geo.py:24

  • Import of 'mtransforms' is not used.
import matplotlib.transforms as mtransforms

ultraplot/axes/geo.py:29

  • Import of 'pticker' is not used.
from .. import ticker as pticker

ultraplot/axes/geo.py:39

  • Import of 'ic' is not used.
from ..internals import (
    _not_none,
    _pop_rc,
    _version_cartopy,
    docstring,
    ic,  # noqa: F401
    labels,
    warnings,
)

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

@@ -1469,7 +2336,7 @@ class _CartopyAxes(GeoAxes, _GeoAxes):
# NOTE: The rename argument wrapper belongs here instead of format() because
# these arguments were previously only accepted during initialization.
@warnings._rename_kwargs("0.10", circular="round", autoextent="extent")
def __init__(self, *args, map_projection=None, **kwargs):
def __init__(self, *args: Any, map_projection: Any = None, **kwargs: Any) -> None:
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

This initialization method calls GeoAxes.init multiple times, via this call and this call.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

This comment was marked as resolved.

@cvanelteren
Copy link
Collaborator Author

@cvanelteren I've opened a new pull request, #455, to work on those changes. Once the pull request is ready, I'll request review from you.

Bad copilot, you messed things up

@cvanelteren cvanelteren force-pushed the refactor/geo-gridliner-adapters branch from c6f6a2b to 8952108 Compare January 11, 2026 09:13
@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

❌ Patch coverage is 95.19231% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/tests/test_geographic.py 95.19% 0 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren cvanelteren merged commit 0cd86ba into main Jan 11, 2026
36 of 53 checks passed
@cvanelteren cvanelteren deleted the refactor/geo-gridliner-adapters branch January 11, 2026 10:37
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.

2 participants