Skip to content

Commit 1dd7278

Browse files
authored
Merge branch 'feature/forecast_v2' into ad/add_support_for_valid_data
2 parents 38e0ce0 + f195ea6 commit 1dd7278

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

ads/opctl/operator/lowcode/anomaly/model/base_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def _save_report(
247247

248248
output_dir = find_output_dirname(self.spec.output_directory)
249249

250-
if ObjectStorageDetails.is_oci_path(output_dir):
250+
if ObjectStorageDetails.is_oci_path(unique_output_dir):
251251
storage_options = default_signer()
252252
else:
253253
storage_options = dict()
@@ -260,7 +260,7 @@ def _save_report(
260260
enable_print()
261261
with open(report_local_path) as f1:
262262
with fsspec.open(
263-
os.path.join(output_dir, self.spec.report_file_name),
263+
os.path.join(unique_output_dir, self.spec.report_file_name),
264264
"w",
265265
**storage_options,
266266
) as f2:
@@ -270,15 +270,15 @@ def _save_report(
270270
inliers = anomaly_output.get_inliers(self.datasets.data)
271271
write_data(
272272
data=inliers,
273-
filename=os.path.join(output_dir, self.spec.inliers_filename),
273+
filename=os.path.join(unique_output_dir, self.spec.inliers_filename),
274274
format="csv",
275275
storage_options=storage_options,
276276
)
277277

278278
outliers = anomaly_output.get_outliers(self.datasets.data)
279279
write_data(
280280
data=outliers,
281-
filename=os.path.join(output_dir, self.spec.outliers_filename),
281+
filename=os.path.join(unique_output_dir, self.spec.outliers_filename),
282282
format="csv",
283283
storage_options=storage_options,
284284
)
@@ -293,7 +293,7 @@ def _save_report(
293293

294294
logger.warn(
295295
f"The report has been successfully "
296-
f"generated and placed to the: {output_dir}."
296+
f"generated and placed to the: {unique_output_dir}."
297297
)
298298

299299
@abstractmethod

ads/opctl/operator/lowcode/common/utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import yaml
2020
from typing import Union
2121

22+
from ads.opctl import logger
2223
from ads.opctl.operator.lowcode.common.errors import (
2324
InputDataError,
2425
InvalidParameterError,
@@ -105,6 +106,40 @@ def write_data(data, filename, format, storage_options, index=False, **kwargs):
105106
)
106107

107108

109+
def get_unique_report_dir(output_dir: str) -> str:
110+
"""
111+
Generate a unique directory path for the report output.
112+
113+
Parameters
114+
------------
115+
output_dir: str
116+
The requested output directory path.
117+
Returns
118+
--------
119+
str: The unique directory path for the report output.
120+
"""
121+
122+
if output_dir:
123+
output_dir = output_dir.url
124+
# set the unique directory path as the requested path by the user
125+
unique_output_dir = output_dir
126+
else:
127+
output_dir = "results"
128+
129+
# If the directory exists, find the next unique directory name by appending an incrementing suffix
130+
counter = 1
131+
unique_output_dir = f"{output_dir}"
132+
while os.path.exists(unique_output_dir):
133+
unique_output_dir = f"{output_dir}_{counter}"
134+
counter += 1
135+
logger.warn(
136+
"Since the output directory was not specified, the output will be saved to {} directory.".format(
137+
unique_output_dir
138+
)
139+
)
140+
return unique_output_dir
141+
142+
108143
def merge_category_columns(data, target_category_columns):
109144
result = data.apply(
110145
lambda x: "__".join([str(x[col]) for col in target_category_columns]), axis=1

0 commit comments

Comments
 (0)