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