e-mission / op-admin-dashboard

An admin/deployer dashboard for the NREL OpenPATH platform
0 stars 8 forks source link

Date filter for trajectory table is giving an error. #80

Closed achasmita closed 9 months ago

achasmita commented 10 months ago

Traceback (most recent call last): File "/root/miniconda-23.5.2/envs/emission/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3802, in get_loc return self._engine.get_loc(casted_key) File "pandas/_libs/index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'data.mode'

The above exception was the direct cause of the following exception:

KeyError: 'data.mode'

achasmita commented 10 months ago
if not df.empty:
        for col in df.columns:
            if df[col].dtype == 'object':
                df[col] = df[col].apply(str)
columns_to_drop = [col for col in df.columns if col.startswith("metadata")]
df.drop(columns= columns_to_drop, inplace=True) 
modified_columns = perm_utils.get_trajectories_columns(df.columns)  
df.columns = modified_columns 
for col in constants.EXCLUDED_TRAJECTORIES_COLS:
      if col in df.columns:
          df.drop(columns= [col], inplace=True) 
df['data.mode_str'] = df['data.mode'].apply(lambda x: ecwm.MotionTypes(x).name if x in set(enum.value for enum in ecwm.MotionTypes) else 'UNKNOWN')
return df

We were getting the issues as it was trying to modify columns even when df is empty, keeping the code to modify column inside the if condition fixed the issue

achasmita commented 10 months ago
 if not df.empty:
        for col in df.columns:
            if df[col].dtype == 'object':
                df[col] = df[col].apply(str)
        columns_to_drop = [col for col in df.columns if col.startswith("metadata")]
        df.drop(columns= columns_to_drop, inplace=True) 
        modified_columns = perm_utils.get_trajectories_columns(df.columns)  
        df.columns = modified_columns 
        for col in constants.EXCLUDED_TRAJECTORIES_COLS:
            if col in df.columns:
                df.drop(columns= [col], inplace=True) 
        df['data.mode_str'] = df['data.mode'].apply(lambda x: ecwm.MotionTypes(x).name if x in set(enum.value for enum in ecwm.MotionTypes) else 'UNKNOWN')
    return df