Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aba3ab2

Browse files
committed
display deprecated warnings for mapbox traces and skip their validation in templates
1 parent 817fef7 commit aba3ab2

File tree

5 files changed

+95
-36
lines changed

5 files changed

+95
-36
lines changed

‎packages/python/plotly/codegen/datatypes.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
from codegen.utils import PlotlyNode, write_source_py
66

77

8+
Deprecated_mapbox_traces = [
9+
"scattermapbox",
10+
"choroplethmapbox",
11+
"densitymapbox",
12+
]
13+
14+
815
def get_typing_type(plotly_type, array_ok=False):
916
"""
1017
Get Python type corresponding to a valType string from the plotly schema
@@ -95,6 +102,9 @@ def build_datatype_py(node):
95102
)
96103
buffer.write(f"import copy as _copy\n")
97104

105+
if node.name_property in Deprecated_mapbox_traces:
106+
buffer.write(f"from warnings import warn\n")
107+
98108
# Write class definition
99109
# ----------------------
100110
buffer.write(
@@ -400,6 +410,18 @@ def __init__(self"""
400410
"""
401411
)
402412

413+
if node.name_property in Deprecated_mapbox_traces:
414+
buffer.write(
415+
f"""
416+
warn(
417+
"*{node.name_property}* is deprecated!"
418+
+ " Use *{node.name_property.replace("mapbox", "map")}* instead."
419+
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",
420+
stacklevel=2
421+
)
422+
"""
423+
)
424+
403425
# Return source string
404426
# --------------------
405427
return buffer.getvalue()

‎packages/python/plotly/plotly/basedatatypes.py‎

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
# - Setting a property to Undefined leaves existing value unmodified
2929
Undefined = object()
3030

31+
Deprecated_mapbox_traces = [
32+
"scattermapbox",
33+
"choroplethmapbox",
34+
"densitymapbox",
35+
]
36+
3137

3238
def _len_dict_item(item):
3339
"""
@@ -4840,49 +4846,56 @@ def __setitem__(self, prop, value):
48404846
# ### Unwrap scalar tuple ###
48414847
prop = prop[0]
48424848

4843-
if self._validate:
4844-
if prop not in self._valid_props:
4845-
self._raise_on_invalid_property_error()(prop)
4849+
# skip deprecated mapbox templates
4850+
if (
4851+
prop not in Deprecated_mapbox_traces
4852+
or "template" not in self._parent_path_str
4853+
):
4854+
if self._validate:
4855+
if prop not in self._valid_props:
4856+
self._raise_on_invalid_property_error()(prop)
48464857

4847-
# ### Get validator for this property ###
4848-
validator = self._get_validator(prop)
4858+
# ### Get validator for this property ###
4859+
validator = self._get_validator(prop)
48494860

4850-
# ### Handle compound property ###
4851-
if isinstance(validator, CompoundValidator):
4852-
self._set_compound_prop(prop, value)
4861+
# ### Handle compound property ###
4862+
if isinstance(validator, CompoundValidator):
4863+
self._set_compound_prop(prop, value)
48534864

4854-
# ### Handle compound array property ###
4855-
elif isinstance(validator, (CompoundArrayValidator, BaseDataValidator)):
4856-
self._set_array_prop(prop, value)
4865+
# ### Handle compound array property ###
4866+
elif isinstance(
4867+
validator, (CompoundArrayValidator, BaseDataValidator)
4868+
):
4869+
self._set_array_prop(prop, value)
48574870

4858-
# ### Handle simple property ###
4871+
# ### Handle simple property ###
4872+
else:
4873+
self._set_prop(prop, value)
48594874
else:
4860-
self._set_prop(prop, value)
4861-
else:
4862-
# Make sure properties dict is initialized
4863-
self._init_props()
4864-
4865-
if isinstance(value, BasePlotlyType):
4866-
# Extract json from graph objects
4867-
value = value.to_plotly_json()
4868-
4869-
# Check for list/tuple of graph objects
4870-
if (
4871-
isinstance(value, (list, tuple))
4872-
and value
4873-
and isinstance(value[0], BasePlotlyType)
4874-
):
4875-
value = [
4876-
v.to_plotly_json() if isinstance(v, BasePlotlyType) else v
4877-
for v in value
4878-
]
4875+
# Make sure properties dict is initialized
4876+
self._init_props()
4877+
4878+
if isinstance(value, BasePlotlyType):
4879+
# Extract json from graph objects
4880+
value = value.to_plotly_json()
4881+
4882+
# Check for list/tuple of graph objects
4883+
if (
4884+
isinstance(value, (list, tuple))
4885+
and value
4886+
and isinstance(value[0], BasePlotlyType)
4887+
):
4888+
value = [
4889+
v.to_plotly_json() if isinstance(v, BasePlotlyType) else v
4890+
for v in value
4891+
]
48794892

4880-
self._props[prop] = value
4893+
self._props[prop] = value
48814894

4882-
# Remove any already constructed graph object so that it will be
4883-
# reconstructed on property access
4884-
self._compound_props.pop(prop, None)
4885-
self._compound_array_props.pop(prop, None)
4895+
# Remove any already constructed graph object so that it will be
4896+
# reconstructed on property access
4897+
self._compound_props.pop(prop, None)
4898+
self._compound_array_props.pop(prop, None)
48864899

48874900
# Handle non-scalar case
48884901
# ----------------------

‎packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
22
import copy as _copy
3+
from warnings import warn
34

45

56
class Choroplethmapbox(_BaseTraceType):
@@ -2378,3 +2379,10 @@ def __init__(
23782379
# Reset skip_invalid
23792380
# ------------------
23802381
self._skip_invalid = False
2382+
2383+
warn(
2384+
"*choroplethmapbox* is deprecated!"
2385+
+ " Use *choroplethmap* instead."
2386+
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",
2387+
stacklevel=2,
2388+
)

‎packages/python/plotly/plotly/graph_objs/_densitymapbox.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
22
import copy as _copy
3+
from warnings import warn
34

45

56
class Densitymapbox(_BaseTraceType):
@@ -2319,3 +2320,10 @@ def __init__(
23192320
# Reset skip_invalid
23202321
# ------------------
23212322
self._skip_invalid = False
2323+
2324+
warn(
2325+
"*densitymapbox* is deprecated!"
2326+
+ " Use *densitymap* instead."
2327+
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",
2328+
stacklevel=2,
2329+
)

‎packages/python/plotly/plotly/graph_objs/_scattermapbox.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
22
import copy as _copy
3+
from warnings import warn
34

45

56
class Scattermapbox(_BaseTraceType):
@@ -2292,3 +2293,10 @@ def __init__(
22922293
# Reset skip_invalid
22932294
# ------------------
22942295
self._skip_invalid = False
2296+
2297+
warn(
2298+
"*scattermapbox* is deprecated!"
2299+
+ " Use *scattermap* instead."
2300+
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",
2301+
stacklevel=2,
2302+
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /