Skip to content

Commit aabbb98

Browse files
Adding bool parser
1 parent 782839f commit aabbb98

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

ads/common/utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from enum import Enum
2323
from io import DEFAULT_BUFFER_SIZE
2424
from textwrap import fill
25-
from typing import Dict, Optional, Tuple, Union
25+
from typing import Any, Dict, Optional, Tuple, Union
2626
from urllib import request
2727
from urllib.parse import urlparse
2828

@@ -231,6 +231,28 @@ def random_valid_ocid(prefix="ocid1.dataflowapplication.oc1.iad"):
231231
return f"{left}.{fake}"
232232

233233

234+
def parse_bool(value: Any) -> bool:
235+
"""
236+
Converts a value to boolean. For strings, it interprets 'true', '1', or 'yes'
237+
(case insensitive) as True; everything else as False.
238+
239+
Parameters
240+
----------
241+
value : Any
242+
The value to convert to boolean.
243+
244+
Returns
245+
-------
246+
bool
247+
The boolean interpretation of the value.
248+
"""
249+
if isinstance(value, bool):
250+
return value
251+
if isinstance(value, str):
252+
return value.strip().lower() in ("true", "1", "yes")
253+
return bool(value)
254+
255+
234256
def read_file(file_path: str, **kwargs) -> str:
235257
try:
236258
with fsspec.open(file_path, "r", **kwargs.get("auth", {})) as f:

ads/model/model_metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ads.common.extended_enum import ExtendedEnum
2525
from ads.common.object_storage_details import ObjectStorageDetails
2626
from ads.common.serializer import DataClassSerializable
27+
from ads.common.utils import parse_bool
2728
from ads.dataset import factory
2829

2930
try:
@@ -345,7 +346,7 @@ def _from_oci_metadata(cls, oci_metadata_item) -> "ModelMetadataItem":
345346
if isinstance(key_value_map["value"], str):
346347
try:
347348
key_value_map["value"] = json.loads(oci_metadata_item.get("value"))
348-
key_value_map["has_artifact"] = bool(
349+
key_value_map["has_artifact"] = parse_bool(
349350
oci_metadata_item.get("has_artifact")
350351
)
351352
except Exception:

0 commit comments

Comments
 (0)