Skip to content

Commit 15a6159

Browse files
Merge pull request #148 from PyPSA/refactor-inplace-operation
replace pandas inplace operation by assignment
2 parents 141da8b + 518bfbe commit 15a6159

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

powerplantmatching/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def to_year(ds):
298298
ppl = clean_name(ppl)
299299

300300
res = units.join(ppl.set_index("projectID"), "projectID", rsuffix="_ppl")
301-
res.DateIn.fillna(res.DateIn_ppl, inplace=True)
301+
res["DateIn"] = res.DateIn.fillna(res.DateIn_ppl)
302302
not_included_ppl = ppl.query("projectID not in @res.projectID")
303303
res = pd.concat([res, not_included_ppl]).pipe(set_column_name, "GEO")
304304
res = scale_to_net_capacities(res)
@@ -1232,7 +1232,7 @@ def UBA(
12321232
"\xd6lr\xfcckstand": "Oil",
12331233
}
12341234
)
1235-
uba.Name.replace([r"(?i)oe", r"(?i)ue"], ["ö", "ü"], regex=True, inplace=True)
1235+
uba["Name"] = uba.Name.replace([r"(?i)oe", r"(?i)ue"], ["ö", "ü"], regex=True)
12361236
if prune_wind:
12371237
uba = uba.loc[lambda x: x.Fueltype != "Wind"]
12381238
if prune_solar:
@@ -1574,7 +1574,7 @@ def IRENASTAT(raw=False, update=False, config=None):
15741574
}
15751575

15761576
df["Fueltype"] = df.Technology.map(fueltype_dict)
1577-
df.Technology.replace(technology_dict, inplace=True)
1577+
df["Technology"] = df.Technology.replace(technology_dict)
15781578

15791579
l = list(set(df.columns).difference(set(["Capacity"])))
15801580
df = df.groupby(l, as_index=False, dropna=True).sum()

powerplantmatching/heuristics.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ def fill_missing_commissioning_years(df):
233233
df = get_obj_if_Acc(df)
234234
df = df.copy()
235235
# 1st try: Fill with both country- and fueltypespecific averages
236-
df.DateIn.fillna(
237-
df.groupby(["Country", "Fueltype"]).DateIn.transform("mean"), inplace=True
236+
df["DateIn"] = df.DateIn.fillna(
237+
df.groupby(["Country", "Fueltype"]).DateIn.transform("mean")
238238
)
239239
# 2nd try: Fill remaining with only fueltype-specific average
240-
df.DateIn.fillna(df.groupby(["Fueltype"]).DateIn.transform("mean"), inplace=True)
240+
df["DateIn"] = df.DateIn.fillna(df.groupby(["Fueltype"]).DateIn.transform("mean"))
241241
# 3rd try: Fill remaining with only country-specific average
242-
df.DateIn.fillna(df.groupby(["Country"]).DateIn.transform("mean"), inplace=True)
242+
df["DateIn"] = df.DateIn.fillna(df.groupby(["Country"]).DateIn.transform("mean"))
243243
if df.DateIn.isnull().any():
244244
count = len(df[df.DateIn.isnull()])
245245
logger.warn(
@@ -251,7 +251,7 @@ def fill_missing_commissioning_years(df):
251251
)
252252
)
253253
df["DateIn"] = df.DateIn.astype(float)
254-
df.DateRetrofit.fillna(df.DateIn, inplace=True)
254+
df["DateRetrofit"] = df.DateRetrofit.fillna(df.DateIn)
255255
return df
256256

257257

@@ -319,7 +319,7 @@ def wm(x):
319319
target_fueltypes = ["Wind", "Solar", "Bioenergy"]
320320
df = df[df.Fueltype.isin(target_fueltypes)]
321321
df = fill_missing_commissioning_years(df)
322-
df.Technology.fillna("-", inplace=True)
322+
df["Technology"] = df.Technology.fillna("-")
323323
df = (
324324
df.groupby(["Country", "DateIn", "Fueltype", "Technology"])
325325
.agg(f)
@@ -539,7 +539,9 @@ def gross_to_net_factors(reference="opsd", aggfunc="median", return_entire_data=
539539
if return_entire_data:
540540
return df
541541
else:
542-
df.energy_source_level_2.fillna(value=df.energy_source, inplace=True)
542+
df["energy_source_level_2"] = df.energy_source_level_2.fillna(
543+
value=df.energy_source
544+
)
543545
df.replace(
544546
dict(
545547
energy_source_level_2={

0 commit comments

Comments
 (0)