diff --git a/src/stepcount/stepcount.py b/src/stepcount/stepcount.py index 5bfd208..1ab6542 100644 --- a/src/stepcount/stepcount.py +++ b/src/stepcount/stepcount.py @@ -212,7 +212,7 @@ def _mean(x): def summarize_steps(Y, steptol=3, adjust_estimates=False): """ Summarize step count data """ - dt = pd.Timedelta(infer_freq(Y.index)).seconds + dt = infer_freq(Y.index).total_seconds() W = Y.mask(~Y.isna(), Y >= steptol).astype('float') if adjust_estimates: @@ -224,7 +224,10 @@ def summarize_steps(Y, steptol=3, adjust_estimates=False): skipna = True def _sum(x): - if not skipna and x.isna().any(): + na = x.isna() + if not skipna and na.any(): + return np.nan + if na.all(): # have to do this explicitly because pandas' .sum() returns 0 if all-NaN return np.nan return x.sum() @@ -392,7 +395,7 @@ def na_to_median(x): .transform(na_to_median) ) - dt = pd.Timedelta(infer_freq(Y.index)).seconds + dt = infer_freq(Y.index).total_seconds() steptol_in_minutes = steptol * 60 / dt # rescale steptol to steps/min minutely = Y.resample('T').sum().rename('Steps') # steps/min