From c0f1065b7063a0378b66e78712a91eb9ef45f0d8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 11 May 2026 12:33:01 +0000 Subject: [PATCH] Fix ZeroDivisionError in Time-based sampler for sub-millisecond sample times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sample times smaller than 0.5ms (e.g. 0.0001s) rounded to 0ms, causing pandas to raise ZeroDivisionError. Switch to microsecond resolution to handle values down to 1µs correctly. https://claude.ai/code/session_01RBBu4ZEdhRGFLWE7b6WCQP --- pydatview/tools/signal_analysis.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pydatview/tools/signal_analysis.py b/pydatview/tools/signal_analysis.py index d86179d..4f1e9b3 100644 --- a/pydatview/tools/signal_analysis.py +++ b/pydatview/tools/signal_analysis.py @@ -259,8 +259,10 @@ def applySampler(x_old, y_old, sampDict, df_old=None): sample_time = float(param[0]) if sample_time <= 0: raise Exception('Error: sample time must be positive') - sample_time_ms = int(round(sample_time * 1000)) - sSample = "{}ms".format(sample_time_ms) + sample_time_us = int(round(sample_time * 1_000_000)) + if sample_time_us == 0: + raise Exception('Error: sample time is too small (rounds to 0 microseconds)') + sSample = "{}us".format(sample_time_us) time_index = pd.to_timedelta(np.asarray(x_old, dtype=float) * 1000, unit="ms") x_new = pd.Series(x_old, index=time_index).resample(sSample).mean().interpolate().values