Skip to content

Commit 4e1286c

Browse files
0.14.6
new method check_type
1 parent 9b45793 commit 4e1286c

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotPython"
10-
version = "0.14.5"
10+
version = "0.14.6"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotPython/spot/spot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,17 @@ def fit_surrogate(self) -> None:
10481048
self.plot_model()
10491049

10501050
def show_progress_if_needed(self, timeout_start) -> None:
1051+
"""Show progress bar if `show_progress` is `True`. If
1052+
self.progress_file is not `None`, the progress bar is saved
1053+
in the file with the name `self.progress_file`.
1054+
1055+
Args:
1056+
self (object): Spot object
1057+
timeout_start (float): start time
1058+
1059+
Returns:
1060+
(NoneType): None
1061+
"""
10511062
if not self.show_progress:
10521063
return
10531064
if isfinite(self.fun_evals):

src/spotPython/utils/convert.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,32 @@ def sort_by_kth_and_return_indices(array, k) -> list:
179179
sorted_indices = [index for index, value in sorted(enumerate(array), key=lambda x: x[1][k], reverse=True)]
180180

181181
return sorted_indices
182+
183+
184+
def check_type(value):
185+
"""Check the type of the input value and return the type as a string.
186+
187+
Args:
188+
value (object): The input value.
189+
190+
Returns:
191+
str: The type of the input value as a string.
192+
Possible values are "int", "float", "str", "bool", or None.
193+
Checks for numpy types as well, i.e., np.integer, np.floating, np.str_, np.bool_.
194+
195+
Examples:
196+
>>> from spotPython.utils.convert import check_type
197+
>>> check_type(5)
198+
"int"
199+
200+
"""
201+
if isinstance(value, (int, np.integer)):
202+
return "int"
203+
elif isinstance(value, (float, np.floating)):
204+
return "float"
205+
elif isinstance(value, (str, np.str_)):
206+
return "str"
207+
elif isinstance(value, (bool, np.bool_)):
208+
return "bool"
209+
else:
210+
return None

0 commit comments

Comments
 (0)