@@ -28,28 +28,29 @@ def sig_digit_round(value, n_digits):
2828 sign_mask = value < 0
2929 value [sign_mask ] *= - 1
3030 exponent = np .ceil (np .log10 (value ))
31- result = 10 ** exponent * np .round (value * 10 ** (- exponent ), n_digits )
31+ result = 10 ** exponent * np .round (value * 10 ** (- exponent ), n_digits )
3232 result [sign_mask ] *= - 1
3333 result [zero_mask ] = in_value [zero_mask ]
3434 return result
3535
3636
37- def convert_df_type (df , logger ):
38- """convert types and warn if there are unexpected columns"""
37+ def convert_df_type (df , type_dict , logger ):
38+ """Convert types and warn if there are unexpected columns. """
3939 try :
40- df = df .astype (TYPE_DICT )
40+ df = df .astype (type_dict )
4141 except KeyError as exc :
42+ newline = "\n "
4243 raise KeyError (
4344 f"""
4445Expected column(s) missed, The dataset schema may
4546have changed. Please investigate and amend the code.
4647
47- expected={ NEWLINE .join (sorted (type_dict .keys ()))}
48+ expected={ newline .join (sorted (type_dict .keys ()))}
4849
49- received={ NEWLINE .join (sorted (df .columns ))}
50+ received={ newline .join (sorted (df .columns ))}
5051"""
5152 ) from exc
52- if new_columns := set (df .columns ) - set (TYPE_DICT .keys ()):
53+ if new_columns := set (df .columns ) - set (type_dict .keys ()):
5354 logger .info ("New columns found in NWSS dataset." , new_columns = new_columns )
5455 return df
5556
@@ -125,15 +126,15 @@ def pull_nwss_data(token: str, logger):
125126 """
126127 # Pull data from Socrata API
127128 client = Socrata ("data.cdc.gov" , token )
128- results_concentration = client .get ("g653-rqe2" , limit = 10 ** 10 )
129- results_metric = client .get ("2ew6-ywp6" , limit = 10 ** 10 )
129+ results_concentration = client .get ("g653-rqe2" , limit = 10 ** 10 )
130+ results_metric = client .get ("2ew6-ywp6" , limit = 10 ** 10 )
130131 df_metric = pd .DataFrame .from_records (results_metric )
131132 df_concentration = pd .DataFrame .from_records (results_concentration )
132133 df_concentration = df_concentration .rename (columns = {"date" : "timestamp" })
133134
134135 # Schema checks.
135- df_concentration = convert_df_type (df_concentration , logger )
136- df_metric = convert_df_type (df_metric , logger )
136+ df_concentration = convert_df_type (df_concentration , TYPE_DICT , logger )
137+ df_metric = convert_df_type (df_metric , TYPE_DICT_METRIC , logger )
137138
138139 # Drop sites without a normalization scheme.
139140 df = df_concentration [~ df_concentration ["normalization" ].isna ()]
0 commit comments