From d254ab135b72797c14d9d8ba9483508faa9ea370 Mon Sep 17 00:00:00 2001 From: Bainan Xia Date: Fri, 13 Nov 2020 17:24:26 -0800 Subject: [PATCH] style: run black --- prereise/gather/demanddata/eia/map_ba.py | 12 ++++-------- prereise/gather/demanddata/eia/tests/test_map_ba.py | 2 +- prereise/gather/helpers.py | 3 +-- prereise/gather/hydrodata/eia/decompose_profile.py | 11 +++++------ prereise/gather/hydrodata/eia/net_demand.py | 5 +++-- .../hydrodata/eia/tests/test_decompose_profile.py | 5 +++-- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/prereise/gather/demanddata/eia/map_ba.py b/prereise/gather/demanddata/eia/map_ba.py index d0622a31f..12b81884c 100644 --- a/prereise/gather/demanddata/eia/map_ba.py +++ b/prereise/gather/demanddata/eia/map_ba.py @@ -40,8 +40,7 @@ def get_demand_in_loadzone(agg_demand, bus_map): :return: (*pandas.DataFrame*) -- data frame with demand columns according to load zone. """ - ba_agg = bus_map[["BA", "Pd"]].groupby("BA")\ - .sum().rename(columns={"Pd": "PdTotal"}) + ba_agg = bus_map[["BA", "Pd"]].groupby("BA").sum().rename(columns={"Pd": "PdTotal"}) ba_scaling_factor = bus_map.merge(ba_agg, left_on="BA", right_on="BA") ba_scaling_factor = ba_scaling_factor.assign( @@ -55,13 +54,11 @@ def get_demand_in_loadzone(agg_demand, bus_map): for zone_name in zone_scaling_df.index.get_level_values(0).to_list(): if zone_name in zone_demand.columns.to_list(): zone_demand[zone_name] += ( - zone_scaling_df.loc[zone_name, "zone_scaling"] - * agg_demand[ba_name] + zone_scaling_df.loc[zone_name, "zone_scaling"] * agg_demand[ba_name] ) else: zone_demand[zone_name] = ( - zone_scaling_df.loc[zone_name, "zone_scaling"] - * agg_demand[ba_name] + zone_scaling_df.loc[zone_name, "zone_scaling"] * agg_demand[ba_name] ) return zone_demand @@ -83,8 +80,7 @@ def map_buses_to_county(bus_county_map): bus_county_map.loc[:, "County"] = None bus_county_map.loc[:, "BA"] = None bus_no_county_match = [] - for index, row in tqdm(bus_county_map.iterrows(), - total=len(bus_county_map)): + for index, row in tqdm(bus_county_map.iterrows(), total=len(bus_county_map)): params = { "latitude": row["lat"], "longitude": row["lon"], diff --git a/prereise/gather/demanddata/eia/tests/test_map_ba.py b/prereise/gather/demanddata/eia/tests/test_map_ba.py index 36d61f366..3999c9b9c 100644 --- a/prereise/gather/demanddata/eia/tests/test_map_ba.py +++ b/prereise/gather/demanddata/eia/tests/test_map_ba.py @@ -2,8 +2,8 @@ from pandas.testing import assert_series_equal from prereise.gather.demanddata.eia.map_ba import ( - get_demand_in_loadzone, aggregate_ba_demand, + get_demand_in_loadzone, ) diff --git a/prereise/gather/helpers.py b/prereise/gather/helpers.py index 43bbe14ef..340cae46c 100644 --- a/prereise/gather/helpers.py +++ b/prereise/gather/helpers.py @@ -90,8 +90,7 @@ def get_monthly_net_generation(state, eia_form_923, resource, hps=True): # Get monthly total net generation by summing up across plants # with all positive values. Note that negative ones are included in # actual demand. - eia_net_generation = list(net_generation.apply(lambda x: x[x > 0] - .sum()).values) + eia_net_generation = list(net_generation.apply(lambda x: x[x > 0].sum()).values) # If there is no such generator in the state, the function will return # a list of 0 instead of NaN. diff --git a/prereise/gather/hydrodata/eia/decompose_profile.py b/prereise/gather/hydrodata/eia/decompose_profile.py index 5518f0156..67b047e00 100644 --- a/prereise/gather/hydrodata/eia/decompose_profile.py +++ b/prereise/gather/hydrodata/eia/decompose_profile.py @@ -69,18 +69,17 @@ def get_profile_by_plant(plant_df, total_profile): raise TypeError("total_profile must be a pandas.Series object") if not all([float(val) == val for val in total_profile]): raise TypeError("total_profile must be all numbers") - if 'Pmax' not in plant_df.columns: + if "Pmax" not in plant_df.columns: raise ValueError("Pmax must be one of the columns of plant_df") - total_hydro_capacity = plant_df['Pmax'].sum() - res_profile = pd.DataFrame(index=total_profile.index, - columns=plant_df.index) + total_hydro_capacity = plant_df["Pmax"].sum() + res_profile = pd.DataFrame(index=total_profile.index, columns=plant_df.index) for plantid in res_profile.columns: if total_hydro_capacity == 0: factor = 0 else: - factor = plant_df.loc[plantid]['Pmax']/total_hydro_capacity - plant_profile = [val*factor for val in total_profile] + factor = plant_df.loc[plantid]["Pmax"] / total_hydro_capacity + plant_profile = [val * factor for val in total_profile] res_profile[plantid] = plant_profile.copy() return res_profile diff --git a/prereise/gather/hydrodata/eia/net_demand.py b/prereise/gather/hydrodata/eia/net_demand.py index 84e800f86..dbe53c9d8 100644 --- a/prereise/gather/hydrodata/eia/net_demand.py +++ b/prereise/gather/hydrodata/eia/net_demand.py @@ -42,8 +42,9 @@ def get_net_demand_profile(state, scenario): wind_in_state = wind[wind_plant_in_state].sum(axis=1) solar_in_state = solar[solar_plant_in_state].sum(axis=1) - loadzone_in_state = [grid.zone2id[z] for z in abv2loadzone[state] if z - in grid.zone2id] + loadzone_in_state = [ + grid.zone2id[z] for z in abv2loadzone[state] if z in grid.zone2id + ] demand_in_state = demand[loadzone_in_state].sum(axis=1) net_demand_in_state = demand_in_state - wind_in_state - solar_in_state diff --git a/prereise/gather/hydrodata/eia/tests/test_decompose_profile.py b/prereise/gather/hydrodata/eia/tests/test_decompose_profile.py index 88bac974a..7d6a6d3c3 100644 --- a/prereise/gather/hydrodata/eia/tests/test_decompose_profile.py +++ b/prereise/gather/hydrodata/eia/tests/test_decompose_profile.py @@ -2,8 +2,9 @@ import pandas as pd import pytest -from prereise.gather.hydrodata.eia.decompose_profile import \ - get_profile_by_state +from prereise.gather.hydrodata.eia.decompose_profile import ( + get_profile_by_state, +) def test_get_profile_argument_type():