Skip to content

Commit a810263

Browse files
committed
test warn no xyticklabels
1 parent d9c772f commit a810263

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

mplotutils/_cartopy_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ def yticklabels(
322322

323323
if not y_label_points:
324324
msg = (
325-
"WARN: no points found for ylabel\n"
325+
"no points found for ylabel. "
326326
f"y_lim is: {y_lim[0]:0.2f} to {y_lim[1]:0.2f}"
327327
)
328-
warnings.warn(msg)
328+
warnings.warn(msg, stacklevel=2)
329329

330330
# get a transform instance that mpl understands
331331
transform = ccrs.PlateCarree()._as_mpl_transform(ax)
@@ -421,10 +421,10 @@ def xticklabels(
421421

422422
if not x_label_points:
423423
msg = (
424-
"WARN: no points found for xlabel\n"
424+
"no points found for xlabel. "
425425
f"x_lim is: {x_lim[0]:0.2f} to {x_lim[1]:0.2f}"
426426
)
427-
warnings.warn(msg)
427+
warnings.warn(msg, stacklevel=2)
428428

429429
# get a transform instance that mpl understands
430430
transform = ccrs.PlateCarree()._as_mpl_transform(ax)

mplotutils/tests/test_mapticklabels.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def test_xticklabels_robinson(pass_ax):
7171
assert ax.texts[-1].get_text() == "120°E"
7272

7373

74+
def test_xyticklabels_not_on_map():
75+
76+
with subplots_context(subplot_kw=dict(projection=ccrs.PlateCarree())) as (f, ax):
77+
# restrict extent
78+
ax.set_extent([0, 180, -90, 0], ccrs.PlateCarree())
79+
80+
with pytest.warns(match="no points found for xlabel"):
81+
mpu.xticklabels([180, 270, 360], ax=ax, size=8)
82+
83+
with pytest.warns(match="no points found for ylabel"):
84+
mpu.yticklabels([0, 45, 90], ax=ax, size=8)
85+
86+
7487
# TODO: https://github.com/mpytools/mplotutils/issues/48
7588
# def test_xticklabels_robinson_180():
7689

0 commit comments

Comments
 (0)