Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for mapbox deprecation warnings
  • Loading branch information
emilykl committed Mar 12, 2025
commit 9243f6d7760ad94a988c58bd3c0dee0531b1e5ef
27 changes: 27 additions & 0 deletions tests/test_core/test_graph_objs/test_graph_objs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest import TestCase
import warnings

import pytest
import plotly.graph_objs as go


Expand Down Expand Up @@ -154,3 +156,28 @@ def test_pop_invalid_prop_key_error(self):

def test_pop_invalid_prop_with_default(self):
self.assertEqual(self.layout.pop("bogus", 42), 42)

class TestDeprecationWarnings(TestCase):
def test_warn_on_deprecated_mapbox_traces(self):
# This test will fail if any of the following traces
# fails to emit a DeprecationWarning
for trace_constructor in [
go.Scattermapbox,
go.Densitymapbox,
go.Choroplethmapbox,
]:
with pytest.warns(DeprecationWarning):
_ = go.Figure([trace_constructor()])

def test_no_warn_on_non_deprecated_traces(self):
# This test will fail if any of the following traces emits a DeprecationWarning
for trace_constructor in [
go.Scatter,
go.Bar,
go.Scattermap,
go.Densitymap,
go.Choroplethmap,
]:
with warnings.catch_warnings():
warnings.simplefilter("error")
_ = go.Figure([trace_constructor()])
48 changes: 47 additions & 1 deletion tests/test_optional/test_px/test_px.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from itertools import permutations
import warnings

import plotly.express as px
import plotly.io as pio
import narwhals.stable.v1 as nw
import numpy as np
import pytest
from itertools import permutations


def test_scatter(backend):
Expand Down Expand Up @@ -394,3 +396,47 @@ def test_load_px_data(return_type):
else:
df = getattr(px.data, fname)(return_type=return_type)
assert len(df) > 0


def test_warn_on_deprecated_mapbox_px_constructors():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

# This test will fail if any of the following px constructors
# fails to emit a DeprecationWarning
for fig_constructor in [
px.line_mapbox,
px.scatter_mapbox,
px.density_mapbox,
px.choropleth_mapbox,
]:
# Look for warnings with the string "_mapbox" in them
# to make sure the warning is coming from px rather than go
with pytest.warns(DeprecationWarning, match="_mapbox"):
if fig_constructor == px.choropleth_mapbox:
fig_constructor(locations=["CA", "TX", "NY"])
else:
fig_constructor(lat=[10, 20, 30], lon=[10, 20, 30])

def test_no_warn_on_non_deprecated_px_constructors():
# This test will fail if any of the following px constructors
# emits a DeprecationWarning
for fig_constructor in [
px.scatter,
px.line,
px.scatter_map,
px.density_map,
px.choropleth_map,
]:
with warnings.catch_warnings():
warnings.simplefilter("error")
if fig_constructor == px.choropleth_map:
fig_constructor(locations=["CA", "TX", "NY"])
elif fig_constructor in {px.scatter_map, px.density_map}:
fig_constructor(lat=[10, 20, 30], lon=[10, 20, 30])
else:
fig_constructor(x=[1, 2, 3], y=[1, 2, 3])

def test_no_warn_on_update_template():
# This test will fail if update_layout(template=...) emits a DeprecationWarning
fig = px.line(x=[1, 2, 3], y=[1, 2, 3])
with warnings.catch_warnings():
warnings.simplefilter("error")
fig.update_layout(template="plotly_white")