Skip to content

Commit

Permalink
Merge pull request #3025 from catalyst-cooperative/fix_mystery_fuel_c…
Browse files Browse the repository at this point in the history
…at_nan

Fix validation `test_fbp_ferc1_mismatched_fuels` error
  • Loading branch information
cmgosnell authored Nov 8, 2023
2 parents fcf4ccc + b7533cf commit a2bdffa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/pudl/analysis/classify_plants_ferc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,11 @@ def fuel_by_plant_ferc1(
]

# Ensure that the dataframe we've gotten has all the information we need:
for col in keep_cols:
if col not in fuel_df.columns:
raise AssertionError(f"Required column {col} not found in input fuel_df.")
missing_cols = [col for col in keep_cols if col not in fuel_df.columns]
if missing_cols:
raise AssertionError(
f"Required columns not found in input fuel_df: {missing_cols}"
)

# Calculate per-fuel derived values and add them to the DataFrame
df = (
Expand All @@ -679,7 +681,8 @@ def fuel_by_plant_ferc1(
"plant_name_ferc1",
"report_year",
"fuel_type_code_pudl",
]
],
observed=True,
)
.sum()
.reset_index()
Expand Down Expand Up @@ -732,6 +735,13 @@ def fuel_by_plant_ferc1(
).reset_index()

# Label each plant-year record by primary fuel:
df.loc[:, ["primary_fuel_by_cost", "primary_fuel_by_mmbtu"]] = pd.NA
df = df.astype(
{
"primary_fuel_by_cost": pd.StringDtype(),
"primary_fuel_by_mmbtu": pd.StringDtype(),
}
)
for fuel_str in fuel_categories:
try:
mmbtu_mask = df[f"{fuel_str}_fraction_mmbtu"] > thresh
Expand Down
4 changes: 0 additions & 4 deletions src/pudl/output/ferc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,6 @@ def drop_other_fuel_types(df):
return df[df.fuel_type_code_pudl != "other"].copy()

thresh = context.op_config["thresh"]
# The existing function expects `fuel_type_code_pudl` to be an object, rather than
# a category. This is a legacy of pre-dagster code, and we convert here to prevent
# further retooling in the code-base.
fuel_ferc1["fuel_type_code_pudl"] = fuel_ferc1["fuel_type_code_pudl"].astype(str)

fuel_categories = list(
pudl.transform.ferc1.FuelFerc1TableTransformer()
Expand Down

0 comments on commit a2bdffa

Please sign in to comment.