Skip to content

Commit 9f29a6e

Browse files
removed xmltodict library and added docstrings to new functions
1 parent 3ce2618 commit 9f29a6e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/modelspec/utils.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import math
99
import numpy as np
10-
import xmltodict
10+
1111

1212
from modelspec.base_types import print_
1313
from modelspec.base_types import EvaluableExpression
@@ -78,7 +78,7 @@ def load_xml(filename: str):
7878

7979
def element_to_dict(element):
8080
"""
81-
Convert an ElementTree element to a dictionary.
81+
This convert an ElementTree element to a dictionary.
8282
8383
Args:
8484
element: The ElementTree element to convert.
@@ -103,6 +103,15 @@ def element_to_dict(element):
103103

104104

105105
def convert_values(value):
106+
"""
107+
This recursively converts values to their actual types.
108+
109+
Args:
110+
value: The value to be converted.
111+
112+
Returns:
113+
The converted value with its actual data type.
114+
"""
106115
if isinstance(value, str):
107116
if value.isdigit():
108117
return int(value)
@@ -143,7 +152,7 @@ def save_to_yaml_file(info_dict, filename, indent=4):
143152

144153
def save_to_xml_file(info_dict, filename, indent=4, root="modelspec"):
145154
"""
146-
Save a dictionary to an XML file.
155+
This saves a dictionary to an XML file.
147156
148157
Args:
149158
info_dict (dict): The dictionary containing the data to be saved.
@@ -171,6 +180,16 @@ def save_to_xml_file(info_dict, filename, indent=4, root="modelspec"):
171180

172181

173182
def build_xml_element(parent, data):
183+
"""
184+
This recursively builds an XML element structure from a dictionary or a list.
185+
186+
Args:
187+
parent: The parent XML element to attach the new element(s) to.
188+
data: The data to convert into XML elements.
189+
190+
Returns:
191+
None
192+
"""
174193
if isinstance(data, dict):
175194
for key, value in data.items():
176195
if isinstance(value, dict):

0 commit comments

Comments
 (0)