From e2d58d25885d6b1a1ee83c221ab316b8e88f9ca3 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() --- future_changes.md | 3 ++- python-package/lets_plot/__init__.py | 4 ++++ python-package/lets_plot/plot/gggrid_.py | 2 +- python-package/test/plot/test_gggrid_theme.py | 10 ++-------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/future_changes.md b/future_changes.md index 7dcf1ace8d1..5f05ca66194 100644 --- a/future_changes.md +++ b/future_changes.md @@ -5,4 +5,5 @@ ### Changed ### Fixed -- `to_svg()`, `to_html()`: return the content as string if no "path" is given. [[#1067](https://github.com/JetBrains/lets-plot/issues/1067)]. \ No newline at end of file +- `to_svg()`, `to_html()`: return the content as string if no "path" is given. [[#1067](https://github.com/JetBrains/lets-plot/issues/1067)]. +- Regression of issue [[#966](https://github.com/JetBrains/lets-plot/issues/966)]. \ No newline at end of file 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'}