Add necessary checks for empty data frames.

labels
junos 2022-04-05 18:58:09 +02:00
parent f50a13167e
commit cbc8ae4e03
3 changed files with 11 additions and 5 deletions

View File

@ -240,6 +240,7 @@ PHONE_ESM:
STRAW:
COMPUTE: True
SCALES: ["PANAS_positive_affect", "PANAS_negative_affect", "JCQ_job_demand", "JCQ_job_control", "JCQ_supervisor_support", "JCQ_coworker_support"]
FEATURES: [mean]
SRC_SCRIPT: src/features/phone_esm/straw/main.py
# See https://www.rapids.science/latest/features/phone-keyboard/

View File

@ -343,7 +343,7 @@ rule esm_features:
scales=lambda wildcards: config["PHONE_ESM"]["PROVIDERS"][wildcards.provider_key.upper()]["SCALES"]
output: "data/interim/{pid}/phone_esm_features/phone_esm_clean_{provider_key}.csv"
script:
"../src/features/entry.R"
"../src/features/entry.py"
rule phone_keyboard_python_features:
input:

View File

@ -9,9 +9,14 @@ def straw_features(sensor_data_files, time_segment, provider, filter_data_by_seg
# the subset of requested features this function can compute
features_to_compute = list(set(requested_features) & set(base_features_names))
esm_features = pd.DataFrame(columns=["local_segment"] + features_to_compute)
if not esm_data.empty:
esm_data = filter_data_by_segment(esm_data, time_segment)
if not esm_data.empty:
esm_features = pd.DataFrame()
esm_features["mean"] = esm_data.groupby(["local_segment"])["esm_user_score"].mean()
#TODO Create the column esm_user_score in esm_clean. Currently, this is only done when reversing.
esm_features = esm_features.reset_index()
return esm_features