@@ -137,42 +137,45 @@ def format_basic(df: dd.DataFrame) -> Dict[str, Any]:
137137 "col_type" : itmdt .visual_type .replace ("_column" , "" ),
138138 }
139139
140- # interactions
141- res ["has_interaction" ] = True
142- itmdt = Intermediate (data = data ["scat" ], visual_type = "correlation_crossfilter" )
143- rndrd = render_correlation (itmdt )
144- rndrd .sizing_mode = "stretch_width"
145- res ["interactions" ] = components (rndrd )
146-
147- # correlations
148- res ["has_correlation" ] = True
149- dfs : Dict [str , pd .DataFrame ] = {}
150- for method , corr in data ["corrs" ].items ():
151- ndf = pd .DataFrame (
152- {
153- "x" : data ["num_cols" ][data ["cordx" ]],
154- "y" : data ["num_cols" ][data ["cordy" ]],
155- "correlation" : corr .ravel (),
156- }
140+ if len (data ["num_cols" ]) > 0 :
141+ # interactions
142+ res ["has_interaction" ] = True
143+ itmdt = Intermediate (data = data ["scat" ], visual_type = "correlation_crossfilter" )
144+ rndrd = render_correlation (itmdt )
145+ rndrd .sizing_mode = "stretch_width"
146+ res ["interactions" ] = components (rndrd )
147+
148+ # correlations
149+ res ["has_correlation" ] = True
150+ dfs : Dict [str , pd .DataFrame ] = {}
151+ for method , corr in data ["corrs" ].items ():
152+ ndf = pd .DataFrame (
153+ {
154+ "x" : data ["num_cols" ][data ["cordx" ]],
155+ "y" : data ["num_cols" ][data ["cordy" ]],
156+ "correlation" : corr .ravel (),
157+ }
158+ )
159+ dfs [method .name ] = ndf [data ["cordy" ] > data ["cordx" ]]
160+ itmdt = Intermediate (
161+ data = dfs ,
162+ axis_range = list (data ["num_cols" ]),
163+ visual_type = "correlation_heatmaps" ,
157164 )
158- dfs [method .name ] = ndf [data ["cordy" ] > data ["cordx" ]]
159- itmdt = Intermediate (
160- data = dfs , axis_range = list (data ["num_cols" ]), visual_type = "correlation_heatmaps" ,
161- )
162- rndrd = render_correlation (itmdt )
163- figs .clear ()
164- for tab in rndrd .tabs :
165- fig = tab .child
166- fig .sizing_mode = "stretch_width"
167- fig .title = Title (text = tab .title , align = "center" , text_font_size = "20px" )
168- figs .append (fig )
169- res ["correlations" ] = components (figs )
165+ rndrd = render_correlation (itmdt )
166+ figs .clear ()
167+ for tab in rndrd .tabs :
168+ fig = tab .child
169+ fig .sizing_mode = "stretch_width"
170+ fig .title = Title (text = tab .title , align = "center" , text_font_size = "20px" )
171+ figs .append (fig )
172+ res ["correlations" ] = components (figs )
173+ else :
174+ res ["has_interaction" ], res ["has_correlation" ] = False , False
170175
171176 # missing
172177 res ["has_missing" ] = True
173-
174178 itmdt = completions ["miss" ](data ["miss" ])
175-
176179 rndrd = render_missing (itmdt )
177180 figs .clear ()
178181 for tab in rndrd .tabs :
@@ -200,16 +203,21 @@ def basic_computations(df: dd.DataFrame) -> Tuple[Dict[str, Any], Dict[str, Any]
200203 data ["num_cols" ] = df_num .columns
201204 first_rows = df .select_dtypes (CATEGORICAL_DTYPES ).head
202205
203- # overview
204- data ["ov" ] = calc_stats (df .frame , None )
205- # # variables
206+ # variables
206207 for col in df .columns :
207208 if is_dtype (detect_dtype (df .frame [col ]), Continuous ()):
208209 data [col ] = cont_comps (df .frame [col ], 20 )
209210 elif is_dtype (detect_dtype (df .frame [col ]), Nominal ()):
211+ # cast the column as string type if it contains a mutable type
212+ try :
213+ first_rows [col ].apply (hash )
214+ except TypeError :
215+ df .frame [col ] = df .frame [col ].astype (str )
210216 data [col ] = nom_comps (
211217 df .frame [col ], first_rows [col ], 10 , True , 10 , 20 , True , False , False
212218 )
219+ # overview
220+ data ["ov" ] = calc_stats (df .frame , None )
213221 # interactions
214222 data ["scat" ] = df_num .frame .map_partitions (
215223 lambda x : x .sample (min (1000 , x .shape [0 ])), meta = df_num .frame
0 commit comments