File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -3601,7 +3601,8 @@ def _add_effective_dopant_concentration(
3601
3601
def _group_defect_charge_state_concentrations (
3602
3602
conc_df : pd .DataFrame , per_site : bool = False , skip_formatting : bool = False
3603
3603
):
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
3605
3606
conc_column = next (k for k in conc_df .columns if k .startswith ("Concentration" ))
3606
3607
raw_concentrations = (
3607
3608
summed_df ["Raw Concentration" ]
@@ -3611,6 +3612,9 @@ def _group_defect_charge_state_concentrations(
3611
3612
summed_df [conc_column ] = raw_concentrations .apply (
3612
3613
lambda x : _format_concentration (x , per_site = per_site , skip_formatting = skip_formatting )
3613
3614
)
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" )
3614
3618
return summed_df .drop (
3615
3619
columns = [
3616
3620
i
You can’t perform that action at this time.
0 commit comments