1010
1111import typing as t
1212
13- from ipywidgets import DOMWidget , Layout , ValueWidget , register
14- from ipywidgets .widgets .trait_types import Color
15- from traitlets import (
13+ from ipywidgets import DOMWidget , Layout , ValueWidget , register # type: ignore
14+ from ipywidgets .widgets .trait_types import Color # type: ignore
15+ from traitlets import ( # type: ignore
1616 Bool ,
1717 Dict ,
1818 Enum ,
5353
5454
5555def _sort_sets (
56- sets : t .Sequence [UpSetSet [T ]], order_by : str , limit : t .Optional [int ] = None ,
56+ sets : t .Sequence [UpSetSet [T ]],
57+ order_by : str ,
58+ limit : t .Optional [int ] = None ,
5759) -> t .List [UpSetSet [T ]]:
5860 key = None
5961 if order_by == "cardinality" :
@@ -145,24 +147,35 @@ def _create_combination(
145147) -> UpSetSetCombination :
146148 if combination_type == UpSetSetType .DISTINCT_INTERSECTION :
147149 return UpSetSetDistinctIntersection [T ](
148- cs_name , sets = sets , color = color_lookup .get (cs_name ), cardinality = count ,
150+ cs_name ,
151+ sets = sets ,
152+ color = color_lookup .get (cs_name ),
153+ cardinality = count ,
149154 )
150155 if combination_type == UpSetSetType .INTERSECTION :
151156 return UpSetSetIntersection [T ](
152- cs_name , sets = sets , color = color_lookup .get (cs_name ), cardinality = count ,
157+ cs_name ,
158+ sets = sets ,
159+ color = color_lookup .get (cs_name ),
160+ cardinality = count ,
153161 )
154162 if combination_type == UpSetSetType .UNION :
155163 return UpSetSetUnion [T ](
156- cs_name , sets = sets , color = color_lookup .get (cs_name ), cardinality = count ,
164+ cs_name ,
165+ sets = sets ,
166+ color = color_lookup .get (cs_name ),
167+ cardinality = count ,
157168 )
158169 return UpSetSetComposite [T ](
159- cs_name , sets = sets , color = color_lookup .get (cs_name ), cardinality = count ,
170+ cs_name ,
171+ sets = sets ,
172+ color = color_lookup .get (cs_name ),
173+ cardinality = count ,
160174 )
161175
162176
163177class UpSetJSBaseWidget (ValueWidget , DOMWidget , t .Generic [T ]):
164- """UpSet.js Base Widget
165- """
178+ """UpSet.js Base Widget"""
166179
167180 _model_name = Unicode ("UpSetModel" ).tag (sync = True )
168181 _model_module = Unicode (MODULE_NAME ).tag (sync = True )
@@ -185,12 +198,14 @@ class UpSetJSBaseWidget(ValueWidget, DOMWidget, t.Generic[T]):
185198 elems : t .List [T ] = List (default_value = []).tag (sync = True )
186199 elem_to_index : t .Dict [T , int ] = {}
187200
188- sets : t .List [UpSetSet [T ]] = List (Instance (UpSetSet ), default_value = [],).tag (
189- sync = True , to_json = _to_set_list
190- )
201+ sets : t .List [UpSetSet [T ]] = List (
202+ Instance (UpSetSet ),
203+ default_value = [],
204+ ).tag (sync = True , to_json = _to_set_list )
191205
192206 combinations : t .List [UpSetSetCombination [T ]] = List (
193- Instance (UpSetSetCombination ), default_value = [],
207+ Instance (UpSetSetCombination ),
208+ default_value = [],
194209 ).tag (sync = True , to_json = _to_combination_list )
195210
196211 value : t .Union [None , t .Mapping , t .List [int ]] = Union (
@@ -424,7 +439,7 @@ def _from_dict(
424439 elems : t .Set [T ] = set ()
425440 for set_elems in sets .values ():
426441 elems .update (set_elems )
427- self .elems = sorted (elems )
442+ self .elems = sorted (elems ) # type: ignore
428443 self .elem_to_index = {e : i for i , e in enumerate (self .elems )}
429444 self ._expression_data = False
430445 color_lookup = colors or {}
@@ -539,8 +554,7 @@ def to_set(name: str, series):
539554
540555@register
541556class UpSetJSWidget (UpSetJSBaseWidget , t .Generic [T ]):
542- """UpSet.js Widget
543- """
557+ """UpSet.js Widget"""
544558
545559 _render_mode = Unicode ("upset" ).tag (sync = True )
546560
@@ -706,7 +720,12 @@ def generate_distinct_intersections(
706720 customize the generation of the sets
707721 """
708722 set_intersections = generate_distinct_intersections (
709- self .sets , min_degree , max_degree , empty , self .elems , colors = colors ,
723+ self .sets ,
724+ min_degree ,
725+ max_degree ,
726+ empty ,
727+ self .elems ,
728+ colors = colors ,
710729 )
711730
712731 self .combinations = _sort_combinations (
@@ -727,7 +746,12 @@ def generate_unions(
727746 customize the generation of the sets
728747 """
729748 set_unions = generate_unions (
730- self .sets , min_degree , max_degree , empty , self .elems , colors = colors ,
749+ self .sets ,
750+ min_degree ,
751+ max_degree ,
752+ empty ,
753+ self .elems ,
754+ colors = colors ,
731755 )
732756
733757 self .combinations = _sort_combinations (set_unions , self .sets , order_by , limit )
@@ -766,7 +790,7 @@ def append_categorical_attribute(
766790 """
767791 adds another categorical UpSetAttribute to be visualized
768792 """
769- cats = categories if categories is not None else sorted (set (values ))
793+ cats = categories if categories is not None else list ( sorted (set (values ) ))
770794 self .attrs = self .attrs + [
771795 UpSetAttribute [T ]("categorical" , name , values , categories = cats )
772796 ]
@@ -775,8 +799,7 @@ def append_categorical_attribute(
775799
776800@register
777801class UpSetJSVennDiagramWidget (UpSetJSBaseWidget , t .Generic [T ]):
778- """UpSet.js Venn Diagram Widget
779- """
802+ """UpSet.js Venn Diagram Widget"""
780803
781804 _render_mode = Unicode ("venn" ).tag (sync = True )
782805
@@ -825,7 +848,9 @@ def from_dataframe(
825848 return self ._generate_distinct_intersections (base_sets , colors = colors )
826849
827850 def _generate_distinct_intersections (
828- self , base_sets : t .List [UpSetSet [T ]], colors : t .Mapping [str , str ] = None ,
851+ self ,
852+ base_sets : t .List [UpSetSet [T ]],
853+ colors : t .Mapping [str , str ] = None ,
829854 ) -> "UpSetJSVennDiagramWidget" :
830855 set_intersections = generate_distinct_intersections (
831856 base_sets , 1 , None , True , self .elems , colors = colors
@@ -839,8 +864,7 @@ def _generate_distinct_intersections(
839864
840865@register
841866class UpSetJSEulerDiagramWidget (UpSetJSVennDiagramWidget , t .Generic [T ]):
842- """UpSet.js Euler Diagram Widget
843- """
867+ """UpSet.js Euler Diagram Widget"""
844868
845869 def __init__ (self , ** kwargs ):
846870 super ().__init__ (** kwargs )
@@ -860,8 +884,7 @@ def copy(self) -> "UpSetJSEulerDiagramWidget":
860884
861885@register
862886class UpSetJSKarnaughMapWidget (UpSetJSBaseWidget , t .Generic [T ]):
863- """UpSet.js Karnaugh Map Widget
864- """
887+ """UpSet.js Karnaugh Map Widget"""
865888
866889 _render_mode = Unicode ("kmap" ).tag (sync = True )
867890
@@ -915,7 +938,9 @@ def from_dataframe(
915938 return self ._generate_distinct_intersections (base_sets , colors = colors )
916939
917940 def _generate_distinct_intersections (
918- self , base_sets : t .List [UpSetSet [T ]], colors : t .Mapping [str , str ] = None ,
941+ self ,
942+ base_sets : t .List [UpSetSet [T ]],
943+ colors : t .Mapping [str , str ] = None ,
919944 ) -> "UpSetJSKarnaughMapWidget" :
920945 set_intersections = generate_distinct_intersections (
921946 base_sets , 1 , None , True , self .elems , colors = colors
0 commit comments