Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse string bool values in CmdStan csv header #2354

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match_str_bool(2) I believe should be matr_str_bool.group(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, because the results dictionary values are converted to strings the value False is read incorrectly as "False" when attempting to convert to an integer on line 807 of this PR int(pconf.get("save_warmup", 0))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, let's just turn these to int

results[key] = value == "true"
elif match_str:
key, value = match_str.group(1), match_str.group(2)
results[key] = value
Expand Down
Loading