From 67f40b5c6713b6a461d943c5b9fc373f6ed27d35 Mon Sep 17 00:00:00 2001 From: MoMo Date: Sat, 14 Feb 2026 05:32:50 +0200 Subject: [PATCH 1/2] Stop overriding global warnings.formatwarning Plotly was modifying warnings.formatwarning globally, which affected the entire Python environment and could break other libraries' warning output. Removed the global assignment while keeping the function available internally if needed. This allows plotly to coexist nicely with other libraries without polluting the warning system. Fixes #5472 --- plotly/matplotlylib/renderer.py | 5 ++++- plotly/tools.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plotly/matplotlylib/renderer.py b/plotly/matplotlylib/renderer.py index d55f86ef3c2..169c317760e 100644 --- a/plotly/matplotlylib/renderer.py +++ b/plotly/matplotlylib/renderer.py @@ -19,7 +19,10 @@ def warning_on_one_line(msg, category, filename, lineno, file=None, line=None): return "%s:%s: %s:\n\n%s\n\n" % (filename, lineno, category.__name__, msg) -warnings.formatwarning = warning_on_one_line +# Note: We no longer globally modify warnings.formatwarning to avoid polluting +# the user's warning system. If custom warning formatting is needed internally, +# use warnings.warn_explicit() or format within specific warning calls. + class PlotlyRenderer(Renderer): diff --git a/plotly/tools.py b/plotly/tools.py index 67f828204d7..dbb117aa07c 100644 --- a/plotly/tools.py +++ b/plotly/tools.py @@ -60,7 +60,10 @@ def warning_on_one_line(message, category, filename, lineno, file=None, line=Non return "%s:%s: %s:\n\n%s\n\n" % (filename, lineno, category.__name__, message) -warnings.formatwarning = warning_on_one_line +# Note: We no longer globally modify warnings.formatwarning to avoid polluting +# the user's warning system. If custom warning formatting is needed internally, +# use warnings.warn_explicit() or format within specific warning calls. + ### mpl-related tools ### From 5f9fa6d37c26f5a4ee5fd53a414862435f2fed77 Mon Sep 17 00:00:00 2001 From: MoMo Date: Sat, 14 Feb 2026 07:03:34 +0200 Subject: [PATCH 2/2] Apply ruff formatting --- plotly/matplotlylib/renderer.py | 1 - plotly/tools.py | 1 - 2 files changed, 2 deletions(-) diff --git a/plotly/matplotlylib/renderer.py b/plotly/matplotlylib/renderer.py index 169c317760e..151b016679d 100644 --- a/plotly/matplotlylib/renderer.py +++ b/plotly/matplotlylib/renderer.py @@ -24,7 +24,6 @@ def warning_on_one_line(msg, category, filename, lineno, file=None, line=None): # use warnings.warn_explicit() or format within specific warning calls. - class PlotlyRenderer(Renderer): """A renderer class inheriting from base for rendering mpl plots in plotly. diff --git a/plotly/tools.py b/plotly/tools.py index dbb117aa07c..cb3332a781e 100644 --- a/plotly/tools.py +++ b/plotly/tools.py @@ -65,7 +65,6 @@ def warning_on_one_line(message, category, filename, lineno, file=None, line=Non # use warnings.warn_explicit() or format within specific warning calls. - ### mpl-related tools ### def mpl_to_plotly(fig, resize=False, strip_style=False, verbose=False): """Convert a matplotlib figure to plotly dictionary and send.