File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -682,11 +682,30 @@ def render_return_value(
682682 layout = QVBoxLayout (container )
683683 nm_checkbox = QCheckBox ("Convert to nm" )
684684 nm_checkbox .setChecked (False )
685+
685686 # Create table widget
686687 table = QTableWidget ()
687688 table .setRowCount (len (df ))
688689 table .setColumnCount (len (df .columns ))
689690 table .setHorizontalHeaderLabels (df .columns .tolist ())
691+
692+ if isinstance (original , Labels ):
693+ # Create a copy of the dataframe with an extra row for the background for proper alignmemt of labels
694+ # This will not affect the original dataframe used for the table
695+ features_df = df .copy ()
696+ features_df .index = features_df .index + 1
697+ if 0 not in features_df .index :
698+ # Get the first row to copy the columns and dtypes
699+ bg_row = features_df .iloc [[0 ]].copy ()
700+ bg_row .index = [0 ]
701+ # Fill the row with NaN
702+ bg_row .loc [0 ] = np .nan
703+ if "grain_number" in bg_row .columns :
704+ # Set grain_number to -1 for the background row so it is different from real grains (0-indexed)
705+ bg_row ["grain_number" ] = - 1
706+ features_df = pd .concat ([bg_row , features_df ])
707+ features_df ["label_id" ] = features_df .index
708+ original .features = features_df
690709 original .mode = Mode .PICK
691710 is_updating = False
692711
You can’t perform that action at this time.
0 commit comments