Skip to content

Commit 4cdb70d

Browse files
committed
fix: histogram for numpy 2.2x
1 parent 77d9479 commit 4cdb70d

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/ydata_profiling/model/summary_algorithms.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,29 @@ def histogram_compute(
4040
hist_config = config.plot.histogram
4141
bins_arg = "auto" if hist_config.bins == 0 else min(hist_config.bins, n_unique)
4242

43+
# --- FIX para NumPy 2.x: fallback seguro quando o range é demasiado pequeno ---
4344
try:
44-
# First try: whatever the config asked for
4545
bins = np.histogram_bin_edges(finite_values, bins=bins_arg)
4646
except ValueError as exc:
47-
# NumPy 2.x: "Too many bins for data range. Cannot create X finite-sized bins."
47+
# NumPy 2.x error: "Too many bins for data range. Cannot create X finite-sized bins."
4848
if "Too many bins for data range" in str(exc):
49-
# Fallback: let NumPy choose something reasonable
49+
# fallback robusto: deixar NumPy escolher automaticamente
5050
bins = np.histogram_bin_edges(finite_values, bins="auto")
5151
else:
52-
# Different error → still bubble up
52+
# manter comportamento anterior para erros diferentes
5353
raise
5454

55+
# manter a lógica original do max_bins
56+
if len(bins) > hist_config.max_bins:
57+
bins = np.histogram_bin_edges(finite_values, bins=hist_config.max_bins)
58+
weights = weights if weights is not None and len(weights) == hist_config.max_bins else None
59+
60+
stats[name] = np.histogram(
61+
finite_values,
62+
bins=bins,
63+
weights=weights,
64+
density=config.plot.histogram.density,
65+
)
5566
return stats
5667

5768

0 commit comments

Comments
 (0)