KeyError and TypeError in def write_to_sql (run_sql.py) when loading PCT line type data to METviewer database #2175
Replies: 4 comments
-
Hi @heu3becteh. My apologies for a delayed response. I'm going to tag a couple of colleagues here with hope that one of them can help answer your questions soon. @venitahagerty @TatianaBurek @bikegeek |
Beta Was this translation helpful? Give feedback.
-
Hi @heu3becteh |
Beta Was this translation helpful? Give feedback.
-
Thank you for the reply! I attach the log from METdbload Version: version = "2.0.2". We had 2.0.1 version, installation of METviewer and all related packages from 22.02.2023 when we got this problem first, but updating METdataio to v2.0.2 did not help. I also attach our python environment packages. We have Python 3.8.16 according to https://metviewer.readthedocs.io/en/latest/Users_Guide/installation.html (Python 3.8.6 or higher), pandas 1.5.1. Example data stat-file is produced from pct-file to avoid filtering of other line types, I believe that is not a problem. Best regards, |
Beta Was this translation helpful? Give feedback.
-
Alexander |
Beta Was this translation helpful? Give feedback.
-
Hello!
I have encountered problem with database loading of PCT line type data:
The problem with KeyError: it tries to access date/lead time columns on lines 148-157 of run_sql.py, but there is no such data for line_data_pct_thresh table.
raw_data
for line_data_pct_thresh looks like that:There are no fcst_valid_beg, fcst_valid_end, fcst_init_beg, obs_valid_beg, obs_valid_end, fcst_valid, fcst_init, obs_valid.
To load this data I have added a check:
at the beginning of def
write_to_sql
, and then have added conditionif raw_data_has_dates
for lines 148-157.I guess the condition on line 148 (
if 'line_data' in sql_table
) should be changed, as line_data_pct_thresh has no timestamps.The problem with TypeError is related to
sql_query
being not adequate for line_data_pct.sql_query
isbut the data in
dfile
has other format, which leads to an error on line 160 of run_sql.py.Data in
dfile
looks like that:It is 14 values with the first being line_data_id. But the default
sql_query
has 13 values without line_data_id, so I have changed it to:sql_query="INSERT INTO line_data_pct (line_data_id, stat_header_id,data_file_id,line_num,fcst_lead,fcst_valid_beg,fcst_valid_end,fcst_init_beg,obs_lead,obs_valid_beg,obs_valid_end,cov_thresh,total,n_thresh) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
which allowed to load the data.
There were similar issues with other lines too, but did not look into it much for now.
The fixes I have made are quick and dirty, but I assume that issue exists not only for myself and should be addressed?
Best regards,
Alexander
Beta Was this translation helpful? Give feedback.
All reactions