From a810263603a454135ba1dcba7827aa0b997280d9 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Tue, 23 Sep 2025 15:33:46 +0200 Subject: [PATCH 1/2] test warn no xyticklabels --- mplotutils/_cartopy_utils.py | 8 ++++---- mplotutils/tests/test_mapticklabels.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/mplotutils/_cartopy_utils.py b/mplotutils/_cartopy_utils.py index 2b9b2a8..2661bb2 100644 --- a/mplotutils/_cartopy_utils.py +++ b/mplotutils/_cartopy_utils.py @@ -322,10 +322,10 @@ def yticklabels( if not y_label_points: msg = ( - "WARN: no points found for ylabel\n" + "no points found for ylabel. " f"y_lim is: {y_lim[0]:0.2f} to {y_lim[1]:0.2f}" ) - warnings.warn(msg) + warnings.warn(msg, stacklevel=2) # get a transform instance that mpl understands transform = ccrs.PlateCarree()._as_mpl_transform(ax) @@ -421,10 +421,10 @@ def xticklabels( if not x_label_points: msg = ( - "WARN: no points found for xlabel\n" + "no points found for xlabel. " f"x_lim is: {x_lim[0]:0.2f} to {x_lim[1]:0.2f}" ) - warnings.warn(msg) + warnings.warn(msg, stacklevel=2) # get a transform instance that mpl understands transform = ccrs.PlateCarree()._as_mpl_transform(ax) diff --git a/mplotutils/tests/test_mapticklabels.py b/mplotutils/tests/test_mapticklabels.py index 9afd569..6375c75 100644 --- a/mplotutils/tests/test_mapticklabels.py +++ b/mplotutils/tests/test_mapticklabels.py @@ -71,6 +71,19 @@ def test_xticklabels_robinson(pass_ax): assert ax.texts[-1].get_text() == "120°E" +def test_xyticklabels_not_on_map(): + + with subplots_context(subplot_kw=dict(projection=ccrs.PlateCarree())) as (f, ax): + # restrict extent + ax.set_extent([0, 180, -90, 0], ccrs.PlateCarree()) + + with pytest.warns(match="no points found for xlabel"): + mpu.xticklabels([180, 270, 360], ax=ax, size=8) + + with pytest.warns(match="no points found for ylabel"): + mpu.yticklabels([0, 45, 90], ax=ax, size=8) + + # TODO: https://github.com/mpytools/mplotutils/issues/48 # def test_xticklabels_robinson_180(): From f7dca62848b23ca146e7099aec7649a66d489e64 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Tue, 23 Sep 2025 15:35:04 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de857e5..6597b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ ### Enhancements - Add python 3.13 to list of supported versions ([#158](https://github.com/mpytools/mplotutils/pull/158)). -- Increased test coverage ([#180](https://github.com/mpytools/mplotutils/pull/180)). +- Increased test coverage ([#180](https://github.com/mpytools/mplotutils/pull/180), and [#181](https://github.com/mpytools/mplotutils/pull/181)). ### Bug fixes