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

Inconsistent conversion from string to int #61

Open
dd2912 opened this issue Oct 19, 2024 · 0 comments
Open

Inconsistent conversion from string to int #61

dd2912 opened this issue Oct 19, 2024 · 0 comments

Comments

@dd2912
Copy link

dd2912 commented Oct 19, 2024

Bug Report: Inconsistent Handling of string values in merge_from_file()

Description:
I encountered an issue when using merge_from_file() with a YAML configuration where the key seq: stores a sequence subfolder name as strings ("00", "01", "02", ..., "10", "11", etc.).

  • Expected behavior: When seq: '03' is specified in the YAML file, the merge works without issues.
  • Issue: However, when seq: '10' is used, I receive a ValueError indicating a type mismatch between str and int.

Error Message:

Traceback (most recent call last):
  File "[PATH]/yac/main.py", line 5, in <module>
    cfg.merge_from_file("experiment.yaml")
  File "[PATH]/python3.12/site-packages/yacs/config.py", line 213, in merge_from_file
    self.merge_from_other_cfg(cfg)
  File "[PATH]/python3.12/site-packages/yacs/config.py", line 217, in merge_from_other_cfg
    _merge_a_into_b(cfg_other, self, self, [])
  File "[PATH]/python3.12/site-packages/yacs/config.py", line 474, in _merge_a_into_b
    v = _check_and_coerce_cfg_value_type(v, b[k], k, full_key)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[PATH]/python3.12/site-packages/yacs/config.py", line 534, in _check_and_coerce_cfg_value_type
    raise ValueError(
ValueError: Type mismatch (<class 'str'> vs. <class 'int'>) with values (01 vs. 10) for config key: seq

Example Code:

Here’s a simplified version of the code demonstrating the issue:

config.py

from yacs.config import CfgNode as cn
_cn = cn()
_cn.seq = "01"

def get_cfg():
    return _cn.clone()

main.py

from config import get_cfg

if __name__ == "__main__":
    cfg = get_cfg()
    cfg.merge_from_file("experiment.yaml")
    cfg.freeze()
    print(cfg)

YAML File: working

seq: '03'

YAML File: with error

seq: '10'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant