@@ -333,6 +333,7 @@ def index_with_obj(
333
333
file_obj_sep : str = "_" ,
334
334
file_col : str = "RVFILE" ,
335
335
obj_col : str = "OBJECT" ,
336
+ obj_col_backup : str = "_INITIAL_BRAV0" ,
336
337
row_col : str = "ROW" ,
337
338
force_self_mask : bool = False ,
338
339
) -> DataFrame :
@@ -351,17 +352,30 @@ def index_with_obj(
351
352
:type file_obj_ind: int
352
353
:param file_obj_sep: Separator between filename parts, defaults to "_"
353
354
:type file_obj_sep: str, optional
355
+ :param obj_col: Column label to use for object names in output file
356
+ :type obj_col: str, optional
357
+ :param obj_col_backup: If there is already an obj_col column,
358
+ add obj_col_backup to its name.
359
+ :type obj_col_backup: str, optional
354
360
"""
355
361
356
362
df = df .copy ()
357
363
358
- # NOTE: this is a strong assumption on raw format/filenames
359
- # can think of ways to improve it in the future
360
364
if obj_col in df .columns :
361
- msg = f"There is already an { obj_col } column, doing nothing."
362
- warnings .warn (msg , category = RuntimeWarning )
363
- return
365
+ msg = f"There is already an { obj_col } column, moving it to { obj_col } _{ obj_col_backup } ."
366
+ new_obj_col = obj_col + obj_col_backup
367
+ if new_obj_col not in df :
368
+ warnings .warn (msg , category = RuntimeWarning )
369
+ df = df .rename (columns = {obj_col : new_obj_col })
370
+ else :
371
+ raise ValueError (
372
+ f"Both { obj_col } and { new_obj_col } already exist in the dataframe. "
373
+ "Provide new value for one of them."
374
+ )
364
375
376
+ # NOTE: Also strong assumption. Straightforward default would be something
377
+ # like OBJNAME.ext, with support for other ways to get name (block below
378
+ # or header key)
365
379
# Get filenames in pandas index object and split/index to get obj names
366
380
file_lvl = df .index .get_level_values (file_col )
367
381
objects = (
0 commit comments