From d7f778d5311cf196b989903f0667abe23f1171e0 Mon Sep 17 00:00:00 2001 From: Barbara Bertozzi Date: Thu, 21 Aug 2025 11:37:23 +0200 Subject: [PATCH] Fix: the hisotgrams were adding lines with NaNs when the corresponding partition was completely empty. Now it is back to old behavior and no index is added for partitions completely empty. --- src/sp2xr/distribution.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sp2xr/distribution.py b/src/sp2xr/distribution.py index f1ef593..fc0f956 100644 --- a/src/sp2xr/distribution.py +++ b/src/sp2xr/distribution.py @@ -259,10 +259,15 @@ def process_hist_and_dist_partition( # expand list-of-counts -> wide matrix (one col per bin) max_list_length = len(bin_ctrs) if df_resampled.empty: - # IMPORTANT: use the resampled time index so schema matches later joins + """# IMPORTANT: use the resampled time index so schema matches later joins idx = flow_dt.index columns = [f"result_{i}" for i in range(max_list_length)] - ddf_hist = pd.DataFrame(np.nan, columns=columns, index=idx) + ddf_hist = pd.DataFrame(np.nan, columns=columns, index=idx)""" + + ddf_hist = pd.DataFrame( + columns=[f"result_{i}" for i in range(max_list_length)], + index=pd.DatetimeIndex([], name=df.index.name), + ) else: ddf_hist = df_resampled["result"].apply(pd.Series) ddf_hist.index = df_resampled.index