Skip to content

Commit

Permalink
fix: QAt IndexError
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Sep 26, 2023
1 parent 816516b commit 302a1f9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/stepcount/stepcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,20 @@ def _max(x, n=1):

# distributional features - quantiles
def _QAt(x):
na_return = {'StepsQ1At': np.nan, 'StepsQ2At': np.nan, 'StepsQ3At': np.nan}
if adjust_estimates and x.isna().any():
return {'StepsQ1At': np.nan, 'StepsQ2At': np.nan, 'StepsQ3At': np.nan}
return na_return
z = x.cumsum() / x.sum()
q1_at = z[z >= 0.25].index[0]
q1_at = q1_at - q1_at.floor('D')
q2_at = z[z >= 0.5].index[0]
q2_at = q2_at - q2_at.floor('D')
q3_at = z[z >= 0.75].index[0]
q3_at = q3_at - q3_at.floor('D')
return {'StepsQ1At': q1_at, 'StepsQ2At': q2_at, 'StepsQ3At': q3_at}
try:
q1_at = z[z >= 0.25].index[0]
q1_at = q1_at - q1_at.floor('D')
q2_at = z[z >= 0.5].index[0]
q2_at = q2_at - q2_at.floor('D')
q3_at = z[z >= 0.75].index[0]
q3_at = q3_at - q3_at.floor('D')
return {'StepsQ1At': q1_at, 'StepsQ2At': q2_at, 'StepsQ3At': q3_at}
except IndexError:
return na_return

def _QAt_to_str(tdelta):
if pd.isna(tdelta):
Expand Down

0 comments on commit 302a1f9

Please sign in to comment.