@@ -118,6 +118,26 @@ def get_kde_numeric_attribute(values, parameters=None):
118118 Parameters .GRAPH_POINTS , parameters , 200
119119 )
120120 values = np .sort (values )
121+
122+ # Check if we have enough unique values for KDE
123+ unique_values = np .unique (values )
124+ if len (unique_values ) < 2 :
125+ # Handle edge case: not enough unique values for KDE
126+ if len (unique_values ) == 0 :
127+ # No values at all
128+ return [], []
129+ else :
130+ # Single unique value - create a simple representation
131+ single_val = float (unique_values [0 ])
132+ # Create a small range around the single value for visualization
133+ eps = max (abs (single_val ) * 0.01 , 1e-6 ) if single_val != 0 else 1.0
134+ xs = np .linspace (single_val - eps , single_val + eps , graph_points )
135+ # Create a spike at the single value
136+ ys = np .zeros (graph_points )
137+ mid_idx = graph_points // 2
138+ ys [mid_idx ] = 1.0
139+ return xs .tolist (), ys .tolist ()
140+
121141 density = gaussian_kde (values )
122142
123143 # ensure we have at least two points for each spacing
@@ -209,6 +229,27 @@ def get_kde_date_attribute(values, parameters=None):
209229 int_values = sorted (
210230 [x .replace (tzinfo = None ).timestamp () for x in red_values ]
211231 )
232+
233+ # Check if we have enough unique values for KDE
234+ unique_int_values = np .unique (int_values )
235+ if len (unique_int_values ) < 2 :
236+ # Handle edge case: not enough unique values for KDE
237+ if len (unique_int_values ) == 0 :
238+ # No values at all
239+ return [[], []]
240+ else :
241+ # Single unique value - create a simple representation
242+ single_val = float (unique_int_values [0 ])
243+ # Create a small time range around the single value (1 hour range)
244+ time_eps = 3600 # 1 hour in seconds
245+ xs = np .linspace (single_val - time_eps , single_val + time_eps , graph_points )
246+ xs_transf = pd .to_datetime (xs * 10 ** 9 , unit = "ns" )
247+ # Create a spike at the single value
248+ ys = np .zeros (graph_points )
249+ mid_idx = graph_points // 2
250+ ys [mid_idx ] = 1.0
251+ return [xs_transf , ys .tolist ()]
252+
212253 density = gaussian_kde (int_values )
213254 xs = np .linspace (min (int_values ), max (int_values ), graph_points )
214255 xs_transf = pd .to_datetime (xs * 10 ** 9 , unit = "ns" )
0 commit comments