Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benhammondmusic committed May 25, 2024
1 parent 21ea658 commit 4e54bd7
Show file tree
Hide file tree
Showing 3 changed files with 475 additions and 475 deletions.
18 changes: 9 additions & 9 deletions python/datasources/chr.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def write_to_bq(self, dataset, gcs_bucket, **attrs):
timeview_float_cols_map = get_float_cols()
float_cols = timeview_float_cols_map[timeview]

df_for_bq, float_cols = convert_some_pct_rate_to_100k(df, float_cols)

df_for_bq, col_types = dataset_utils.generate_time_df_with_cols_and_types(
df, float_cols, timeview, demographic
df_for_bq, float_cols, timeview, demographic
)

df_for_bq, col_types = convert_some_pct_rate_to_100k(df_for_bq, col_types)

gcs_to_bq_util.add_df_to_bq(df_for_bq, dataset, table_name, column_types=col_types)


Expand Down Expand Up @@ -265,18 +265,18 @@ def convert_some_pct_rate_to_100k(df: pd.DataFrame, float_cols: List[str]) -> tu
'diabetes_pct_rate': 'diabetes_per_100k',
}

# swap col names in df and float cols
float_cols = [cols_conversion_map.get(col, col) for col in float_cols]
df = df.rename(columns=cols_conversion_map)

# convert per 100 to per 100,000
for col in cols_conversion_map.keys():
for col in cols_conversion_map.values():
df[col] = df[col] * 1000

# round 100k to whole numbers and pct_rate to one decimal
for col in df.columns:
if col in float_cols:
num_decimal_places = 0 if col.endswith(std_col.PER_100K_SUFFIX) else 1
num_decimal_places = 1 if "_pct" in col else 0
df[col] = df[col].round(num_decimal_places)

# swap col names in df and float cols
df = df.rename(columns=cols_conversion_map)
float_cols = [cols_conversion_map.get(col, col) for col in float_cols]

return (df, float_cols)
2 changes: 1 addition & 1 deletion python/ingestion/dataset_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def generate_time_df_with_cols_and_types(
numerical_cols_to_keep: List[str],
table_type: Literal['current', 'historical'],
dem_col: Literal['age', 'race', 'race_and_ethnicity', 'sex'],
):
) -> tuple[pd.DataFrame, Dict[str, str]]:
"""
Accepts a DataFrame along with list of column names for either current or
historical data and generates the appropiate BQ types for each column.
Expand Down
Loading

0 comments on commit 4e54bd7

Please sign in to comment.