@@ -193,6 +193,15 @@ def _get_range(values, frac=0.2, factor=3.0):
193193 return low , high
194194
195195
196+ def _get_safe_hist_range (values ):
197+ # make sure numpy can find bin edges between the range low and high bounds
198+ vmin , vmax = values .min (), values .max ()
199+ delta = max (np .spacing (vmin ), np .spacing (vmax ))
200+ if vmax - vmin > 12 * delta :
201+ return None
202+ return vmin - 6 * delta , vmax + 6 * delta
203+
204+
196205def _robust_hist (col , ax = None , color = None ):
197206 col = sbd .drop_nulls (col )
198207 if sbd .is_float (col ):
@@ -218,12 +227,16 @@ def _robust_hist(col, ax=None, color=None):
218227 n_low_outliers = (values < low ).sum ()
219228 n_high_outliers = (high < values ).sum ()
220229 result = {"n_low_outliers" : n_low_outliers , "n_high_outliers" : n_high_outliers }
230+ np_histogram_inliers = np_histogram_values [inlier_mask ]
221231 result ["bin_counts" ], result ["bin_edges" ] = np .histogram (
222- np_histogram_values [ inlier_mask ]
232+ np_histogram_inliers , range = _get_safe_hist_range ( np_histogram_inliers )
223233 )
224234 if ax is None :
225235 return result
226- n , bins , patches = ax .hist (values [inlier_mask ])
236+ histogram_inliers = values [inlier_mask ]
237+ n , bins , patches = ax .hist (
238+ histogram_inliers , range = _get_safe_hist_range (histogram_inliers )
239+ )
227240 n_out = n_low_outliers + n_high_outliers
228241 if not n_out :
229242 return result
0 commit comments