Skip to content

Commit fa317e8

Browse files
committed
Ensure sorting in output dataframes is consistent
1 parent 42e7a69 commit fa317e8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

doped/thermodynamics.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3601,7 +3601,8 @@ def _add_effective_dopant_concentration(
36013601
def _group_defect_charge_state_concentrations(
36023602
conc_df: pd.DataFrame, per_site: bool = False, skip_formatting: bool = False
36033603
):
3604-
summed_df = conc_df.groupby("Defect").sum(numeric_only=True)
3604+
original_order = {k: i for i, k in enumerate(conc_df["Defect"].unique())} # preserve order
3605+
summed_df = conc_df.groupby("Defect").sum(numeric_only=True) # auto-reordered by groupby sum
36053606
conc_column = next(k for k in conc_df.columns if k.startswith("Concentration"))
36063607
raw_concentrations = (
36073608
summed_df["Raw Concentration"]
@@ -3611,6 +3612,9 @@ def _group_defect_charge_state_concentrations(
36113612
summed_df[conc_column] = raw_concentrations.apply(
36123613
lambda x: _format_concentration(x, per_site=per_site, skip_formatting=skip_formatting)
36133614
)
3615+
# Group and sort by original order
3616+
summed_df["order"] = summed_df.index.map(original_order)
3617+
summed_df = summed_df.sort_values(by="order").drop(columns="order")
36143618
return summed_df.drop(
36153619
columns=[
36163620
i

0 commit comments

Comments
 (0)