Skip to content

Commit f032628

Browse files
authored
Serialize string to bool (geopython#1876)
* Serialize string to bool * Update per feedback
1 parent 21d8ce9 commit f032628

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pygeoapi/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def dategetter(date_property: str, collection: dict) -> str:
134134
return value.isoformat()
135135

136136

137-
def get_typed_value(value: str) -> Union[float, int, str]:
137+
def get_typed_value(value: str) -> Union[bool, float, int, str]:
138138
"""
139139
Derive true type from data value
140140
@@ -148,6 +148,8 @@ def get_typed_value(value: str) -> Union[float, int, str]:
148148
value2 = float(value)
149149
elif len(value) > 1 and value.startswith('0'):
150150
value2 = value
151+
elif value.lower() in ['true', 'false']:
152+
value2 = str2bool(value)
151153
else: # int?
152154
value2 = int(value)
153155
except ValueError: # string (default)?

tests/test_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def test_get_typed_value():
7272
value = util.get_typed_value('1.c2')
7373
assert isinstance(value, str)
7474

75+
value = util.get_typed_value('true')
76+
assert isinstance(value, bool)
77+
78+
value = util.get_typed_value('false')
79+
assert isinstance(value, bool)
80+
7581

7682
def test_yaml_load(config):
7783
assert isinstance(config, dict)

0 commit comments

Comments
 (0)