Skip to content

Commit

Permalink
Fixed global theme tests for gggrid()
Browse files Browse the repository at this point in the history
  • Loading branch information
RYangazov committed Apr 22, 2024
1 parent 3eb3735 commit 8c2c842
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 4 additions & 0 deletions python-package/lets_plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion python-package/lets_plot/plot/gggrid_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 2 additions & 8 deletions python-package/test/plot/test_gggrid_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'}
Expand All @@ -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'}
Expand Down

0 comments on commit 8c2c842

Please sign in to comment.