@@ -78,20 +78,26 @@ def _get_histogram(pd_series):
7878 # let's drop infinite values because they break histograms
7979 np_array = np .array (pd_series .replace ([np .inf , - np .inf ], np .nan ).dropna ())
8080
81+ # Check if array is empty after dropping NaN/NaT values
82+ if len (np_array ) == 0 :
83+ return None
84+
8185 y , bins = np .histogram (np_array , bins = 10 )
8286 return [
8387 {"bin_start" : bins [i ], "bin_end" : bins [i + 1 ], "count" : count .item ()}
8488 for i , count in enumerate (y )
8589 ]
86- except ValueError as e :
90+ except ( ValueError , IndexError ) as e :
8791 # NumPy 2.2+ raises "Too many bins for data range" when:
8892 # - Data range is zero (all values identical), or
8993 # - For integer data, bin width would be < 1.0, or
9094 # - Floating point precision prevents creating finite-sized bins at large scales
9195 # Numpy implementation: https://github.com/numpy/numpy/blob/e7a123b2d3eca9897843791dd698c1803d9a39c2/numpy/lib/_histograms_impl.py#L454
92- if "Too many bins for data range" in str (e ):
96+ # IndexError can occur in NumPy 2.x with edge cases involving large integers or datetime conversions
97+ if isinstance (e , ValueError ) and "Too many bins for data range" in str (e ):
9398 return None
94- raise
99+ # For IndexError or other ValueError cases, return None to gracefully handle edge cases
100+ return None
95101
96102
97103def _calculate_min_max (column ):
0 commit comments