YAML Input & Output¶
API¶
Utilities for doing IO to YAML files.
-
urbansim.utils.yamlio.
convert_to_yaml
(cfg, str_or_buffer)[source]¶ Convert a dictionary to YAML and return the string or write it out depending on the type of str_or_buffer.
Parameters: cfg : dict
Dictionary to convert.
str_or_buffer : None, str, or buffer
If None: the YAML string will be returned. If string: YAML will be saved to a file. If buffer: YAML will be written to buffer using the
.write
method.Returns: str or None
YAML string if str_or_buffer is None, otherwise None since YAML is written out to a separate destination.
-
urbansim.utils.yamlio.
frame_to_yaml_safe
(frame)[source]¶ Convert a pandas DataFrame to a dictionary that will survive YAML serialization and re-conversion back to a DataFrame.
Parameters: frame : pandas.DataFrame Returns: safe : dict
-
urbansim.utils.yamlio.
ordered_yaml
(cfg)[source]¶ Convert a dictionary to a YAML string with preferential ordering for some keys. Converted string is meant to be fairly human readable.
Parameters: cfg : dict
Dictionary to convert to a YAML string.
Returns: str
Nicely formatted YAML string.
-
urbansim.utils.yamlio.
series_to_yaml_safe
(series)[source]¶ Convert a pandas Series to a dict that will survive YAML serialization and re-conversion back to a Series.
Parameters: series : pandas.Series Returns: safe : dict
-
urbansim.utils.yamlio.
to_scalar_safe
(obj)[source]¶ Convert a numpy data type to a standard python scalar.
-
urbansim.utils.yamlio.
yaml_to_dict
(yaml_str=None, str_or_buffer=None)[source]¶ Load YAML from a string, file, or buffer (an object with a .read method). Parameters are mutually exclusive.
Parameters: yaml_str : str, optional
A string of YAML.
str_or_buffer : str or file like, optional
File name or buffer from which to load YAML.
Returns: dict
Conversion from YAML.