Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed global theme tests for gggrid() #1083

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)].
- `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)].
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