YamlDumper#

class tollan.utils.yaml.YamlDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]#

Bases: SafeDumper

YAML dumper with support for astronomy types and common scientific objects.

This dumper extends PyYAML’s SafeDumper to handle:

  • Astropy Time objects (serialized as ISO-8601 strings)

  • Astropy Quantity objects (serialized as strings with units, only scalar supported)

  • Coordinate frames (serialized as frame names)

  • Path-like objects (serialized as strings)

  • Enums (serialized as strings)

  • NumPy numeric types (as native Python types)

  • Dataclasses (serialized as dicts)

Raises:

ValueError – If a non-scalar Quantity or Time is encountered.

Attributes Summary

Methods Summary

ignore_aliases(data)

Avoid generating YAML aliases (anchors).

represent_data(data)

Represent data for YAML serialization, handling astronomy and scientific types.

represent_scalar(tag, value[, style])

Represent a scalar value, using block style for long or multiline strings.

Attributes Documentation

yaml_multi_representers = {<class 'astropy.time.core.Time'>: <function _scalar_astropy_time_representer>, <class 'astropy.units.quantity.Quantity'>: <function _scalar_quantity_representer>, <class 'pathlib._local.Path'>: <function _path_representer>, <enum 'Enum'>: <function _enum_representer>}#
yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'numpy.bool'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.float16'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.float32'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.float64'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.int16'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.int32'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.int64'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.int8'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.longdouble'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.str_'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.uint16'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.uint32'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.uint64'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'numpy.uint8'>: <function add_numpy_scalar_representers.<locals>.<lambda>>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'tuple'>: <function SafeRepresenter.represent_list>, None: <function SafeRepresenter.represent_undefined>}#

Methods Documentation

ignore_aliases(data: object) bool[source]#

Avoid generating YAML aliases (anchors).

Parameters:

data (object) – The data object (unused)

Returns:

Always True

Return type:

bool

represent_data(data: object) Node[source]#

Represent data for YAML serialization, handling astronomy and scientific types.

Parameters:

data (object) – The data to represent.

Returns:

YAML node representation.

Return type:

Node

represent_scalar(tag: str, value: str, style: str | None = None) ScalarNode[source]#

Represent a scalar value, using block style for long or multiline strings.

Parameters:
  • tag (str) – YAML tag.

  • value (str) – Scalar value.

  • style (str, optional) – YAML style indicator. If None, block style is used for long/multiline strings.

Returns:

Scalar node for YAML output.

Return type:

ScalarNode