Skip to content

Commit 09e7c5b

Browse files
committed
fix: numpy because of python 3.13
1 parent 929b7e4 commit 09e7c5b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

deepnote_toolkit/ocelots/pandas/analyze.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

97103
def _calculate_min_max(column):

0 commit comments

Comments
 (0)