Skip to content

Commit 3ed73b4

Browse files
committed
fix: histograms support Numpy 2.x
1 parent aa9c00b commit 3ed73b4

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/ydata_profiling/model/summary_algorithms.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,22 @@ def histogram_compute(
3636
stats = {}
3737
if len(finite_values) == 0:
3838
return {name: []}
39+
3940
hist_config = config.plot.histogram
4041
bins_arg = "auto" if hist_config.bins == 0 else min(hist_config.bins, n_unique)
41-
bins = np.histogram_bin_edges(finite_values, bins=bins_arg)
42-
if len(bins) > hist_config.max_bins:
43-
bins = np.histogram_bin_edges(finite_values, bins=hist_config.max_bins)
44-
weights = weights if weights and len(weights) == hist_config.max_bins else None
45-
46-
stats[name] = np.histogram(
47-
finite_values, bins=bins, weights=weights, density=config.plot.histogram.density
48-
)
42+
43+
try:
44+
# First try: whatever the config asked for
45+
bins = np.histogram_bin_edges(finite_values, bins=bins_arg)
46+
except ValueError as exc:
47+
# NumPy 2.x: "Too many bins for data range. Cannot create X finite-sized bins."
48+
if "Too many bins for data range" in str(exc):
49+
# Fallback: let NumPy choose something reasonable
50+
bins = np.histogram_bin_edges(finite_values, bins="auto")
51+
else:
52+
# Different error → still bubble up
53+
raise
54+
4955
return stats
5056

5157

0 commit comments

Comments
 (0)