Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandas deprecation fixes #916

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions scripts/make_summary_perfect.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ def calculate_energy(n, label, energy):
.groupby(level=0)
.sum()
.multiply(c.df.sign)
.groupby(c.df.carrier, axis=1)
.T.groupby(c.df.carrier)
.sum()
.T
)
else:
c_energies = pd.DataFrame(
Expand Down Expand Up @@ -394,16 +395,9 @@ def calculate_supply_energy(n, label, supply_energy):
if len(items) == 0:
continue

s = (
(-1)
* c.pnl["p" + end]
.reindex(items, axis=1)
.multiply(n.snapshot_weightings.objective, axis=0)
.groupby(level=0)
.sum()
.groupby(c.df.loc[items, "carrier"], axis=1)
.sum()
).T
s = (-1) * c.pnl["p" + end].reindex(items, axis=1).multiply(
n.snapshot_weightings.objective, axis=0
).groupby(level=0).sum().T.groupby(c.df.loc[items, "carrier"]).sum()
s.index = s.index + end
s = pd.concat([s], keys=[c.list_name])
s = pd.concat([s], keys=[i])
Expand Down Expand Up @@ -498,7 +492,7 @@ def calculate_weighted_prices(n, label, weighted_prices):
else:
suffix = " " + carrier

buses = n.buses.index[n.buses.index.str[2:] == suffix]
buses = n.buses.index[n.buses.index.str[5:] == suffix]

if buses.empty:
continue
Expand All @@ -509,14 +503,14 @@ def calculate_weighted_prices(n, label, weighted_prices):
else n.loads_t.p_set.reindex(buses, axis=1)
)
for tech in value:
names = n.links.index[n.links.index.to_series().str[-len(tech) :] == tech]
names = n.links.index[
n.links.index.to_series().str[-len(tech) - 5 : -5] == tech
]

if names.empty:
continue

load += (
n.links_t.p0[names].groupby(n.links.loc[names, "bus0"], axis=1).sum()
)
load += n.links_t.p0[names].T.groupby(n.links.loc[names, "bus0"]).sum().T

# Add H2 Store when charging
# if carrier == "H2":
Expand Down Expand Up @@ -557,9 +551,9 @@ def calculate_market_values(n, label, market_values):

dispatch = (
n.generators_t.p[gens]
.groupby(n.generators.loc[gens, "bus"], axis=1)
.T.groupby(n.generators.loc[gens, "bus"])
.sum()
.reindex(columns=buses, fill_value=0.0)
.T.reindex(columns=buses, fill_value=0.0)
)

revenue = dispatch * n.buses_t.marginal_price[buses]
Expand All @@ -583,9 +577,9 @@ def calculate_market_values(n, label, market_values):

dispatch = (
n.links_t["p" + i][links]
.groupby(n.links.loc[links, "bus" + i], axis=1)
.T.groupby(n.links.loc[links, "bus" + i])
.sum()
.reindex(columns=buses, fill_value=0.0)
.T.reindex(columns=buses, fill_value=0.0)
)

revenue = dispatch * n.buses_t.marginal_price[buses]
Expand Down Expand Up @@ -652,7 +646,7 @@ def calculate_co2_emissions(n, label, df):
emitted = n.generators_t.p[gens.index].mul(em_pu)

emitted_grouped = (
emitted.groupby(level=0).sum().groupby(n.generators.carrier, axis=1).sum().T
emitted.groupby(level=0).sum().T.groupby(n.generators.carrier).sum()
)

df = df.reindex(emitted_grouped.index.union(df.index))
Expand Down
6 changes: 4 additions & 2 deletions scripts/prepare_perfect_foresight.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def get_investment_weighting(time_weighting, r=0.01):
end = time_weighting.cumsum()
start = time_weighting.cumsum().shift().fillna(0)
return pd.concat([start, end], axis=1).apply(
lambda x: sum(get_social_discount(t, r) for t in range(int(x[0]), int(x[1]))),
lambda x: sum(
get_social_discount(t, r) for t in range(int(x.iloc[0]), int(x.iloc[1]))
),
axis=1,
)

Expand Down Expand Up @@ -188,7 +190,7 @@ def concat_networks(years):
pnl = getattr(n, component.list_name + "_t")
for k in iterkeys(component.pnl):
pnl_year = component.pnl[k].copy().reindex(snapshots, level=1)
if pnl_year.empty and ~(component.name == "Load" and k == "p_set"):
if pnl_year.empty and (not (component.name == "Load" and k == "p_set")):
continue
if component.name == "Load":
static_load = network.loads.loc[network.loads.p_set != 0]
Expand Down
Loading