Skip to content

Commit

Permalink
Merge pull request #763 from akrherz/summary_cols
Browse files Browse the repository at this point in the history
fix: ensure summary cols in null_ are valid
  • Loading branch information
akrherz committed Sep 14, 2023
2 parents 7630529 + 7ea243e commit 5031db6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/pyiem/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
import pandas as pd
from metpy.units import units as munits

# Track which columns are in the summary table for the null_ check below
SUMMARY_COLS = (
"max_tmpf min_tmpf max_sknt max_gust max_sknt_ts max_gust_ts max_dwpf "
"min_dwpf pday pmonth snow snowd max_tmpf_qc min_tmpf_qc pday_qc snow_qc "
"snoww max_drct max_srad coop_tmpf coop_valid et_inch srad_mj avg_sknt "
"vector_avg_drct avg_rh min_rh max_rh max_water_tmpf min_water_tmpf "
"max_feel avg_feel min_feel min_rstage max_rstage report"
).split()


def get_summary_table(valid):
"""Optimize the summary table we potentially use.
Expand Down Expand Up @@ -107,7 +116,7 @@ def summary_update(txn, data):
# Check to see if we have any hard coded nulls
updates = []
for col in data:
if col.startswith("null_"):
if col.startswith("null_") and col[5:] in SUMMARY_COLS:
updates.append(f"{col[5:]} = null")
if updates:
txn.execute(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_hardcoded_maxtmpf(iemob):
assert iemob.cursor.fetchone()["max_tmpf"] == 54


def test_settting_null(iemob):
def test_setting_null(iemob):
"""Test setting a null value into the database after a real value."""
iemob.ob.data["max_tmpf"] = 55
iemob.ob.save(iemob.cursor)
Expand All @@ -186,6 +186,8 @@ def test_settting_null(iemob):
)
assert iemob.cursor.fetchone()["max_tmpf"] == 55
iemob.ob.data["null_max_tmpf"] = None
# bogus value that should not trip up the summary table update
iemob.ob.data["null_drct"] = None
iemob.ob.save(iemob.cursor)
iemob.cursor.execute(
"""SELECT max_tmpf from summary_2015
Expand Down

0 comments on commit 5031db6

Please sign in to comment.