Skip to content

Commit

Permalink
fix: handle degenerate case (len = 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Mar 14, 2024
1 parent ad99942 commit 6d95c3e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/stepcount/stepcount.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import os
import pathlib
import urllib
Expand Down Expand Up @@ -282,13 +283,18 @@ def _QAt_to_str(tdelta):

def impute_missing(data: pd.DataFrame, extrapolate=True):

if extrapolate:
# padding at the boundaries to have full 24h
if extrapolate: # extrapolate beyond start/end times to have full 24h
freq = infer_freq(data.index)
if pd.isna(freq):
warnings.warn("Cannot infer frequency, using 1s")
freq = pd.Timedelta('1s')
freq = to_offset(freq)
data = data.reindex(
pd.date_range(
# TODO: This fails if data.index[0] happens to be midnight
data.index[0].floor('D'),
data.index[-1].ceil('D'),
freq=to_offset(infer_freq(data.index)),
freq=freq,
inclusive='left',
name='time',
),
Expand Down

0 comments on commit 6d95c3e

Please sign in to comment.