From 8c2c8422fe1b80b99f43c2b92c96ac9bf0990349 Mon Sep 17 00:00:00 2001 From: Rashid Yangazov <129742127+RYangazov@users.noreply.github.com> Date: Fri, 19 Apr 2024 18:17:36 +0200 Subject: [PATCH] Fixed global theme tests for gggrid() --- python-package/lets_plot/__init__.py | 4 ++++ python-package/lets_plot/plot/gggrid_.py | 2 +- python-package/test/plot/test_gggrid_theme.py | 10 ++-------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/python-package/lets_plot/__init__.py b/python-package/lets_plot/__init__.py index 1f9a3c43b48..8abb5f70258 100644 --- a/python-package/lets_plot/__init__.py +++ b/python-package/lets_plot/__init__.py @@ -171,6 +171,10 @@ def set_theme(cls, theme: Union['core.FeatureSpec', 'core.FeatureSpecArray']): Theme spec provided by `theme(...)`, `theme_xxx()`, `flavor_xxx()` functions, or their sum. """ + if theme is None: + _set_global_theme(None) + return + if theme.kind != 'theme' and not (theme.kind == 'feature-list' and all(f.kind == 'theme' for f in theme)): raise ValueError("Only `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported") diff --git a/python-package/lets_plot/plot/gggrid_.py b/python-package/lets_plot/plot/gggrid_.py index 12e1aa0f7ca..ab2fd22f724 100644 --- a/python-package/lets_plot/plot/gggrid_.py +++ b/python-package/lets_plot/plot/gggrid_.py @@ -119,7 +119,7 @@ def gggrid(plots: list, ncol: int = None, *, def _strip_theme_if_global(fig): # Strip global theme options from plots in grid (see issue: #966). - if global_theme_options is not None and fig is not None and 'theme' in fig.props() and fig.props()['theme'] == global_theme_options: + if global_theme_options is not None and fig is not None and 'theme' in fig.props() and fig.props()['theme'] == global_theme_options.props(): if isinstance(fig, PlotSpec): fig = PlotSpec.duplicate(fig) fig.props().pop('theme') diff --git a/python-package/test/plot/test_gggrid_theme.py b/python-package/test/plot/test_gggrid_theme.py index 5b10e57cbd0..32d3de16a35 100644 --- a/python-package/test/plot/test_gggrid_theme.py +++ b/python-package/test/plot/test_gggrid_theme.py @@ -6,8 +6,6 @@ import lets_plot as gg -from lets_plot._global_settings import PLOT_THEME - def test_gggrid_theme(): spec = gg.gggrid([gg.ggplot()]) + gg.theme_grey() @@ -43,9 +41,7 @@ def test_gggrid_global_theme_override(): spec = gg.gggrid([gg.ggplot()]) + gg.theme_light() finally: # Clear global setting - gg.LetsPlot.set({ - PLOT_THEME: None - }) + gg.LetsPlot.set_theme(None) assert 'theme' in spec.as_dict() assert spec.as_dict()['theme'] == {'name': 'light'} @@ -67,9 +63,7 @@ def test_gggrid_global_theme_override_cancelled(): spec = gg.gggrid([fig]) + gg.theme_light() finally: # Clear global setting - gg.LetsPlot.set({ - PLOT_THEME: None - }) + gg.LetsPlot.set_theme(None) assert 'theme' in spec.as_dict() assert spec.as_dict()['theme'] == {'name': 'light'}