@@ -435,15 +435,24 @@ def _save_report(
435
435
436
436
if self .spec .output_directory :
437
437
output_dir = self .spec .output_directory .url
438
+ # set the unique directory path as the requested path by the user
439
+ unique_output_dir = output_dir
438
440
else :
439
- output_dir = "tmp_fc_operator_result"
441
+ output_dir = "results"
442
+
443
+ # If the directory exists, find the next unique directory name by appending an incrementing suffix
444
+ counter = 1
445
+ unique_output_dir = f"{ output_dir } "
446
+ while os .path .exists (unique_output_dir ):
447
+ unique_output_dir = f"{ output_dir } _{ counter } "
448
+ counter += 1
440
449
logger .warn (
441
450
"Since the output directory was not specified, the output will be saved to {} directory." .format (
442
- output_dir
451
+ unique_output_dir
443
452
)
444
453
)
445
454
446
- if ObjectStorageDetails .is_oci_path (output_dir ):
455
+ if ObjectStorageDetails .is_oci_path (unique_output_dir ):
447
456
storage_options = default_signer ()
448
457
else :
449
458
storage_options = dict ()
@@ -457,7 +466,7 @@ def _save_report(
457
466
dp .save_report (report_sections , report_local_path )
458
467
utils .enable_print ()
459
468
460
- report_path = os .path .join (output_dir , self .spec .report_filename )
469
+ report_path = os .path .join (unique_output_dir , self .spec .report_filename )
461
470
with open (report_local_path ) as f1 :
462
471
with fsspec .open (
463
472
report_path ,
@@ -469,7 +478,7 @@ def _save_report(
469
478
# forecast csv report
470
479
utils ._write_data (
471
480
data = result_df ,
472
- filename = os .path .join (output_dir , self .spec .forecast_filename ),
481
+ filename = os .path .join (unique_output_dir , self .spec .forecast_filename ),
473
482
format = "csv" ,
474
483
storage_options = storage_options ,
475
484
)
@@ -479,7 +488,7 @@ def _save_report(
479
488
if metrics_df is not None :
480
489
utils ._write_data (
481
490
data = metrics_df .rename_axis ("metrics" ).reset_index (),
482
- filename = os .path .join (output_dir , self .spec .metrics_filename ),
491
+ filename = os .path .join (unique_output_dir , self .spec .metrics_filename ),
483
492
format = "csv" ,
484
493
storage_options = storage_options ,
485
494
index = False ,
@@ -495,7 +504,7 @@ def _save_report(
495
504
utils ._write_data (
496
505
data = test_metrics_df .rename_axis ("metrics" ).reset_index (),
497
506
filename = os .path .join (
498
- output_dir , self .spec .test_metrics_filename
507
+ unique_output_dir , self .spec .test_metrics_filename
499
508
),
500
509
format = "csv" ,
501
510
storage_options = storage_options ,
@@ -512,7 +521,7 @@ def _save_report(
512
521
utils ._write_data (
513
522
data = self .formatted_global_explanation ,
514
523
filename = os .path .join (
515
- output_dir , self .spec .global_explanation_filename
524
+ unique_output_dir , self .spec .global_explanation_filename
516
525
),
517
526
format = "csv" ,
518
527
storage_options = storage_options ,
@@ -527,7 +536,7 @@ def _save_report(
527
536
utils ._write_data (
528
537
data = self .formatted_local_explanation ,
529
538
filename = os .path .join (
530
- output_dir , self .spec .local_explanation_filename
539
+ unique_output_dir , self .spec .local_explanation_filename
531
540
),
532
541
format = "csv" ,
533
542
storage_options = storage_options ,
@@ -546,7 +555,7 @@ def _save_report(
546
555
# model params
547
556
utils ._write_data (
548
557
data = pd .DataFrame .from_dict (self .model_parameters ),
549
- filename = os .path .join (output_dir , "model_params.json" ),
558
+ filename = os .path .join (unique_output_dir , "model_params.json" ),
550
559
format = "json" ,
551
560
storage_options = storage_options ,
552
561
index = True ,
@@ -555,17 +564,17 @@ def _save_report(
555
564
556
565
# model pickle
557
566
if self .spec .generate_model_pickle :
558
- self ._save_model (output_dir , storage_options )
567
+ self ._save_model (unique_output_dir , storage_options )
559
568
560
569
logger .info (
561
570
f"The outputs have been successfully "
562
- f"generated and placed into the directory: { output_dir } ."
571
+ f"generated and placed into the directory: { unique_output_dir } ."
563
572
)
564
573
if self .errors_dict :
565
574
utils ._write_data (
566
575
data = pd .DataFrame (self .errors_dict .items (), columns = ["model" , "error" ]),
567
576
filename = os .path .join (
568
- output_dir , self .spec .errors_dict_filename
577
+ unique_output_dir , self .spec .errors_dict_filename
569
578
),
570
579
format = "csv" ,
571
580
storage_options = storage_options ,
0 commit comments