timor.utilities.json_serialization_formatting

Functions

compress_json_vectors(content)

Compresses json vectors and matrices, s.t. innermost on single line

numpy2list(d)

Converts all numpy arrays in a dictionary to lists and returns the according copy

possibly_nest_as_list(value[, tuple_ok])

A utility to wrap a value within a list if it is not already.

Module Contents

timor.utilities.json_serialization_formatting.compress_json_vectors(content)

Compresses json vectors and matrices, s.t. innermost on single line

Parameters:

content (str)

Return type:

str

timor.utilities.json_serialization_formatting.numpy2list(d)

Converts all numpy arrays in a dictionary to lists and returns the according copy

Parameters:

d (Dict[any, any])

Return type:

Dict[any, any]

timor.utilities.json_serialization_formatting.possibly_nest_as_list(value, tuple_ok=True)

A utility to wrap a value within a list if it is not already.

Useful for loading jsons where arrays sometimes get unpacked if they contain only one element - which silently causes errors later in the pipeline.

Parameters:
  • value (any) – Basically any python variable

  • tuple_ok (bool) – If true, tuples will not be packed as a list as their behavior in python is very similar.

Returns:

[value] if value was not a list (or possibly a tuple) before, else value