madgui.util.yaml module¶
Utilities for loading and writing YAML documents. We currently use YAML for config files, session data and various data exports.
The functions here are merely thin wrappers on top of the PyYAML API. They mainly add these features:
the
load
functions are order preserving, i.e. they return dicts that when iterated yield elements in the same order as written in the YAML documentthe
save
family of functions handle serialization ofOrderedDict
and several numpy number types that would otherwise raise an error.load_file()
andsave_file()
allow to directly provide a filename rather than having to pass a stream.the
save_file()
function ensures that an existing file at the same location will only be overwritten if the data can be serialized without error.save_file()
creates directories as needed
Functions
|
Load yaml document from filename. |
|
Load YAML document from stream, returns dictionaries in the written order within the YAML document. |
|
Saves YAML document to stream (or returns as string). |
Exceptions
|
|
|
-
exception
madgui.util.yaml.
ParserError
(context=None, context_mark=None, problem=None, problem_mark=None, note=None)[source]¶ Bases:
yaml.error.MarkedYAMLError
-
exception
madgui.util.yaml.
ScannerError
(context=None, context_mark=None, problem=None, problem_mark=None, note=None)[source]¶ Bases:
yaml.error.MarkedYAMLError
-
madgui.util.yaml.
safe_dump
(data, stream=None, Dumper=<class 'yaml.cyaml.CSafeDumper'>, **kwds)[source]¶ Saves YAML document to stream (or returns as string). This function takes care to correctly serialize
OrderedDict
, as well as several numpy number types, which would otherwise lead to errors.Note that it is easy to accidentally have some of these types in your data if not taking extreme care. For example, if you retrieve an array element fron numpy using
array[i]
, you will not get a python float or int, but a numpy specific datatype.