Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .total_seconds() instead of .seconds; Fix .sum() of all-NaN to return NaN #87

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/stepcount/stepcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()

Expand Down Expand Up @@ -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

Expand Down
Loading