-
Notifications
You must be signed in to change notification settings - Fork 14
Description
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:
- https://stackoverflow.com/questions/18065427/
- https://stackoverflow.com/questions/51272814/
- https://stackoverflow.com/questions/13518819/
YAML spec: