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

fix: dtype conversion issue in detect_nonwear #26

Merged
merged 1 commit into from
Nov 29, 2023
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
6 changes: 5 additions & 1 deletion src/actipy/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def detect_nonwear(data, patience='90m', window='10s', stdtol=15 / 1000):

info = {}

stationary_indicator = ( # this is more memory friendly than of data[['x', 'y', 'z']].std()
stationary_indicator = ( # this is more memory friendly than data[['x', 'y', 'z']].std()
data['x'].resample(window, origin='start').std().lt(stdtol)
& data['y'].resample(window, origin='start').std().lt(stdtol)
& data['z'].resample(window, origin='start').std().lt(stdtol)
Expand All @@ -206,6 +206,10 @@ def detect_nonwear(data, patience='90m', window='10s', stdtol=15 / 1000):
)
.set_index('start_time')
.squeeze()
# dtype defaults to int64 when series is empty, so
# astype('timedelta64[ns]') makes sure it's always a timedelta,
# otherwise comparison with Timedelta(patience) below will fail
.astype('timedelta64[ns]')
)
nonwear_segment_lengths = stationary_segment_lengths[stationary_segment_lengths > pd.Timedelta(patience)]

Expand Down