Skip to content

Commit

Permalink
fixes PerformanceWarning in detect_non_wear_time_syed2021
Browse files Browse the repository at this point in the history
  • Loading branch information
Trybnetic committed Nov 11, 2024
1 parent 79b8384 commit aaa97f4
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions paat/wear_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _group_episodes(episodes, distance_in_min=3, correction=3, hz=100, training=
return episodes.T

# create a new dataframe that will contain the grouped rows
grouped_episodes = pd.DataFrame()
grouped_episodes = []

Check warning on line 248 in paat/wear_time.py

View check run for this annotation

Codecov / codecov/patch

paat/wear_time.py#L248

Added line #L248 was not covered by tests

# get all current values from the first row
current_start = episodes.iloc[0]['start']
Expand Down Expand Up @@ -280,24 +280,28 @@ def _group_episodes(episodes, distance_in_min=3, correction=3, hz=100, training=
counter_label = f'{current_counter}-{next_counter}'

# save to new dataframe
grouped_episodes[counter_label] = pd.Series({'counter': counter_label,
'start_index': current_start_index,
'start': current_start,
'stop_index': current_stop_index,
'stop': current_stop,
'label': None if not training else current_label})
grouped_episodes += [pd.Series({

Check warning on line 283 in paat/wear_time.py

View check run for this annotation

Codecov / codecov/patch

paat/wear_time.py#L283

Added line #L283 was not covered by tests
'counter': counter_label,
'start_index': current_start_index,
'start': current_start,
'stop_index': current_stop_index,
'stop': current_stop,
'label': None if not training else current_label
})]
else:

# create the counter label
counter_label = current_counter if (next_counter - current_counter == 1) else f'{current_counter}-{next_counter - 1}'

# save to new dataframe
grouped_episodes[counter_label] = pd.Series({'counter': counter_label,
'start_index': current_start_index,
'start': current_start,
'stop_index': current_stop_index,
'stop': current_stop,
'label': None if not training else current_label})
grouped_episodes += [pd.Series({

Check warning on line 297 in paat/wear_time.py

View check run for this annotation

Codecov / codecov/patch

paat/wear_time.py#L297

Added line #L297 was not covered by tests
'counter': counter_label,
'start_index': current_start_index,
'start': current_start,
'stop_index': current_stop_index,
'stop': current_stop,
'label': None if not training else current_label
})]

# update tracker variables
current_start = next_start
Expand All @@ -311,14 +315,16 @@ def _group_episodes(episodes, distance_in_min=3, correction=3, hz=100, training=
if next_counter == episodes.iloc[-1]['counter']:

# save to new dataframe
grouped_episodes[next_counter] = pd.Series({'counter': next_counter,
'start_index': current_start_index,
'start': current_start,
'stop_index': current_stop_index,
'stop': current_stop,
'label': None if not training else current_label})

return grouped_episodes
grouped_episodes += [pd.Series({

Check warning on line 318 in paat/wear_time.py

View check run for this annotation

Codecov / codecov/patch

paat/wear_time.py#L318

Added line #L318 was not covered by tests
'counter': next_counter,
'start_index': current_start_index,
'start': current_start,
'stop_index': current_stop_index,
'stop': current_stop,
'label': None if not training else current_label
})]

return pd.concat(grouped_episodes, axis=1)

Check warning on line 327 in paat/wear_time.py

View check run for this annotation

Codecov / codecov/patch

paat/wear_time.py#L327

Added line #L327 was not covered by tests


def detect_non_wear_time_syed2021(data, sample_freq, cnn_model_file=None, std_threshold=0.004, distance_in_min=5, episode_window_sec=7, edge_true_or_false=True,
Expand Down

0 comments on commit aaa97f4

Please sign in to comment.