Skip to content

Commit

Permalink
Fix pandas deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa committed Aug 23, 2018
1 parent b310303 commit ca2198b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pypsa/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,15 +746,15 @@ def __getitem__(self, key):
#presence of links without s_nom_extendable
def branches(self):
return pd.concat((self.df(c) for c in self.branch_components),
keys=self.branch_components)
keys=self.branch_components, sort=False)

def passive_branches(self):
return pd.concat((self.df(c) for c in self.passive_branch_components),
keys=self.passive_branch_components)
keys=self.passive_branch_components, sort=False)

def controllable_branches(self):
return pd.concat((self.df(c) for c in self.controllable_branch_components),
keys=self.controllable_branch_components)
keys=self.controllable_branch_components, sort=False)

def determine_network_topology(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion pypsa/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def get_switchable_as_dense(network, component, attr, snapshots=None, inds=None)
pd.DataFrame(np.repeat([df.loc[fixed_i, attr].values], len(snapshots), axis=0),
index=snapshots, columns=fixed_i),
pnl[attr].loc[snapshots, varying_i]
], axis=1).reindex(columns=index))
], axis=1, sort=False).reindex(columns=index))

def get_switchable_as_iter(network, component, attr, snapshots, inds=None):
"""
Expand Down
12 changes: 6 additions & 6 deletions pypsa/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def import_components_from_dataframe(network, dataframe, cls_name):
old_df = network.df(cls_name)
new_df = dataframe.drop(non_static_attrs_in_df, axis=1)
if not old_df.empty:
new_df = pd.concat((old_df, new_df))
new_df = pd.concat((old_df, new_df), sort=False)

if not new_df.index.is_unique:
logger.error("Error, new components for {} are not unique".format(cls_name))
Expand Down Expand Up @@ -712,14 +712,14 @@ def import_series_from_dataframe(network, dataframe, cls_name, attr):
if len(diff) > 0:
logger.warning("Components {} for attribute {} of {} are not in main components dataframe {}".format(diff,attr,cls_name,list_name))

diff = network.snapshots.difference(dataframe.index)
if len(diff):
logger.warning("Snapshots {} are missing from {} of {}".format(diff,attr,cls_name))


attr_series = network.components[cls_name]["attrs"].loc[attr]
columns = dataframe.columns

diff = network.snapshots.difference(dataframe.index)
if len(diff):
logger.warning("Snapshots {} are missing from {} of {}. Filling with default value '{}'".format(diff,attr,cls_name,attr_series["default"]))
dataframe = dataframe.reindex(network.snapshots, fill_value=attr_series["default"])

if not attr_series.static:
pnl[attr] = pnl[attr].reindex(columns=df.index|columns, fill_value=attr_series.default)
else:
Expand Down
8 changes: 4 additions & 4 deletions pypsa/networkclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def aggregategenerators(network, busmap, with_time=True, carriers=None):

new_df = pd.concat([new_df,
network.generators.loc[~gens_agg_b]
.assign(bus=lambda df: df.bus.map(busmap))], axis=0)
.assign(bus=lambda df: df.bus.map(busmap))], axis=0, sort=False)

new_pnl = dict()
if with_time:
Expand All @@ -93,7 +93,7 @@ def aggregategenerators(network, busmap, with_time=True, carriers=None):
df_agg = df_agg.multiply(weighting.loc[df_agg.columns], axis=1)
pnl_df = df_agg.groupby(grouper, axis=1).sum()
pnl_df.columns = _flatten_multiindex(pnl_df.columns).rename("name")
new_pnl[attr] = pd.concat([df.loc[:, ~pnl_gens_agg_b], pnl_df], axis=1)
new_pnl[attr] = pd.concat([df.loc[:, ~pnl_gens_agg_b], pnl_df], axis=1, sort=False)

return new_df, new_pnl

Expand Down Expand Up @@ -145,7 +145,7 @@ def aggregatelines(network, buses, interlines, line_length_factor=1.0):
positive_order = interlines.bus0_s < interlines.bus1_s
interlines_p = interlines[positive_order]
interlines_n = interlines[~ positive_order].rename(columns={"bus0_s":"bus1_s", "bus1_s":"bus0_s"})
interlines_c = pd.concat((interlines_p,interlines_n))
interlines_c = pd.concat((interlines_p,interlines_n), sort=False)

attrs = network.components["Line"]["attrs"]
columns = set(attrs.index[attrs.static & attrs.status.str.startswith('Input')]).difference(('name', 'bus0', 'bus1'))
Expand Down Expand Up @@ -199,7 +199,7 @@ def normed(s):

linemap_p = interlines_p.join(lines['name'], on=['bus0_s', 'bus1_s'])['name']
linemap_n = interlines_n.join(lines['name'], on=['bus0_s', 'bus1_s'])['name']
linemap = pd.concat((linemap_p,linemap_n))
linemap = pd.concat((linemap_p,linemap_n), sort=False)

return lines, linemap_p, linemap_n, linemap

Expand Down
5 changes: 3 additions & 2 deletions pypsa/opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ def define_passive_branch_constraints(network,snapshots):


s_max_pu = pd.concat({c : get_switchable_as_dense(network, c, 's_max_pu', snapshots)
for c in network.passive_branch_components}, axis=1)
for c in network.passive_branch_components}, axis=1, sort=False)

flow_upper = {(b[0],b[1],sn) : [[(1,network.model.passive_branch_p[b[0],b[1],sn])],
"<=", s_max_pu.at[sn,b]*fixed_branches.at[b,"s_nom"]]
Expand Down Expand Up @@ -1204,7 +1204,8 @@ def get_shadows(constraint, multiind=True):
pd.concat({c.name:
c.pnl.p.loc[snapshots].multiply(c.df.sign, axis=1)
.groupby(c.df.bus, axis=1).sum()
for c in network.iterate_components(network.controllable_one_port_components)}) \
for c in network.iterate_components(network.controllable_one_port_components)},
sort=False) \
.sum(level=1) \
.reindex(columns=network.buses_t.p.columns, fill_value=0.)

Expand Down

0 comments on commit ca2198b

Please sign in to comment.