Skip to content

Commit 8f79757

Browse files
authored
Merge branch 'main' into ODSC-52249/run_tests_for_src_folder
2 parents 2f0e404 + d996812 commit 8f79757

32 files changed

+1989
-51
lines changed

ads/catalog/model.py

Lines changed: 3 additions & 3 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) 2020, 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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 warnings
@@ -404,13 +404,13 @@ def show_in_notebook(self, display_format: str = "dataframe") -> None:
404404
def _repr_html_(self):
405405
"""Shows model in dataframe format."""
406406
return (
407-
self.to_dataframe().style.set_properties(**{"margin-left": "0px"}).render()
407+
self.to_dataframe().style.set_properties(**{"margin-left": "0px"}).to_html()
408408
)
409409

410410
def __repr__(self):
411411
"""Shows model in dataframe format."""
412412
return (
413-
self.to_dataframe().style.set_properties(**{"margin-left": "0px"}).render()
413+
self.to_dataframe().style.set_properties(**{"margin-left": "0px"}).to_html()
414414
)
415415

416416
def activate(self) -> None:

ads/catalog/notebook.py

Lines changed: 3 additions & 3 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) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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 warnings
@@ -220,7 +220,7 @@ def _repr_html_(notebook_self):
220220
lambda x: "<a href='%s'>%s</a>"
221221
% (x if x.startswith("http") else "http://%s" % x, "open")
222222
)
223-
return df.style.set_properties(**{"margin-left": "0px"}).render()
223+
return df.style.set_properties(**{"margin-left": "0px"}).to_html()
224224

225225
notebook.commit = MethodType(commit, notebook)
226226
notebook.rollback = MethodType(rollback, notebook)
@@ -295,7 +295,7 @@ def create_notebook_session(
295295
shape=None,
296296
block_storage_size_in_gbs=None,
297297
subnet_id=None,
298-
**kwargs
298+
**kwargs,
299299
):
300300
"""
301301
Create a new notebook session with the supplied details.

ads/catalog/project.py

Lines changed: 2 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) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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 warnings
@@ -237,7 +237,7 @@ def _repr_html_(project_self):
237237
return (
238238
project_self.to_dataframe()
239239
.style.set_properties(**{"margin-left": "0px"})
240-
.render()
240+
.to_html()
241241
)
242242

243243
project.commit = MethodType(commit, project)

ads/catalog/summary.py

Lines changed: 2 additions & 4 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) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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
from __future__ import print_function, absolute_import
@@ -98,7 +98,6 @@ def __add__(self, rhs): # pragma: no cover
9898
pass
9999

100100
def to_dataframe(self, datetime_format=None):
101-
102101
"""
103102
Returns the model catalog summary as a pandas dataframe
104103
@@ -121,7 +120,6 @@ def to_dataframe(self, datetime_format=None):
121120

122121
@runtime_dependency(module="IPython", install_from=OptionalDependency.NOTEBOOK)
123122
def show_in_notebook(self, datetime_format=None):
124-
125123
"""
126124
Displays the model catalog summary in a Jupyter Notebook cell
127125
@@ -144,7 +142,7 @@ def show_in_notebook(self, datetime_format=None):
144142
def _repr_html_(self):
145143
return self.df.style.applymap(
146144
self._color_lifecycle_state, subset=["lifecycle_state"]
147-
).render()
145+
).to_html()
148146

149147
def _sort_by(self, cols, reverse=False):
150148
return sorted(

ads/data_labeling/metadata.py

Lines changed: 2 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) 2021, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2021, 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
from dataclasses import asdict, dataclass, field
@@ -75,7 +75,7 @@ def to_dataframe(self) -> pd.DataFrame:
7575
def _repr_html_(self):
7676
"""Shows metadata in dataframe format."""
7777
return (
78-
self.to_dataframe().style.set_properties(**{"margin-left": "0px"}).render()
78+
self.to_dataframe().style.set_properties(**{"margin-left": "0px"}).to_html()
7979
)
8080

8181
@classmethod

ads/dataset/dataset.py

Lines changed: 3 additions & 5 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) 2020, 2023 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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
from __future__ import print_function, absolute_import, division
@@ -85,7 +85,6 @@ def __init__(
8585
interactive=False,
8686
**kwargs,
8787
):
88-
8988
#
9089
# to keep performance high and linear no matter the size of the distributed dataset we
9190
# create a pandas df that's used internally because this has a fixed upper size.
@@ -204,7 +203,7 @@ def _repr_html_(self):
204203
.style.set_table_styles(utils.get_dataframe_styles())
205204
.set_table_attributes("class=table")
206205
.hide_index()
207-
.render()
206+
.to_html()
208207
)
209208
)
210209
)
@@ -263,7 +262,7 @@ def _repr_html_(self):
263262
self.style.set_table_styles(utils.get_dataframe_styles())
264263
.set_table_attributes("class=table")
265264
.hide_index()
266-
.render()
265+
.to_html()
267266
)
268267
)
269268
)
@@ -1265,7 +1264,6 @@ def _build_new_dataset(
12651264
n=None,
12661265
**init_kwargs,
12671266
):
1268-
12691267
prev_doc_mode = utils.is_documentation_mode()
12701268

12711269
set_documentation_mode(False)

ads/dataset/factory.py

Lines changed: 2 additions & 3 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) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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
from __future__ import print_function, absolute_import
@@ -367,7 +367,7 @@ def list_snapshots(snapshot_dir=None, name="", storage_options=None, **kwargs):
367367
HTML(
368368
list_df.style.set_table_attributes("class=table")
369369
.hide_index()
370-
.render()
370+
.to_html()
371371
)
372372
)
373373
return list_df
@@ -884,7 +884,6 @@ def read_xml(path: str, **kwargs) -> pd.DataFrame:
884884
import xml.etree.cElementTree as et
885885

886886
def get_children(df, node, parent, i):
887-
888887
for name in node.attrib.keys():
889888
df.at[i, parent + name] = node.attrib[name]
890889
for child in list(node):

ads/dataset/sampled_dataset.py

Lines changed: 3 additions & 5 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) 2020, 2022 Oracle and/or its affiliates.
4+
# Copyright (c) 2020, 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 matplotlib
@@ -49,6 +49,7 @@
4949

5050
NATURAL_EARTH_DATASET = "naturalearth_lowres"
5151

52+
5253
class PandasDataset(object):
5354
"""
5455
This class provides APIs that can work on a sampled dataset.
@@ -107,7 +108,6 @@ def __init__(
107108
self.sampled_df = self.sampled_df.reset_index(drop=True)
108109

109110
def _find_feature_subset(self, df, target_name, include_n_features=32):
110-
111111
if len(df.columns) <= include_n_features:
112112
return self.sampled_df
113113
else:
@@ -212,7 +212,6 @@ def _calculate_dataset_statistics(self, is_wide_dataset, out):
212212
def _generate_features_html(
213213
self, is_wide_dataset, n_features, df_stats, visualizations_follow
214214
):
215-
216215
html = utils.get_bootstrap_styles()
217216

218217
if is_wide_dataset:
@@ -233,7 +232,7 @@ def _generate_features_html(
233232
if ("float" in str(type(x))) or ("int" in str(type(x)))
234233
else x
235234
)
236-
.render()
235+
.to_html()
237236
)
238237

239238
if visualizations_follow:
@@ -244,7 +243,6 @@ def _generate_features_html(
244243
def _generate_warnings_html(
245244
self, is_wide_dataset, n_rows, n_features, df_stats, out, accordion
246245
):
247-
248246
#
249247
# create the "Warnings" accordion section:
250248
# - show high cardinal categoricals

ads/jobs/ads_job.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import fsspec
1212
import oci
13+
import yaml
1314
from ads.common.auth import default_signer
1415
from ads.common.decorator.utils import class_or_instance_method
1516
from ads.jobs.builders.base import Builder
@@ -263,6 +264,9 @@ def __init__(
263264
Job runtime, by default None.
264265
265266
"""
267+
# Saves a copy of the auth object from the class to the instance.
268+
# Future changes to the class level Job.auth will not affect the auth of existing instances.
269+
self.auth = self.auth.copy()
266270
for key in ["config", "signer", "client_kwargs"]:
267271
if kwargs.get(key):
268272
self.auth[key] = kwargs.pop(key)
@@ -545,6 +549,26 @@ def to_dict(self, **kwargs: Dict) -> Dict:
545549
"spec": spec,
546550
}
547551

552+
@class_or_instance_method
553+
def from_yaml(
554+
cls,
555+
yaml_string: str = None,
556+
uri: str = None,
557+
loader: callable = yaml.SafeLoader,
558+
**kwargs,
559+
):
560+
if inspect.isclass(cls):
561+
job = cls(**cls.auth)
562+
else:
563+
job = cls.__class__(**cls.auth)
564+
565+
if yaml_string:
566+
return job.from_dict(yaml.load(yaml_string, Loader=loader))
567+
if uri:
568+
yaml_dict = yaml.load(cls._read_from_file(uri=uri, **kwargs), Loader=loader)
569+
return job.from_dict(yaml_dict)
570+
raise ValueError("Must provide either YAML string or URI location")
571+
548572
@class_or_instance_method
549573
def from_dict(cls, config: dict) -> "Job":
550574
"""Initializes a job from a dictionary containing the configurations.
@@ -573,9 +597,9 @@ def from_dict(cls, config: dict) -> "Job":
573597
"runtime": cls._RUNTIME_MAPPING,
574598
}
575599
if inspect.isclass(cls):
576-
job = cls()
600+
job = cls(**cls.auth)
577601
else:
578-
job = cls.__class__()
602+
job = cls.__class__(**cls.auth)
579603

580604
for key, value in spec.items():
581605
if key in mappings:

ads/jobs/builders/infrastructure/dsc_job.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from __future__ import annotations
77

88
import datetime
9+
import inspect
910
import logging
10-
import oci
1111
import os
1212
import time
1313
import traceback
@@ -17,11 +17,12 @@
1717
from typing import Any, Dict, List, Optional, Union
1818

1919
import fsspec
20+
import oci
2021
import oci.data_science
2122
import oci.util as oci_util
22-
import yaml
2323
from oci.data_science.models import JobInfrastructureConfigurationDetails
2424
from oci.exceptions import ServiceError
25+
import yaml
2526
from ads.common import utils
2627
from ads.common.oci_datascience import DSCNotebookSession, OCIDataScienceMixin
2728
from ads.common.oci_logging import OCILog
@@ -782,7 +783,7 @@ def to_yaml(self) -> str:
782783
# Update runtime from job run
783784
from ads.jobs import Job
784785

785-
job = Job.from_dict(job_dict)
786+
job = Job(**self.auth).from_dict(job_dict)
786787
envs = job.runtime.envs
787788
run_config_override = run_dict.get("jobConfigurationOverrideDetails", {})
788789
envs.update(run_config_override.get("environmentVariables", {}))
@@ -811,7 +812,7 @@ def job(self):
811812
"""
812813
from ads.jobs import Job
813814

814-
return Job.from_datascience_job(self.job_id)
815+
return Job(**self.auth).from_datascience_job(self.job_id)
815816

816817
def download(self, to_dir):
817818
"""Downloads files from job run output URI to local.
@@ -953,9 +954,9 @@ def standardize_spec(spec):
953954
if key not in attribute_map and key.lower() in snake_to_camel_map:
954955
value = spec.pop(key)
955956
if isinstance(value, dict):
956-
spec[
957-
snake_to_camel_map[key.lower()]
958-
] = DataScienceJob.standardize_spec(value)
957+
spec[snake_to_camel_map[key.lower()]] = (
958+
DataScienceJob.standardize_spec(value)
959+
)
959960
else:
960961
spec[snake_to_camel_map[key.lower()]] = value
961962
return spec
@@ -971,6 +972,9 @@ def __init__(self, spec: Dict = None, **kwargs) -> None:
971972
Specification as keyword arguments.
972973
If spec contains the same key as the one in kwargs, the value from kwargs will be used.
973974
"""
975+
# Saves a copy of the auth object from the class to the instance.
976+
# Future changes to the class level Job.auth will not affect the auth of existing instances.
977+
self.auth = self.auth.copy()
974978
for key in ["config", "signer", "client_kwargs"]:
975979
if kwargs.get(key):
976980
self.auth[key] = kwargs.pop(key)
@@ -1710,6 +1714,15 @@ def from_id(cls, job_id: str) -> DataScienceJob:
17101714
"""
17111715
return cls.from_dsc_job(DSCJob(**cls.auth).from_ocid(job_id))
17121716

1717+
@class_or_instance_method
1718+
def from_dict(cls, obj_dict: dict):
1719+
"""Initialize the object from a Python dictionary"""
1720+
if inspect.isclass(cls):
1721+
job_cls = cls
1722+
else:
1723+
job_cls = cls.__class__
1724+
return job_cls(spec=obj_dict.get("spec"), **cls.auth)
1725+
17131726
@class_or_instance_method
17141727
def list_jobs(cls, compartment_id: str = None, **kwargs) -> List[DataScienceJob]:
17151728
"""Lists all jobs in a compartment.

0 commit comments

Comments
 (0)