From b3aab37d257cd14e816a62ff80cb6a102708ae0a Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:29:44 -0400 Subject: [PATCH 1/2] modify codegen instead of modifying autogenerated _template.py file --- codegen/datatypes.py | 25 ++++++++++++++++++++----- plotly/graph_objs/_choroplethmapbox.py | 4 ++-- plotly/graph_objs/_densitymapbox.py | 4 ++-- plotly/graph_objs/_scattermapbox.py | 4 ++-- plotly/graph_objs/layout/_template.py | 4 ++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/codegen/datatypes.py b/codegen/datatypes.py index deb1c9bbdf..e928b666ab 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -102,8 +102,8 @@ def build_datatype_py(node): ) buffer.write(f"import copy as _copy\n") - if node.name_property in deprecated_mapbox_traces: - buffer.write(f"from warnings import warn\n") + if node.name_property in deprecated_mapbox_traces or node.name_property == "template": + buffer.write(f"import warnings\n") # Write class definition # ---------------------- @@ -375,9 +375,24 @@ def __init__(self""" f""" _v = arg.pop('{name_prop}', None) _v = {name_prop} if {name_prop} is not None else _v - if _v is not None: - self['{name_prop}'] = _v""" + if _v is not None:""" ) + if datatype_class == "Template" and name_prop == "data": + buffer.write( + """ + # Template.data contains a 'scattermapbox' key, which causes a + # go.Scattermapbox trace object to be created during validation. + # In order to prevent false deprecation warnings from surfacing, + # we suppress deprecation warnings for this line only. + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + self["data"] = _v""" + ) + else: + buffer.write( + f""" + self['{name_prop}'] = _v""" + ) # ### Literals ### if literal_nodes: @@ -413,7 +428,7 @@ def __init__(self""" if node.name_property in deprecated_mapbox_traces: buffer.write( f""" - warn( + warnings.warn( "*{node.name_property}* is deprecated!" + " Use *{node.name_property.replace("mapbox", "map")}* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/_choroplethmapbox.py b/plotly/graph_objs/_choroplethmapbox.py index c1c14e6d4a..9169bfcc15 100644 --- a/plotly/graph_objs/_choroplethmapbox.py +++ b/plotly/graph_objs/_choroplethmapbox.py @@ -1,6 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy -from warnings import warn +import warnings class Choroplethmapbox(_BaseTraceType): @@ -2380,7 +2380,7 @@ def __init__( # ------------------ self._skip_invalid = False - warn( + warnings.warn( "*choroplethmapbox* is deprecated!" + " Use *choroplethmap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/_densitymapbox.py b/plotly/graph_objs/_densitymapbox.py index 8498ab2d17..3623258306 100644 --- a/plotly/graph_objs/_densitymapbox.py +++ b/plotly/graph_objs/_densitymapbox.py @@ -1,6 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy -from warnings import warn +import warnings class Densitymapbox(_BaseTraceType): @@ -2321,7 +2321,7 @@ def __init__( # ------------------ self._skip_invalid = False - warn( + warnings.warn( "*densitymapbox* is deprecated!" + " Use *densitymap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/_scattermapbox.py b/plotly/graph_objs/_scattermapbox.py index c7494d48fb..9f98a2b1af 100644 --- a/plotly/graph_objs/_scattermapbox.py +++ b/plotly/graph_objs/_scattermapbox.py @@ -1,6 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy -from warnings import warn +import warnings class Scattermapbox(_BaseTraceType): @@ -2294,7 +2294,7 @@ def __init__( # ------------------ self._skip_invalid = False - warn( + warnings.warn( "*scattermapbox* is deprecated!" + " Use *scattermap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/layout/_template.py b/plotly/graph_objs/layout/_template.py index 69f6cf38ec..1f90ba94cb 100644 --- a/plotly/graph_objs/layout/_template.py +++ b/plotly/graph_objs/layout/_template.py @@ -1,10 +1,10 @@ +from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType import copy as _copy import warnings -from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType - class Template(_BaseLayoutHierarchyType): + # class properties # -------------------- _parent_path_str = "layout" From 22aa9bac3f56b0eb3fa02000b58cdff1762eaec6 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:37:51 -0400 Subject: [PATCH 2/2] format --- codegen/datatypes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/codegen/datatypes.py b/codegen/datatypes.py index e928b666ab..178c777850 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -102,7 +102,10 @@ def build_datatype_py(node): ) buffer.write(f"import copy as _copy\n") - if node.name_property in deprecated_mapbox_traces or node.name_property == "template": + if ( + node.name_property in deprecated_mapbox_traces + or node.name_property == "template" + ): buffer.write(f"import warnings\n") # Write class definition