deepcave.utils.compression

# Compression

This module provides utilities for serializing and deserializing a dataframe from/to a string.

## Classes
  • Encoder: This class defines a custom JSON Encoder.

## Constants
  • JSON_DENSE_SEPARATORS: Tuple(str, str)

  • JSON_DEFAULT_SEPARATORS: Tuple(str, str)

  • TYPE: TypeVar

Functions

deserialize(string[, dtype])

Deserialize a dataframe from a string.

serialize(data)

Serialize a dataframe to a string.

Classes

Encoder(*[, skipkeys, ensure_ascii, ...])

Define a custom JSON Encoder.

class deepcave.utils.compression.Encoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

Define a custom JSON Encoder.

default(obj)[source]

Return the object as list if np.ndarray.

Parameters:

obj (Any) – The object to be converted.

Returns:

The converted object.

Return type:

Any

deepcave.utils.compression.deserialize(string, dtype=<class 'pandas.core.frame.DataFrame'>)[source]

Deserialize a dataframe from a string.

Parameters:
  • string (str) – The string to be deserialized.

  • dtype (TYPE, optional) – The type of the object. Default is pd.DataFrame.

Returns:

The deserialized object.

Return type:

TYPE

deepcave.utils.compression.serialize(data)[source]

Serialize a dataframe to a string.

Parameters:

data (Union[Dict, List, pd.DataFrame]) – The dataframe to be serialized.

Returns:

The serialized object as a JSON formatted string.

Return type:

str