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

Notation like &id001 in saved yaml #125

Open
smmaurer opened this issue Apr 28, 2021 · 0 comments
Open

Notation like &id001 in saved yaml #125

smmaurer opened this issue Apr 28, 2021 · 0 comments

Comments

@smmaurer
Copy link
Member

Sometimes saved yaml files can include automatically generated notation like &id001:

saved_object:
    filters: &id001
    - rent_median_7 > 0
    - block_groups_mean_year_built > 0

What does this mean? Is it a problem? This issue was reported by @msoltadeo.

Diagnosis

This turns out to be a feature of the YAML spec called "anchors and aliases". When data (in this case a list of strings) is passed by name instead of value, and shows up in a YAML file multiple times, PyYAML automatically adds an identifier like &id001 in front of the first occurrence. In subsequent occurrences, only the corresponding alias appears:

    model:
        fit_filters: *id001

When the YAML file is read back into Python, the data is reconstructed like normal. My understanding is that this helps save space in YAML files, and can also help avoid potential recursion issues.

Resolution

If we want to, we can add a patch to urbansim_templates to disable this YAML feature. I am inclined to do this, since (a) it would make the yaml files a bit more human-readable, and (b) it might work more smoothly in case we need to read or modify the files using an interpreter that doesn't implement this aspect of the YAML spec.

Sample affected file: repm_rent7.yaml
Demonstration of patch: test.py

References

Discussion and workarounds:

YAML spec:

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