class_docstr: Extends the functionality of dill to serialize arbitrary objects.
  
  Originally intended to serialize the anomaly detector class
  `~greykite.detection.anomaly_detector.AnomalyDetector`, but
  can be potentially used to serialize other objects.
  
  Outputs a dictionary that can be serialized by `json` or `yaml` libraries.
  The dictionary has a tree structure, where each node is either a
  serialized object, or a pair of type and directory of serialized objects.
  The base of the directory is called "ROOT".
  
  Usage
  -----
      # To serialize
      pickler = GreykitePickler()
      pickled = pickler.dumps(obj)
      pickled_json = json.dumps(pickled)
  
      # To deserialize
      pickled = json.loads(pickled_json)
      obj = pickler.loads(pickled)
  
  Attributes
  ----------
  obj: any
      The object to be serialized.
class_docstr_tok: ["Extends","the","functionality","of","dill","to","serialize","arbitrary","objects",".","Originally","intended","to","serialize","the","anomaly","detector","class","`","~greykite.detection.anomaly_detector.AnomalyDetector","`",",","but","can","be","potentially","used","to","serialize","other","objects",".","Outputs","a","dictionary","that","can","be","serialized","by","`","json","`","or","`","yaml","`","libraries",".","The","dictionary","has","a","tree","structure",",","where","each","node","is","either","a","serialized","object",",","or","a","pair","of","type","and","directory","of","serialized","objects",".","The","base","of","the","directory","is","called","``","ROOT","''",".","Usage","--","--","-","#","To","serialize","pickler","=","GreykitePickler","(",")","pickled","=","pickler.dumps","(","obj",")","pickled_json","=","json.dumps","(","pickled",")","#","To","deserialize","pickled","=","json.loads","(","pickled_json",")","obj","=","pickler.loads","(","pickled",")","Attributes","--","--","--","--","--","obj",":","any","The","object","to","be","serialized","."]
docstr: Serializes a list or a tuple, preserving its order, when it can not be directly pickled by `dill`.
  
  Generates a dictionary with two keys.
      - {`obj_name`}.type stores the object type.
      - {`obj_name`}.dir stores the elements/attributes of the object.
      To build the {`obj_name`}.dir dictionary, `dumps` method is called recursively.
  
      ```python
      {
          "{obj_name}.type": "serializable object type",
          "{obj_name}.dir": {
              "0__key__": "serialized value1",
              "1__key__": "serialized value2",
              ...
          }
      }
      ```
  
  Parameters
  ----------
  obj: `list` or `tuple`
      The list or tuple to be serialized.
  obj_name: `str`
      The name of the object to be serialized.
  
  Returns
  -------
  serialized: `dict`
      The serialized list or tuple.
docstr_tok: ["Serializes","a","list","or","a","tuple",",","preserving","its","order",",","when","it","can","not","be","directly","pickled","by","`","dill","`",".","Generates","a","dictionary","with","two","keys",".","-","{","`","obj_name","`","}",".type","stores","the","object","type",".","-","{","`","obj_name","`","}",".dir","stores","the","elements\/attributes","of","the","object",".","To","build","the","{","`","obj_name","`","}",".dir","dictionary",",","`","dumps","`","method","is","called","recursively",".","``","`","python","{","``","{","obj_name","}",".type","''",":","``","serializable","object","type","''",",","``","{","obj_name","}",".dir","''",":","{","``","0__key__","''",":","``","serialized","value1","''",",","``","1__key__","''",":","``","serialized","value2","''",",","...","}","}","``","`","Parameters","--","--","--","--","--","obj",":","`","list","`","or","`","tuple","`","The","list","or","tuple","to","be","serialized",".","obj_name",":","`","str","`","The","name","of","the","object","to","be","serialized",".","Returns","--","--","--","-","serialized",":","`","dict","`","The","serialized","list","or","tuple","."]
code: def _serialize_list_tuple(self, obj, obj_name):
      """Serializes a list or a tuple, preserving its order, when it can not be directly pickled by `dill`.
  
      Generates a dictionary with two keys.
          - {`obj_name`}.type stores the object type.
          - {`obj_name`}.dir stores the elements/attributes of the object.
          To build the {`obj_name`}.dir dictionary, `dumps` method is called recursively.
  
          ```python
          {
              "{obj_name}.type": "serializable object type",
              "{obj_name}.dir": {
                  "0__key__": "serialized value1",
                  "1__key__": "serialized value2",
                  ...
              }
          }
          ```
  
      Parameters
      ----------
      obj: `list` or `tuple`
          The list or tuple to be serialized.
      obj_name: `str`
          The name of the object to be serialized.
  
      Returns
      -------
      serialized: `dict`
          The serialized list or tuple.
      """
      # Dumps the type in .type dictionary
      serialized = {
          f"{obj_name}{TYPE_KEY_EXTENSION}": self.dumps_to_str(
              type(obj).__name__
          )
      }
  
      # Dumps the keys and values in .dir dictionary
      result = {}
      for i, value in enumerate(obj):
          result.update(
              self.dumps(obj=value, obj_name=f"{i}{KEY_SUFFIX}")
          )
      serialized[f"{obj_name}{DIRECTORY_KEY_EXTENSION}"] = result
  
      return serialized
  
file_path: greykite/greykite/detection/common/pickler.py
imports: import codecs
  import inspect
  from collections import OrderedDict
  import dill
label_desc: Use image node_id 6 for calling the GreykitePickler obj's underlying member method code with example usage: obj._serialize_list_tuple(obj, obj_name) and returns: serialized