Fix bug when there are no event segments for participants

pull/103/head
JulioV 2020-10-22 16:41:26 -04:00
parent 47adb8bc4b
commit c41d24df45
2 changed files with 7 additions and 2 deletions

View File

@ -59,7 +59,7 @@ assign_rows_to_segments_frequency <- function(nested_data, nested_timezone, day_
assign_to_day_segment <- function(sensor_data, day_segments, day_segments_type, include_past_periodic_segments){ assign_to_day_segment <- function(sensor_data, day_segments, day_segments_type, include_past_periodic_segments){
if(nrow(sensor_data) == 0) if(nrow(sensor_data) == 0 || nrow(day_segments) == 0)
return(sensor_data %>% mutate(assigned_segments = NA)) return(sensor_data %>% mutate(assigned_segments = NA))
if(day_segments_type == "FREQUENCY"){ if(day_segments_type == "FREQUENCY"){

View File

@ -1,4 +1,5 @@
import pandas as pd import pandas as pd
import warnings
def is_valid_frequency_segments(day_segments, day_segments_file): def is_valid_frequency_segments(day_segments, day_segments_file):
""" """
@ -200,5 +201,9 @@ def parse_day_segments(day_segments_file, segments_type, pid):
return day_segments return day_segments
final_day_segments = parse_day_segments(snakemake.input[0], snakemake.params["day_segments_type"], snakemake.params["pid"]) final_day_segments = parse_day_segments(snakemake.input[0], snakemake.params["day_segments_type"], snakemake.params["pid"])
if snakemake.params["day_segments_type"] == "EVENT" and final_day_segments.shape[0] == 0:
warnings.warn("There are no event day segments for {}. Check your day segment file {}".format(snakemake.params["pid"], snakemake.input[0]))
final_day_segments.to_csv(snakemake.output["segments_file"], index=False) final_day_segments.to_csv(snakemake.output["segments_file"], index=False)
pd.DataFrame({"label" : final_day_segments["label"].unique()}).to_csv(snakemake.output["segments_labels_file"], index=False) pd.DataFrame({"label" : final_day_segments["label"].unique()}).to_csv(snakemake.output["segments_labels_file"], index=False)