Skip to content

Commit 3eb03e3

Browse files
authored
chore: deprecate basemap backend starting from version 3.0 (#786)
1 parent 2ab3b6c commit 3eb03e3

7 files changed

Lines changed: 85 additions & 11 deletions

File tree

‎docs/projections.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,10 @@
289289
# when they are omitted (e.g., ``lon0=0`` as the default for most projections).
290290
#
291291
# .. warning::
292-
# The `basemap`_ package is now being actively maintained again with a short hiatus for a few years. We originally
293-
# included basemap support because its gridline labeling was more powerful
294-
# than cartopy gridline labeling. While cartopy gridline labeling has
295-
# significantly improved since version 0.18, UltraPlot continues to support
296-
# both mapping libraries to give users flexibility in their visualization choices.
292+
# The basemap backend is deprecated as of version 3.0.0 and may be removed in a
293+
# future release. Please use the cartopy backend instead. Cartopy gridline
294+
# labeling has significantly improved since version 0.18 and now covers the
295+
# features we originally included basemap support for.
297296

298297
# %%
299298
import ultraplot as uplt

‎ultraplot/_subplots.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ def parse_backend(backend=None, basemap=None):
6666
Handle deprecation of basemap and cartopy package.
6767
"""
6868
if backend == "basemap":
69-
warnings._warn_ultraplot(
70-
f"{backend=} will be deprecated in next major release (v2.0). "
71-
"See https://github.com/Ultraplot/ultraplot/pull/243"
72-
)
69+
constructor._warn_basemap_deprecated()
7370
return backend
7471

7572
def parse_proj(
@@ -108,6 +105,7 @@ def parse_proj(
108105
):
109106
name = "ultraplot_basemap"
110107
kwargs["map_projection"] = proj
108+
constructor._warn_basemap_deprecated()
111109

112110
if name is None and isinstance(proj, str):
113111
try:

‎ultraplot/axes/base.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
backend : {'cartopy', 'basemap'}, default: :rc:`geo.backend`
105105
Whether to use `~mpl_toolkits.basemap.Basemap` or
106106
`~cartopy.crs.Projection` for map projections.
107+
108+
.. deprecated:: 3.0.0
109+
The ``'basemap'`` backend is deprecated and may be removed in a
110+
future release. Please use the ``'cartopy'`` backend instead.
107111
"""
108112
docstring._snippet_manager["axes.proj"] = _proj_docstring
109113
docstring._snippet_manager["axes.proj_kw"] = _proj_kw_docstring

‎ultraplot/constructor.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,17 @@ def Scale(scale, *args, **kwargs):
14841484
return scale(*args, **kwargs)
14851485

14861486

1487+
def _warn_basemap_deprecated():
1488+
"""
1489+
Warn that the basemap backend is deprecated.
1490+
"""
1491+
warnings._warn_ultraplot(
1492+
"The basemap backend was deprecated in version 3.0.0 and may be removed "
1493+
"in a future release. Please use the cartopy backend instead. "
1494+
"See https://github.com/Ultraplot/ultraplot/pull/243"
1495+
)
1496+
1497+
14871498
def Proj(
14881499
name,
14891500
backend=None,
@@ -1574,6 +1585,10 @@ def Proj(
15741585
backend : {'cartopy', 'basemap'}, default: :rc:`geo.backend`
15751586
Whether to return a cartopy `~cartopy.crs.Projection` instance
15761587
or a basemap `~mpl_toolkits.basemap.Basemap` instance.
1588+
1589+
.. deprecated:: 3.0.0
1590+
The ``'basemap'`` backend is deprecated and may be removed in a
1591+
future release. Please use the ``'cartopy'`` backend instead.
15771592
lon0, lat0 : float, optional
15781593
The central projection longitude and latitude. These are translated to
15791594
`central_longitude`, `central_latitude` for cartopy projections.
@@ -1670,6 +1685,8 @@ def Proj(
16701685
f"Unexpected projection {name!r}. Must be PROJ string name, "
16711686
"cartopy.crs.Projection, or mpl_toolkits.basemap.Basemap."
16721687
)
1688+
if backend == "basemap":
1689+
_warn_basemap_deprecated()
16731690
for key_proj, key_cartopy, value in (
16741691
("lon_0", "central_longitude", lon0),
16751692
("lat_0", "central_latitude", lat0),
@@ -1692,6 +1709,8 @@ def Proj(
16921709
warnings._warn_ultraplot(f"Ignoring Proj() keyword arg(s): {kwargs!r}.")
16931710
proj = name
16941711
backend = "cartopy" if is_crs else "basemap"
1712+
if is_basemap:
1713+
_warn_basemap_deprecated()
16951714

16961715
# Cartopy name
16971716
# NOTE: Error message matches basemap invalid projection message

‎ultraplot/internals/rcsetup.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,9 @@ def _validator_accepts(validator, value):
17641764
"cartopy",
17651765
_validate_belongs("cartopy", "basemap"),
17661766
"The backend used for `~ultraplot.axes.GeoAxes`. Must be "
1767-
"either 'cartopy' or 'basemap'.",
1767+
"either 'cartopy' or 'basemap'. "
1768+
".. deprecated:: 3.0.0 The 'basemap' backend is deprecated and may be "
1769+
"removed in a future release. Please use 'cartopy' instead.",
17681770
),
17691771
"geo.extent": (
17701772
"globe",

‎ultraplot/tests/test_constructor_helpers_extra.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Additional branch coverage for constructor helpers."""
33

44
import importlib
5+
import warnings
56

67
import cycler
78
import matplotlib.colors as mcolors
@@ -195,3 +196,35 @@ def test_proj_constructor_branches():
195196
constructor.Proj("merc", backend="cartopy", round=True)
196197
with pytest.raises(ValueError, match="unknown cartopy projection class"):
197198
constructor.Proj("not-a-proj", backend="cartopy")
199+
200+
201+
def test_proj_basemap_backend_deprecated():
202+
pytest.importorskip("mpl_toolkits.basemap")
203+
with pytest.warns(UltraPlotWarning, match="deprecated in version 3\\.0\\.0"):
204+
proj = constructor.Proj("npstere", backend="basemap")
205+
assert proj._proj_backend == "basemap"
206+
207+
208+
def test_proj_basemap_instance_deprecated():
209+
pytest.importorskip("mpl_toolkits.basemap")
210+
with pytest.warns(UltraPlotWarning, match="basemap backend was deprecated"):
211+
basemap_proj = constructor.Proj("npstere", backend="basemap")
212+
proj = constructor.Proj(basemap_proj)
213+
assert proj is basemap_proj
214+
assert proj._proj_backend == "basemap"
215+
216+
217+
def test_proj_basemap_rc_backend_deprecated():
218+
pytest.importorskip("mpl_toolkits.basemap")
219+
with uplt.rc.context({"geo.backend": "basemap"}):
220+
with pytest.warns(UltraPlotWarning, match="basemap backend was deprecated"):
221+
proj = constructor.Proj("npstere")
222+
assert proj._proj_backend == "basemap"
223+
224+
225+
def test_proj_cartopy_backend_no_warning():
226+
pytest.importorskip("cartopy")
227+
with warnings.catch_warnings():
228+
warnings.simplefilter("error", UltraPlotWarning)
229+
proj = constructor.Proj("npstere", backend="cartopy")
230+
assert proj._proj_backend == "cartopy"

‎ultraplot/tests/test_subplot_manager.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_gridspec_setter_accepts_ultraplot():
3333

3434
def test_parse_backend_basemap_warns():
3535
"""parse_backend emits a deprecation warning for basemap."""
36-
with pytest.warns(match="basemap"):
36+
with pytest.warns(match="basemap backend was deprecated"):
3737
SubplotManager.parse_backend(backend="basemap")
3838

3939

@@ -43,6 +43,25 @@ def test_parse_backend_passthrough():
4343
assert SubplotManager.parse_backend(backend=None) is None
4444

4545

46+
def test_subplots_basemap_backend_warns():
47+
"""Requesting the basemap backend emits a deprecation warning."""
48+
pytest.importorskip("mpl_toolkits.basemap")
49+
with pytest.warns(match="basemap backend was deprecated"):
50+
fig, axs = uplt.subplots(proj="cyl", backend="basemap")
51+
assert axs[0]._name == "basemap"
52+
uplt.close(fig)
53+
54+
55+
def test_subplots_basemap_instance_warns():
56+
"""Passing a Basemap instance as proj emits a deprecation warning."""
57+
pytest.importorskip("mpl_toolkits.basemap")
58+
with pytest.warns(match="basemap backend was deprecated"):
59+
proj = uplt.Proj("npstere", backend="basemap")
60+
fig, axs = uplt.subplots(proj=proj)
61+
assert axs[0]._name == "basemap"
62+
uplt.close(fig)
63+
64+
4665
def test_add_subplot_integer_arg():
4766
"""add_subplot(111) creates a single subplot."""
4867
fig = uplt.figure()

0 commit comments

Comments
 (0)