From 8a243c95fba209760ebccbd7dfe81b2f93253a5d Mon Sep 17 00:00:00 2001 From: Gianna Jordan <61707471+GiaJordan@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:55:34 -0700 Subject: [PATCH 1/2] add cases for str and numerical entries --- schematic/utils/validate_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/schematic/utils/validate_utils.py b/schematic/utils/validate_utils.py index 3e694bce8..365991334 100644 --- a/schematic/utils/validate_utils.py +++ b/schematic/utils/validate_utils.py @@ -6,6 +6,7 @@ from schematic import LOADER from typing import List import numpy as np +from numbers import Number def validate_schema(schema): """Validate schema against schema.org standard""" @@ -76,10 +77,18 @@ def np_array_to_str_list(np_array): def iterable_to_str_list(iterable): "Parse an iterable into a list of strings" - strlist = [] - for element in iterable: - strlist.append(str(element)) + # If object is a string, just return wrapped as a list + if isinstance(iterable, str): + return [iterable] + # If object is numberical, convert to string and wrap as a list + elif isinstance(iterable, Number): + return [str(iterable)] + # If the object is iterable and not a string, convert every element to string and wratp as a list + else: + strlist = [] + for element in iterable: + strlist.append(str(element)) return strlist \ No newline at end of file From 8f2885cf4305dda0f57a976f6f243b1ca8afd48a Mon Sep 17 00:00:00 2001 From: Gianna Jordan <61707471+GiaJordan@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:55:55 -0700 Subject: [PATCH 2/2] update docstring --- schematic/utils/validate_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/schematic/utils/validate_utils.py b/schematic/utils/validate_utils.py index 365991334..78c8277eb 100644 --- a/schematic/utils/validate_utils.py +++ b/schematic/utils/validate_utils.py @@ -76,7 +76,10 @@ def np_array_to_str_list(np_array): return np.char.mod('%d', np_array).tolist() def iterable_to_str_list(iterable): - "Parse an iterable into a list of strings" + """ + Parse an object into a list of strings + Accepts str, Number, and iterable inputs + """ # If object is a string, just return wrapped as a list if isinstance(iterable, str):