From 7746eccb4f9dd042a3f5b39452f161ff5985ae21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 12 Sep 2024 18:50:10 +0200 Subject: [PATCH 1/6] Don't show all elements if nothing is selected by visibile --- holonote/annotate/display.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/holonote/annotate/display.py b/holonote/annotate/display.py index d926843..6494ec4 100644 --- a/holonote/annotate/display.py +++ b/holonote/annotate/display.py @@ -537,8 +537,8 @@ def static_indicators(self, **events): msg = f"{self.region_format} not implemented" raise NotImplementedError(msg) - if len(indicator.data) == 0: - return hv.NdOverlay({0: self._make_empty_element()}) + if len(indicator.data) == 0 or not self.annotator.visible: + return hv.NdOverlay({0: self._make_empty_element()}).opts(show_legend=False) if self.annotator.groupby and self.annotator.visible: indicator = indicator.get(self.annotator.visible) From ddbc31fc8afffc53bcbef2397cef4e9e510cc607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 12 Sep 2024 19:03:55 +0200 Subject: [PATCH 2/6] Debug --- holonote/annotate/annotator.py | 2 +- holonote/annotate/display.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/holonote/annotate/annotator.py b/holonote/annotate/annotator.py index e37c0d5..85de7a5 100644 --- a/holonote/annotate/annotator.py +++ b/holonote/annotate/annotator.py @@ -321,7 +321,7 @@ class Annotator(AnnotatorInterface): groupby = param.Selector(default=None, doc="Groupby dimension", allow_refs=True) visible = param.ListSelector( - default=[], doc="Visible dimensions, needs groupby enabled", allow_refs=True + default=None, doc="Visible dimensions, needs groupby enabled", allow_refs=True ) style = param.ClassSelector(default=Style(), class_=Style, doc="Style parameters") diff --git a/holonote/annotate/display.py b/holonote/annotate/display.py index 6494ec4..43f3e59 100644 --- a/holonote/annotate/display.py +++ b/holonote/annotate/display.py @@ -537,8 +537,12 @@ def static_indicators(self, **events): msg = f"{self.region_format} not implemented" raise NotImplementedError(msg) - if len(indicator.data) == 0 or not self.annotator.visible: - return hv.NdOverlay({0: self._make_empty_element()}).opts(show_legend=False) + if len(indicator.data) == 0 or ( + self.annotator.groupby + and self.annotator.visible is not None + and not len(self.annotator.visible) + ): + return hv.NdOverlay({0: self._make_empty_element()}) # .opts(show_legend=False) if self.annotator.groupby and self.annotator.visible: indicator = indicator.get(self.annotator.visible) From 09eb44aaa18386d38d5e05a762a33a026b3d59d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 13 Sep 2024 09:36:19 +0200 Subject: [PATCH 3/6] Apply default opts on empty plot --- holonote/annotate/display.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/holonote/annotate/display.py b/holonote/annotate/display.py index 43f3e59..5a28f01 100644 --- a/holonote/annotate/display.py +++ b/holonote/annotate/display.py @@ -542,7 +542,9 @@ def static_indicators(self, **events): and self.annotator.visible is not None and not len(self.annotator.visible) ): - return hv.NdOverlay({0: self._make_empty_element()}) # .opts(show_legend=False) + el = self._make_empty_element() + el_opts = getattr(hv.opts, type(el).__name__)(**_default_opts) + return hv.NdOverlay({0: el}).opts(el_opts) if self.annotator.groupby and self.annotator.visible: indicator = indicator.get(self.annotator.visible) From e0da4d82fcdef61e3c1a0915a98df131e27c2659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 13 Sep 2024 09:54:20 +0200 Subject: [PATCH 4/6] Add test for case --- holonote/tests/test_annotators_element.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/holonote/tests/test_annotators_element.py b/holonote/tests/test_annotators_element.py index 32fd244..d2c6ec1 100644 --- a/holonote/tests/test_annotators_element.py +++ b/holonote/tests/test_annotators_element.py @@ -251,6 +251,14 @@ def test_groupby_visible(cat_annotator): next(iter_indicator) +def test_groupby_visible_empty(cat_annotator): + cat_annotator.groupby = "category" + cat_annotator.visible = [] + iter_indicator = get_indicator(cat_annotator, hv.Curve) + indicator = next(iter_indicator) + assert indicator.data.shape == (0, 2) + + def test_groupby_with_overlay_from_empty_annotator(annotator_range2d, capsys): # Test for https://github.com/holoviz/holonote/issues/119 annotator = annotator_range2d From cfbd63c52e54318a7752320779a3799fe76bc2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 13 Sep 2024 09:55:11 +0200 Subject: [PATCH 5/6] Enforce get_indicator_data have the correct element type --- holonote/tests/test_annotators_element.py | 4 ++-- holonote/tests/test_annotators_style.py | 2 +- holonote/tests/util.py | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/holonote/tests/test_annotators_element.py b/holonote/tests/test_annotators_element.py index d2c6ec1..b843a90 100644 --- a/holonote/tests/test_annotators_element.py +++ b/holonote/tests/test_annotators_element.py @@ -37,7 +37,7 @@ def test_set_regions_range1d(annotator_range1d) -> None: expected = [None, None] assert output == expected - output = next(get_indicator_data(annotator, hv.Rectangles)) + output = next(get_indicator_data(annotator, hv.VSpans)) output1 = output.iloc[0][["start[TIME]", "end[TIME]"]].tolist() expected1 = [-0.25, 0.25] assert output1 == expected1 @@ -115,7 +115,7 @@ def test_set_regions_multiple(multiple_annotators): expected = [None, None] assert output == expected - output = next(get_indicator_data(annotator, hv.Rectangles, "TIME")) + output = next(get_indicator_data(annotator, hv.VSpans, "TIME")) output1 = output.iloc[0][["start[TIME]", "end[TIME]"]].tolist() expected1 = [-0.25, 0.25] assert output1 == expected1 diff --git a/holonote/tests/test_annotators_style.py b/holonote/tests/test_annotators_style.py index a730648..aef866d 100644 --- a/holonote/tests/test_annotators_style.py +++ b/holonote/tests/test_annotators_style.py @@ -38,7 +38,7 @@ def compare_style(cat_annotator): def get_selected_indicator_data(annotator) -> pd.Series: - df = pd.concat([i.data for i in get_indicator(annotator, hv.VLines)]) + df = pd.concat([i.data for i in get_indicator(annotator, None)]) return df["__selected__"] diff --git a/holonote/tests/util.py b/holonote/tests/util.py index ef61368..29b2d72 100644 --- a/holonote/tests/util.py +++ b/holonote/tests/util.py @@ -26,7 +26,10 @@ def get_editor_data(annotator, element_type, kdims=None): def get_indicator(annotator, element_type, kdims=None): si = _get_display(annotator, kdims).indicators().last - yield from si.data.values() + if element_type: + yield from (s for s in si.data.values() if isinstance(s, element_type)) + else: + yield from si.data.values() def get_indicator_data(annotator, element_type, kdims=None): From e53baa3040a045834235509701de8280145439b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 13 Sep 2024 09:55:45 +0200 Subject: [PATCH 6/6] Ignore debug warning --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 4e2d13d..0ad8135 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,8 @@ filterwarnings = [ "ignore:datetime.datetime.utcfromtimestamp():DeprecationWarning:dateutil.tz.tz", # https://github.com/dateutil/dateutil/pull/1285 # 2024-01 "ignore:\\s+Pyarrow will become a required dependency of pandas", # Will fix itself + # 2024-09 + "ignore:The (non_)?interactive_bk attribute was deprecated in Matplotlib 3.9", # OK - Only happening in debug mode ] [tool.ruff]