Clean up SQL statements changed for sqlite
Had to remove some things like "IN" statements when moving from
postgres to sqlite due to limit of 999 parameters and inability to pass
tuple as a single parameter.
@@ -481,7 +481,6 @@ def load_generator_860_data(pudl_engine, data_years=[2017]):
gens_860 = pd.read_sql_query(
sql=sql,
con=pudl_engine,
- # params={"data_years": tuple(data_years)},
parse_dates=["planned_retirement_date", "report_date"],
)
gens_860 = gens_860.loc[gens_860["report_date"].dt.year.isin(data_years), :]
@@ -716,16 +715,10 @@ def load_923_gen_fuel_data(pudl_engine, pudl_out, model_region_map, data_years=[
# Only load plants in the model regions.
sql = """
SELECT * FROM generation_fuel_eia923
-
"""
- # WHERE plant_id_eia IN ?
gen_fuel_923 = pd.read_sql_query(
sql,
pudl_engine,
- # params=(
- # # "data_years": tuple(data_years),
- # tuple(model_region_map.plant_id_eia.tolist()),
- # ),
parse_dates=["report_date"],
)
gen_fuel_923 = gen_fuel_923.loc[
@@ -1357,7 +1350,6 @@ def gentype_region_capacity_factor(
sql,
pudl_engine,
parse_dates=["report_date"],
- # params={"plant_ids": tuple(plant_region_map["plant_id_eia"].tolist())},
)
plant_gen_tech_cap = plant_gen_tech_cap.loc[
plant_gen_tech_cap["plant_id_eia"].isin(plant_region_map["plant_id_eia"]), :
@@ -1376,25 +1368,6 @@ def gentype_region_capacity_factor(
label_small_hydro(plant_tech_cap, settings, by=["plant_id_eia", "report_date"])
- # if type(pudl_engine) == sa.engine.base.Engine:
- # sql = """
- # SELECT
- # DATE_PART('year', GF.report_date) AS report_date,
- # GF.plant_id_eia,
- # SUM(GF.net_generation_mwh) AS net_generation_mwh,
- # GF.fuel_type_code_pudl
- # FROM
- # generation_fuel_eia923 GF
- # GROUP BY
- # DATE_PART('year', GF.report_date),
- # GF.plant_id_eia,
- # GF.fuel_type_code_pudl
- # ORDER by GF.plant_id_eia, DATE_PART('year', GF.report_date)
- # """
- # generation = pd.read_sql_query(
- # sql, pudl_engine, parse_dates={"report_date": "%Y"}
- # )
- # elif type(pudl_engine) == sqlite3.Connection:
sql = """
SELECT
strftime('%Y', GF.report_date) AS report_date,
@@ -1412,11 +1385,6 @@ def gentype_region_capacity_factor(
generation = pd.read_sql_query(
sql, pudl_engine, parse_dates={"report_date": "%Y"}
)
- # else:
- # raise TypeError(
- # f"pudl_engine should be a sqlalchemy Engine or sqlite3 Connection./n"
- # f"It is actually a {type(pudl_engine)}"
- # )
capacity_factor = pudl.helpers.merge_on_date_year(
plant_tech_cap, generation, on=["plant_id_eia"], how="left"
