pg_utils.numerics.io.CompactArrayJSONEncoder
- class pg_utils.numerics.io.CompactArrayJSONEncoder(*args, **kwargs)[source]
Bases:
JSONEncoder
A Json encoder that puts long arrays on one line
This encoder is adopted from the encoder written by Jannismain for compressing small containers on single lines.
Methods
__init__
(*args, **kwargs)default
(o)Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).encode
(o)Encode JSON
iterencode
(o[, _one_shot])Encode the given object and yield each string representation as available.
Attributes
CONTAINER_TYPES
SINGLELINE_THRESHOLD
indent_str
item_separator
key_separator
- default(o)[source]
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)