Skip to content

to_raster default-extent warning depends on Cartopy's initial extent #1469

Description

@rajeeja

Problem

UxDataArray.to_raster() originally only treated ax.get_xlim() == (0, 1) and ax.get_ylim() == (0, 1) as the default extent case before auto-setting the rasterization extent and warning the user.

That is too narrow for Cartopy GeoAxes: depending on the Cartopy/Matplotlib setup, a newly created axes may still be in its default state while reporting projection-scale/global limits instead of (0, 1). In that case the warning is skipped even though the user never set an extent.

How this showed up in tests

After adding warning assertions to the raster tests, these started failing inconsistently:

  • test/test_plot.py::test_to_raster
  • test/test_plot.py::test_to_raster_with_extra_dims
  • test/test_plot.py::test_to_raster_reuse_mapping

The tests expected the auto-extent warning, but on environments where Cartopy initialized the axes with projection/global limits rather than (0, 1), no warning was emitted.

Root cause

The implementation used one specific default-limit representation ((0, 1)) as a proxy for "user did not set extent". That assumption does not hold across Cartopy/Matplotlib environments.

Resolution

Use ax.get_autoscale_on() as the primary signal that the user has not explicitly set the extent, and then treat a near-global PlateCarree extent as default as well. This keeps the warning behavior consistent when Cartopy supplies projection defaults instead of (0, 1).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
📚 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions