Skip to content

Commit dc583b3

Browse files
authored
Enable python 3.9, 3.10 tests for Operators (#868)
1 parent 2a625ed commit dc583b3

File tree

15 files changed

+36
-18
lines changed

15 files changed

+36
-18
lines changed

.github/workflows/run-forecast-unit-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
python-version: ["3.8"]
30+
python-version: ["3.8", "3.9", "3.10"]
3131

3232
steps:
3333
- uses: actions/checkout@v4
@@ -56,4 +56,7 @@ jobs:
5656
$CONDA/bin/conda init
5757
source /home/runner/.bashrc
5858
pip install -r test-requirements-operators.txt
59+
pip install "oracle-automlx[classic]>=24.2.0"
60+
pip install "oracle-automlx[forecasting]>=24.2.0"
61+
pip install pandas>=2.2.0
5962
python -m pytest -v -p no:warnings --durations=5 tests/operators/forecast

.github/workflows/run-operators-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
python-version: ["3.8"]
30+
python-version: ["3.8", "3.9", "3.10"]
3131

3232
steps:
3333
- uses: actions/checkout@v4

ads/opctl/operator/lowcode/anomaly/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def operate(operator_config: AnomalyOperatorConfig) -> None:
4040
AnomalyOperatorModelFactory.get_model(
4141
operator_config, datasets
4242
).generate_report()
43-
except Exception as e2:
43+
except Exception as ee:
4444
logger.debug(
45-
f"Failed to backup forecast with error {e2.args}. Raising original error."
45+
f"Failed to backup forecast with error {ee.args}. Raising original error."
4646
)
47-
raise e
47+
raise ee
4848
else:
4949
raise e
5050

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _generate_report(self):
9191
),
9292
]
9393
model_description = rc.Text(
94-
"The automlx model automatically pre-processes, selects and engineers "
94+
"The autots model automatically pre-processes, selects and engineers "
9595
"high-quality features in your dataset, which then given to an automatically "
9696
"chosen and optimized machine learning model.."
9797
)

ads/opctl/operator/lowcode/anomaly/schema.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,8 @@ spec:
349349
model:
350350
type: string
351351
required: false
352-
default: automlx
352+
default: autots
353353
allowed:
354-
- automlx
355354
- autots
356355
- auto
357356
meta:

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*--
33

4-
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import os
@@ -77,5 +77,6 @@ def default_signer(**kwargs):
7777

7878
return default_signer(**kwargs)
7979

80+
8081
def select_auto_model(datasets, operator_config):
81-
return SupportedModels.AutoMLX
82+
return SupportedModels.AutoTS

ads/opctl/operator/lowcode/forecast/model/arima.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def _train_model(self, i, s_id, df, model_kwargs):
125125
logger.debug("===========Done===========")
126126
except Exception as e:
127127
self.errors_dict[s_id] = {"model_name": self.spec.model, "error": str(e)}
128+
logger.debug(f"Encountered Error: {e}. Skipping.")
128129

129130
def _build_model(self) -> pd.DataFrame:
130131
full_data_dict = self.datasets.get_data_by_series()

ads/opctl/operator/lowcode/forecast/model/automlx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _build_model(self) -> pd.DataFrame:
8484
loglevel=logging.CRITICAL,
8585
)
8686
except Exception as e:
87-
logger.info("Ray already initialized")
87+
logger.info(f"Error. Has Ray already been initialized? Skipping. {e}")
8888

8989
full_data_dict = self.datasets.get_data_by_series()
9090

@@ -168,6 +168,7 @@ def _build_model(self) -> pd.DataFrame:
168168
"model_name": self.spec.model,
169169
"error": str(e),
170170
}
171+
logger.debug(f"Encountered Error: {e}. Skipping.")
171172

172173
logger.debug("===========Forecast Generated===========")
173174

ads/opctl/operator/lowcode/forecast/model/autots.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def _build_model(self) -> pd.DataFrame:
209209
"model_name": self.spec.model,
210210
"error": str(e),
211211
}
212+
logger.debug(f"Encountered Error: {e}. Skipping.")
212213

213214
logger.debug("===========Done===========")
214215

ads/opctl/operator/lowcode/forecast/model/ml_forecast.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*--
3+
4+
# Copyright (c) 2024 Oracle and/or its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
16
import pandas as pd
27
import numpy as np
38

@@ -46,7 +51,6 @@ def preprocess(self, df, series_id):
4651
)
4752
def _train_model(self, data_train, data_test, model_kwargs):
4853
try:
49-
5054
import lightgbm as lgb
5155
from mlforecast import MLForecast
5256
from mlforecast.lag_transforms import ExpandingMean, RollingMean
@@ -158,6 +162,7 @@ def _train_model(self, data_train, data_test, model_kwargs):
158162
"model_name": self.spec.model,
159163
"error": str(e),
160164
}
165+
logger.debug(f"Encountered Error: {e}. Skipping.")
161166

162167
def _build_model(self) -> pd.DataFrame:
163168
data_train = self.datasets.get_all_data_long(include_horizon=False)

ads/opctl/operator/lowcode/forecast/model/neuralprophet.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def _fit_model(data, params, additional_regressors, select_metric):
7575
m = m.add_future_regressor(name=add_reg)
7676
m.fit(df=data)
7777
accepted_regressors_config = m.config_regressors or dict()
78+
if hasattr(accepted_regressors_config, "regressors"):
79+
accepted_regressors_config = accepted_regressors_config.regressors or dict()
7880

7981
enable_print()
8082
return m, list(accepted_regressors_config.keys())
@@ -122,7 +124,13 @@ def _train_model(self, i, s_id, df, model_kwargs):
122124

123125
if self.loaded_models is not None and s_id in self.loaded_models:
124126
model = self.loaded_models[s_id]
125-
accepted_regressors_config = model.config_regressors or dict()
127+
accepted_regressors_config = (
128+
model.config_regressors.regressors or dict()
129+
)
130+
if hasattr(accepted_regressors_config, "regressors"):
131+
accepted_regressors_config = (
132+
accepted_regressors_config.regressors or dict()
133+
)
126134
self.accepted_regressors[s_id] = list(accepted_regressors_config.keys())
127135
if self.loaded_trainers is not None and s_id in self.loaded_trainers:
128136
model.trainer = self.loaded_trainers[s_id]

ads/opctl/operator/lowcode/forecast/model/prophet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def _train_model(self, i, series_id, df, model_kwargs):
131131
"model_name": self.spec.model,
132132
"error": str(e),
133133
}
134+
logger.debug(f"Encountered Error: {e}. Skipping.")
134135

135136
def _build_model(self) -> pd.DataFrame:
136137
full_data_dict = self.datasets.get_data_by_series()

docs/source/user_guide/operators/anomaly_detection_operator/yaml_schema.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ Here is an example anomaly.yaml with every parameter specified:
3333
* **format**: the format of the datetime string in python notation `detailed here <https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes>`_.
3434

3535
* **target_category_columns**: (optional) The Series ID of the target. When provided, the target data must be present for each date in the datetime_column and for each series id in the target_category_columns.
36-
* **validation_data**: (optional) This dictionary contains the details for how to read the validation data. Validation data must contain all of the columns of input_data plus a column titles "anomaly".
36+
* **validation_data**: (optional) This dictionary contains the details for how to read the validation data. Validation data must contain all of the columns of input_data plus a column titled "anomaly".
3737
* **url**: Insert the uri for the dataset if it's on object storage or Data Lake using the URI pattern ``oci://<bucket>@<namespace>/path/to/data.csv``.
3838
* **kwargs**: Insert any other args for pandas to load the data (``format``, ``options``, etc.) See full list in ``YAML Schema`` section.
3939
* **output_directory**: (optional) This dictionary contains the details for where to put the output artifacts. The directory need not exist, but must be accessible by the Operator during runtime.
4040
* **url**: Insert the uri for the dataset if it's on object storage or Data Lake using the URI pattern ``oci://<bucket>@<namespace>/subfolder/``.
4141
* **kwargs**: Insert any other args for pandas to load the data (``format``, ``options``, etc.) See full list in ``YAML Schema`` section.
42-
* **model**: (optional) The name of the model framework you want to use. Defaults to "auto". Other options are: ``arima``, ``automlx``, ``prophet``, ``neuralprophet``, ``autots``, and ``auto``.
42+
* **model**: (optional) The name of the model framework you want to use. Defaults to "auto". Other options are: ``autots``, and ``auto``.
4343
* **model_kwargs**: (optional) This kwargs dict passes straight through to the model framework. If you want to take direct control of the modeling, this is the best way.
4444
* **test_data**: (optional) This dictionary contains the details for how to read the test data. Test data should contain every datetime value of the input_data, (optionally) all of the series from target_category_columns, and a column titles "anomaly" with either a 1 (non-anomalous) or 0 (anomalous).
4545
* **url**: Insert the uri for the dataset if it's on object storage or Data Lake using the URI pattern ``oci://<bucket>@<namespace>/path/to/data.csv``.

test-requirements-operators.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
-e ".[forecast]"
33
-e ".[feature-store-marketplace]"
44
plotly
5-
oracle-automlx[classic]>=24.2.0
6-
oracle-automlx[forecasting]>=24.2.0
75
pandas>=2.0.0
86
protobuf==3.20.3

tests/operators/anomaly/test_anomaly_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ads.opctl.operator.cmd import run
1717

1818

19-
MODELS = ["automlx", "autots"]
19+
MODELS = ["autots"] # "automlx",
2020

2121
# Mandatory YAML parameters
2222
TEMPLATE_YAML = {

0 commit comments

Comments
 (0)