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: Pickles a class 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": {
              "{key1}": "serialized value corresponding to key1",
              "{key2}": "serialized value corresponding to key2",
              ...
          }
      }
      ```
      Unlike `dict` and `OrderedDict`, the keys of the class attributes does not need to be
      serialized, as these are simple strings.
  
  Parameters
  ----------
  obj: `class`
      The class to be serialized.
  obj_name: `str`
      The name of the object to be serialized.
  
  Returns
  -------
  serialized: `dict`
      The serialized calss.
docstr_tok: ["Pickles","a","class","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","''",":","{","``","{","key1","}","''",":","``","serialized","value","corresponding","to","key1","''",",","``","{","key2","}","''",":","``","serialized","value","corresponding","to","key2","''",",","...","}","}","``","`","Unlike","`","dict","`","and","`","OrderedDict","`",",","the","keys","of","the","class","attributes","does","not","need","to","be","serialized",",","as","these","are","simple","strings",".","Parameters","--","--","--","--","--","obj",":","`","class","`","The","class","to","be","serialized",".","obj_name",":","`","str","`","The","name","of","the","object","to","be","serialized",".","Returns","--","--","--","-","serialized",":","`","dict","`","The","serialized","calss","."]
code: def _serialize_class(self, obj, obj_name):
      """Pickles a class 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": {
                  "{key1}": "serialized value corresponding to key1",
                  "{key2}": "serialized value corresponding to key2",
                  ...
              }
          }
          ```
          Unlike `dict` and `OrderedDict`, the keys of the class attributes does not need to be
          serialized, as these are simple strings.
  
      Parameters
      ----------
      obj: `class`
          The class to be serialized.
      obj_name: `str`
          The name of the object to be serialized.
  
      Returns
      -------
      serialized: `dict`
          The serialized calss.
      """
      # Dumps the type in .type key
      serialized = dict()
      serialized[f"{obj_name}{TYPE_KEY_EXTENSION}"] = self.dumps_to_str(
          obj.__class__
      )
  
      # Initiates the .dir dictionary
      serialized[f"{obj_name}{DIRECTORY_KEY_EXTENSION}"] = {}
      # Dumps the class attributes in .dir key
      for key, value in obj.__dict__.items():
          serialized[f"{obj_name}{DIRECTORY_KEY_EXTENSION}"].update(
              self.dumps(obj=value, obj_name=key)
          )
  
      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 7 for calling the GreykitePickler obj's underlying member method code with example usage: obj._serialize_class(obj, obj_name) and returns: serialized