Skip to content

Commit c2225b7

Browse files
committed
add DeprecationWarning for upcoming change in locationmode 'country names'
1 parent deef7a3 commit c2225b7

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

codegen/datatypes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"choroplethmapbox",
1111
"densitymapbox",
1212
]
13+
locationmode_traces = [
14+
"choropleth",
15+
"scattergeo",
16+
]
1317

1418

1519
def get_typing_type(plotly_type, array_ok=False):
@@ -100,6 +104,7 @@ def build_datatype_py(node):
100104

101105
if (
102106
node.name_property in deprecated_mapbox_traces
107+
or node.name_property in locationmode_traces
103108
or node.name_property == "template"
104109
):
105110
buffer.write("import warnings\n")
@@ -341,6 +346,27 @@ def __init__(self"""
341346
constructor must be a dict or
342347
an instance of :class:`{class_name}`\"\"\")
343348
349+
"""
350+
)
351+
352+
# Add warning for 'country names' locationmode
353+
if node.name_property in locationmode_traces:
354+
buffer.write(
355+
f"""
356+
if locationmode == "country names" and kwargs.get("_validate"):
357+
warnings.warn(
358+
"The library used by the *country names* `locationmode` option is changing in an upcoming version. "
359+
"Country names in existing plots may not work in the new version. "
360+
"To ensure consistent behavior, consider setting `locationmode` to *ISO-3*.",
361+
DeprecationWarning,
362+
stacklevel=5,
363+
)
364+
365+
"""
366+
)
367+
368+
buffer.write(
369+
f"""
344370
self._skip_invalid = kwargs.pop("skip_invalid", False)
345371
self._validate = kwargs.pop("_validate", True)
346372
"""

plotly/express/_chart_types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,16 @@ def choropleth(
11101110
In a choropleth map, each row of `data_frame` is represented by a
11111111
colored region mark on a map.
11121112
"""
1113+
1114+
if locationmode == "country names":
1115+
warn(
1116+
"The library used by the *country names* `locationmode` option is changing in an upcoming version. "
1117+
"Country names in existing plots may not work in the new version. "
1118+
"To ensure consistent behavior, consider setting `locationmode` to *ISO-3*.",
1119+
DeprecationWarning,
1120+
stacklevel=2,
1121+
)
1122+
11131123
return make_figure(
11141124
args=locals(),
11151125
constructor=go.Choropleth,
@@ -1168,6 +1178,16 @@ def scatter_geo(
11681178
In a geographic scatter plot, each row of `data_frame` is represented
11691179
by a symbol mark on a map.
11701180
"""
1181+
1182+
if locationmode == "country names":
1183+
warn(
1184+
"The library used by the *country names* `locationmode` option is changing in an upcoming version. "
1185+
"Country names in existing plots may not work in the new version. "
1186+
"To ensure consistent behavior, consider setting `locationmode` to *ISO-3*.",
1187+
DeprecationWarning,
1188+
stacklevel=2,
1189+
)
1190+
11711191
return make_figure(
11721192
args=locals(),
11731193
constructor=go.Scattergeo,

plotly/graph_objs/_choropleth.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
55
import copy as _copy
6+
import warnings
67

78

89
class Choropleth(_BaseTraceType):
@@ -1708,6 +1709,15 @@ def __init__(
17081709
constructor must be a dict or
17091710
an instance of :class:`plotly.graph_objs.Choropleth`""")
17101711

1712+
if locationmode == "country names" and kwargs.get("_validate"):
1713+
warnings.warn(
1714+
"The library used by the *country names* `locationmode` option is changing in an upcoming version. "
1715+
"Country names in existing plots may not work in the new version. "
1716+
"To ensure consistent behavior, consider setting `locationmode` to *ISO-3*.",
1717+
DeprecationWarning,
1718+
stacklevel=5,
1719+
)
1720+
17111721
self._skip_invalid = kwargs.pop("skip_invalid", False)
17121722
self._validate = kwargs.pop("_validate", True)
17131723

plotly/graph_objs/_scattergeo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
55
import copy as _copy
6+
import warnings
67

78

89
class Scattergeo(_BaseTraceType):
@@ -1804,6 +1805,15 @@ def __init__(
18041805
constructor must be a dict or
18051806
an instance of :class:`plotly.graph_objs.Scattergeo`""")
18061807

1808+
if locationmode == "country names" and kwargs.get("_validate"):
1809+
warnings.warn(
1810+
"The library used by the *country names* `locationmode` option is changing in an upcoming version. "
1811+
"Country names in existing plots may not work in the new version. "
1812+
"To ensure consistent behavior, consider setting `locationmode` to *ISO-3*.",
1813+
DeprecationWarning,
1814+
stacklevel=5,
1815+
)
1816+
18071817
self._skip_invalid = kwargs.pop("skip_invalid", False)
18081818
self._validate = kwargs.pop("_validate", True)
18091819

0 commit comments

Comments
 (0)