Skip to content

Commit

Permalink
Parse string bool values in CmdStan csv header (#2354)
Browse files Browse the repository at this point in the history
* parse str bool values

* Revert bool to default int

* Fix re access

* Transform bool to int
  • Loading branch information
ahartikainen authored Jun 18, 2024
1 parent 3453abd commit 39eddd6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arviz/data/io_cmdstan.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ def _process_configuration(comments):
elif "=" in comment:
match_int = re.search(r"^(\S+)\s*=\s*([-+]?[0-9]+)$", comment)
match_float = re.search(r"^(\S+)\s*=\s*([-+]?[0-9]+\.[0-9]+)$", comment)
match_str_bool = re.search(r"^(\S+)\s*=\s*(true|false)$", comment)
match_str = re.search(r"^(\S+)\s*=\s*(\S+)$", comment)
match_empty = re.search(r"^(\S+)\s*=\s*$", comment)
if match_int:
Expand All @@ -746,6 +747,9 @@ def _process_configuration(comments):
elif match_float:
key, value = match_float.group(1), match_float.group(2)
results[key] = float(value)
elif match_str_bool:
key, value = match_str_bool.group(1), match_str_bool.group(2)
results[key] = int(value == "true")
elif match_str:
key, value = match_str.group(1), match_str.group(2)
results[key] = value
Expand Down

0 comments on commit 39eddd6

Please sign in to comment.