From aba3ab2a0e2a22816a8a1b4bebac0bf685fdd656 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 12 Nov 2024 09:47:50 -0500 Subject: [PATCH 1/7] display deprecated warnings for mapbox traces and skip their validation in templates --- packages/python/plotly/codegen/datatypes.py | 22 +++++ .../python/plotly/plotly/basedatatypes.py | 85 +++++++++++-------- .../plotly/graph_objs/_choroplethmapbox.py | 8 ++ .../plotly/graph_objs/_densitymapbox.py | 8 ++ .../plotly/graph_objs/_scattermapbox.py | 8 ++ 5 files changed, 95 insertions(+), 36 deletions(-) diff --git a/packages/python/plotly/codegen/datatypes.py b/packages/python/plotly/codegen/datatypes.py index b9ff134fb49..0feb4e915fd 100644 --- a/packages/python/plotly/codegen/datatypes.py +++ b/packages/python/plotly/codegen/datatypes.py @@ -5,6 +5,13 @@ from codegen.utils import PlotlyNode, write_source_py +Deprecated_mapbox_traces = [ + "scattermapbox", + "choroplethmapbox", + "densitymapbox", +] + + def get_typing_type(plotly_type, array_ok=False): """ Get Python type corresponding to a valType string from the plotly schema @@ -95,6 +102,9 @@ 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") + # Write class definition # ---------------------- buffer.write( @@ -400,6 +410,18 @@ def __init__(self""" """ ) + if node.name_property in Deprecated_mapbox_traces: + buffer.write( + f""" + warn( + "*{node.name_property}* is deprecated!" + + " Use *{node.name_property.replace("mapbox", "map")}* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2 + ) +""" + ) + # Return source string # -------------------- return buffer.getvalue() diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index a3044f6763a..d4c70663a30 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -28,6 +28,12 @@ # - Setting a property to Undefined leaves existing value unmodified Undefined = object() +Deprecated_mapbox_traces = [ + "scattermapbox", + "choroplethmapbox", + "densitymapbox", +] + def _len_dict_item(item): """ @@ -4840,49 +4846,56 @@ def __setitem__(self, prop, value): # ### Unwrap scalar tuple ### prop = prop[0] - if self._validate: - if prop not in self._valid_props: - self._raise_on_invalid_property_error()(prop) + # skip deprecated mapbox templates + if ( + prop not in Deprecated_mapbox_traces + or "template" not in self._parent_path_str + ): + if self._validate: + if prop not in self._valid_props: + self._raise_on_invalid_property_error()(prop) - # ### Get validator for this property ### - validator = self._get_validator(prop) + # ### Get validator for this property ### + validator = self._get_validator(prop) - # ### Handle compound property ### - if isinstance(validator, CompoundValidator): - self._set_compound_prop(prop, value) + # ### Handle compound property ### + if isinstance(validator, CompoundValidator): + self._set_compound_prop(prop, value) - # ### Handle compound array property ### - elif isinstance(validator, (CompoundArrayValidator, BaseDataValidator)): - self._set_array_prop(prop, value) + # ### Handle compound array property ### + elif isinstance( + validator, (CompoundArrayValidator, BaseDataValidator) + ): + self._set_array_prop(prop, value) - # ### Handle simple property ### + # ### Handle simple property ### + else: + self._set_prop(prop, value) else: - self._set_prop(prop, value) - else: - # Make sure properties dict is initialized - self._init_props() - - if isinstance(value, BasePlotlyType): - # Extract json from graph objects - value = value.to_plotly_json() - - # Check for list/tuple of graph objects - if ( - isinstance(value, (list, tuple)) - and value - and isinstance(value[0], BasePlotlyType) - ): - value = [ - v.to_plotly_json() if isinstance(v, BasePlotlyType) else v - for v in value - ] + # Make sure properties dict is initialized + self._init_props() + + if isinstance(value, BasePlotlyType): + # Extract json from graph objects + value = value.to_plotly_json() + + # Check for list/tuple of graph objects + if ( + isinstance(value, (list, tuple)) + and value + and isinstance(value[0], BasePlotlyType) + ): + value = [ + v.to_plotly_json() if isinstance(v, BasePlotlyType) else v + for v in value + ] - self._props[prop] = value + self._props[prop] = value - # Remove any already constructed graph object so that it will be - # reconstructed on property access - self._compound_props.pop(prop, None) - self._compound_array_props.pop(prop, None) + # Remove any already constructed graph object so that it will be + # reconstructed on property access + self._compound_props.pop(prop, None) + self._compound_array_props.pop(prop, None) # Handle non-scalar case # ---------------------- diff --git a/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py b/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py index f07047a991e..4db487c4438 100644 --- a/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py +++ b/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py @@ -1,5 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy +from warnings import warn class Choroplethmapbox(_BaseTraceType): @@ -2378,3 +2379,10 @@ def __init__( # Reset skip_invalid # ------------------ self._skip_invalid = False + + warn( + "*choroplethmapbox* is deprecated!" + + " Use *choroplethmap* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + ) diff --git a/packages/python/plotly/plotly/graph_objs/_densitymapbox.py b/packages/python/plotly/plotly/graph_objs/_densitymapbox.py index 7d2c41e1268..775f114c9b4 100644 --- a/packages/python/plotly/plotly/graph_objs/_densitymapbox.py +++ b/packages/python/plotly/plotly/graph_objs/_densitymapbox.py @@ -1,5 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy +from warnings import warn class Densitymapbox(_BaseTraceType): @@ -2319,3 +2320,10 @@ def __init__( # Reset skip_invalid # ------------------ self._skip_invalid = False + + warn( + "*densitymapbox* is deprecated!" + + " Use *densitymap* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + ) diff --git a/packages/python/plotly/plotly/graph_objs/_scattermapbox.py b/packages/python/plotly/plotly/graph_objs/_scattermapbox.py index 34e72ecf037..e35a88d20b6 100644 --- a/packages/python/plotly/plotly/graph_objs/_scattermapbox.py +++ b/packages/python/plotly/plotly/graph_objs/_scattermapbox.py @@ -1,5 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy +from warnings import warn class Scattermapbox(_BaseTraceType): @@ -2292,3 +2293,10 @@ def __init__( # Reset skip_invalid # ------------------ self._skip_invalid = False + + warn( + "*scattermapbox* is deprecated!" + + " Use *scattermap* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + ) From 401026001813ed45f275ab7ba56524004758ebaa Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:31:21 -0500 Subject: [PATCH 2/7] add DeprecationWarning warning type in codegen --- packages/python/plotly/codegen/datatypes.py | 3 ++- packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py | 1 + packages/python/plotly/plotly/graph_objs/_densitymapbox.py | 1 + packages/python/plotly/plotly/graph_objs/_scattermapbox.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/codegen/datatypes.py b/packages/python/plotly/codegen/datatypes.py index 0feb4e915fd..aa44a3afd00 100644 --- a/packages/python/plotly/codegen/datatypes.py +++ b/packages/python/plotly/codegen/datatypes.py @@ -417,7 +417,8 @@ def __init__(self""" "*{node.name_property}* is deprecated!" + " Use *{node.name_property.replace("mapbox", "map")}* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", - stacklevel=2 + stacklevel=2, + category=DeprecationWarning, ) """ ) diff --git a/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py b/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py index 4db487c4438..c1c14e6d4a0 100644 --- a/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py +++ b/packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py @@ -2385,4 +2385,5 @@ def __init__( + " Use *choroplethmap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", stacklevel=2, + category=DeprecationWarning, ) diff --git a/packages/python/plotly/plotly/graph_objs/_densitymapbox.py b/packages/python/plotly/plotly/graph_objs/_densitymapbox.py index 775f114c9b4..8498ab2d17e 100644 --- a/packages/python/plotly/plotly/graph_objs/_densitymapbox.py +++ b/packages/python/plotly/plotly/graph_objs/_densitymapbox.py @@ -2326,4 +2326,5 @@ def __init__( + " Use *densitymap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", stacklevel=2, + category=DeprecationWarning, ) diff --git a/packages/python/plotly/plotly/graph_objs/_scattermapbox.py b/packages/python/plotly/plotly/graph_objs/_scattermapbox.py index e35a88d20b6..c7494d48fbe 100644 --- a/packages/python/plotly/plotly/graph_objs/_scattermapbox.py +++ b/packages/python/plotly/plotly/graph_objs/_scattermapbox.py @@ -2299,4 +2299,5 @@ def __init__( + " Use *scattermap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", stacklevel=2, + category=DeprecationWarning, ) From c187794843922c5fd747594b2a352fb7f93c5590 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:32:55 -0500 Subject: [PATCH 3/7] capitalization --- packages/python/plotly/codegen/datatypes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/python/plotly/codegen/datatypes.py b/packages/python/plotly/codegen/datatypes.py index aa44a3afd00..deb1c9bbdf9 100644 --- a/packages/python/plotly/codegen/datatypes.py +++ b/packages/python/plotly/codegen/datatypes.py @@ -5,7 +5,7 @@ from codegen.utils import PlotlyNode, write_source_py -Deprecated_mapbox_traces = [ +deprecated_mapbox_traces = [ "scattermapbox", "choroplethmapbox", "densitymapbox", @@ -102,7 +102,7 @@ def build_datatype_py(node): ) buffer.write(f"import copy as _copy\n") - if node.name_property in Deprecated_mapbox_traces: + if node.name_property in deprecated_mapbox_traces: buffer.write(f"from warnings import warn\n") # Write class definition @@ -410,7 +410,7 @@ def __init__(self""" """ ) - if node.name_property in Deprecated_mapbox_traces: + if node.name_property in deprecated_mapbox_traces: buffer.write( f""" warn( From cb3dba7921883c348410240fc81738c1b44f909b Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:52:41 -0500 Subject: [PATCH 4/7] clean up basedatatypes (return to previous) --- .../python/plotly/plotly/basedatatypes.py | 81 +++++++++---------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index d4c70663a30..bfb64069fd2 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -4846,56 +4846,51 @@ def __setitem__(self, prop, value): # ### Unwrap scalar tuple ### prop = prop[0] - # skip deprecated mapbox templates - if ( - prop not in Deprecated_mapbox_traces - or "template" not in self._parent_path_str - ): - if self._validate: - if prop not in self._valid_props: - self._raise_on_invalid_property_error()(prop) + if self._validate: + if prop not in self._valid_props: + self._raise_on_invalid_property_error()(prop) - # ### Get validator for this property ### - validator = self._get_validator(prop) + # ### Get validator for this property ### + validator = self._get_validator(prop) - # ### Handle compound property ### - if isinstance(validator, CompoundValidator): - self._set_compound_prop(prop, value) + # ### Handle compound property ### + if isinstance(validator, CompoundValidator): + self._set_compound_prop(prop, value) - # ### Handle compound array property ### - elif isinstance( - validator, (CompoundArrayValidator, BaseDataValidator) - ): - self._set_array_prop(prop, value) + # ### Handle compound array property ### + elif isinstance( + validator, (CompoundArrayValidator, BaseDataValidator) + ): + self._set_array_prop(prop, value) - # ### Handle simple property ### - else: - self._set_prop(prop, value) + # ### Handle simple property ### else: - # Make sure properties dict is initialized - self._init_props() - - if isinstance(value, BasePlotlyType): - # Extract json from graph objects - value = value.to_plotly_json() - - # Check for list/tuple of graph objects - if ( - isinstance(value, (list, tuple)) - and value - and isinstance(value[0], BasePlotlyType) - ): - value = [ - v.to_plotly_json() if isinstance(v, BasePlotlyType) else v - for v in value - ] + self._set_prop(prop, value) + else: + # Make sure properties dict is initialized + self._init_props() + + if isinstance(value, BasePlotlyType): + # Extract json from graph objects + value = value.to_plotly_json() + + # Check for list/tuple of graph objects + if ( + isinstance(value, (list, tuple)) + and value + and isinstance(value[0], BasePlotlyType) + ): + value = [ + v.to_plotly_json() if isinstance(v, BasePlotlyType) else v + for v in value + ] - self._props[prop] = value + self._props[prop] = value - # Remove any already constructed graph object so that it will be - # reconstructed on property access - self._compound_props.pop(prop, None) - self._compound_array_props.pop(prop, None) + # Remove any already constructed graph object so that it will be + # reconstructed on property access + self._compound_props.pop(prop, None) + self._compound_array_props.pop(prop, None) # Handle non-scalar case # ---------------------- From 9908d72e1fbe9d4f3236de815269f0a99f9d1bc6 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Mon, 25 Nov 2024 01:44:11 -0500 Subject: [PATCH 5/7] add deprecation warnings to px mapbox functions --- .../plotly/plotly/express/_chart_types.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index 614431f19a2..c6e14fa3932 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1,3 +1,5 @@ +from warnings import warn + from ._core import make_figure from ._doc import make_docstring import plotly.graph_objs as go @@ -1415,9 +1417,18 @@ def scatter_mapbox( height=None, ) -> go.Figure: """ + *scatter_mapbox* is deprecated! Use *scatter_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox scatter plot, each row of `data_frame` is represented by a symbol mark on a Mapbox map. """ + warn( + "*scatter_mapbox* is deprecated!" + + " Use *scatter_map* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + category=DeprecationWarning, + ) return make_figure(args=locals(), constructor=go.Scattermapbox) @@ -1453,9 +1464,18 @@ def choropleth_mapbox( height=None, ) -> go.Figure: """ + *choropleth_mapbox* is deprecated! Use *choropleth_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox choropleth map, each row of `data_frame` is represented by a colored region on a Mapbox map. """ + warn( + "*choropleth_mapbox* is deprecated!" + + " Use *choropleth_map* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + category=DeprecationWarning, + ) return make_figure(args=locals(), constructor=go.Choroplethmapbox) @@ -1489,9 +1509,18 @@ def density_mapbox( height=None, ) -> go.Figure: """ + *density_mapbox* is deprecated! Use *density_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox density map, each row of `data_frame` contributes to the intensity of the color of the region around the corresponding point on the map """ + warn( + "*density_mapbox* is deprecated!" + + " Use *density_map* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + category=DeprecationWarning, + ) return make_figure( args=locals(), constructor=go.Densitymapbox, trace_patch=dict(radius=radius) ) @@ -1526,9 +1555,18 @@ def line_mapbox( height=None, ) -> go.Figure: """ + *line_mapbox* is deprecated! Use *line_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox line plot, each row of `data_frame` is represented as a vertex of a polyline mark on a Mapbox map. """ + warn( + "*line_mapbox* is deprecated!" + + " Use *line_map* instead." + + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", + stacklevel=2, + category=DeprecationWarning, + ) return make_figure(args=locals(), constructor=go.Scattermapbox) From 3b31f3a1ff16683ba9ce3c8d3e2dfa040a6ca98f Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:09:18 -0500 Subject: [PATCH 6/7] formatting --- packages/python/plotly/plotly/basedatatypes.py | 4 +--- .../python/plotly/plotly/express/_chart_types.py | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index bfb64069fd2..9cc1571e255 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -4858,9 +4858,7 @@ def __setitem__(self, prop, value): self._set_compound_prop(prop, value) # ### Handle compound array property ### - elif isinstance( - validator, (CompoundArrayValidator, BaseDataValidator) - ): + elif isinstance(validator, (CompoundArrayValidator, BaseDataValidator)): self._set_array_prop(prop, value) # ### Handle simple property ### diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index c6e14fa3932..9ec2b4a6a63 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1417,8 +1417,8 @@ def scatter_mapbox( height=None, ) -> go.Figure: """ - *scatter_mapbox* is deprecated! Use *scatter_map* instead. - Learn more at: https://plotly.com/python/mapbox-to-maplibre/ + *scatter_mapbox* is deprecated! Use *scatter_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox scatter plot, each row of `data_frame` is represented by a symbol mark on a Mapbox map. """ @@ -1464,8 +1464,8 @@ def choropleth_mapbox( height=None, ) -> go.Figure: """ - *choropleth_mapbox* is deprecated! Use *choropleth_map* instead. - Learn more at: https://plotly.com/python/mapbox-to-maplibre/ + *choropleth_mapbox* is deprecated! Use *choropleth_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox choropleth map, each row of `data_frame` is represented by a colored region on a Mapbox map. """ @@ -1509,8 +1509,8 @@ def density_mapbox( height=None, ) -> go.Figure: """ - *density_mapbox* is deprecated! Use *density_map* instead. - Learn more at: https://plotly.com/python/mapbox-to-maplibre/ + *density_mapbox* is deprecated! Use *density_map* instead. + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox density map, each row of `data_frame` contributes to the intensity of the color of the region around the corresponding point on the map """ @@ -1556,7 +1556,7 @@ def line_mapbox( ) -> go.Figure: """ *line_mapbox* is deprecated! Use *line_map* instead. - Learn more at: https://plotly.com/python/mapbox-to-maplibre/ + Learn more at: https://plotly.com/python/mapbox-to-maplibre/ In a Mapbox line plot, each row of `data_frame` is represented as a vertex of a polyline mark on a Mapbox map. """ From 5d113b9b269f29dd6a5b2e0aa5cc3fae037a6642 Mon Sep 17 00:00:00 2001 From: Emily Kellison-Linn <4672118+emilykl@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:21:57 -0500 Subject: [PATCH 7/7] cleanup --- packages/python/plotly/plotly/basedatatypes.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 9cc1571e255..a3044f6763a 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -28,12 +28,6 @@ # - Setting a property to Undefined leaves existing value unmodified Undefined = object() -Deprecated_mapbox_traces = [ - "scattermapbox", - "choroplethmapbox", - "densitymapbox", -] - def _len_dict_item(item): """