class_docstr: This encoder produces an encoded representation for timestamps.
  
  The approach consists on decomposing the timestamp objects into its constituent units (e.g. month, year, etc), and describing each of those with a single value that represents the magnitude in a sensible cycle length.
class_docstr_tok: ["This","encoder","produces","an","encoded","representation","for","timestamps",".","The","approach","consists","on","decomposing","the","timestamp","objects","into","its","constituent","units","(","e.g",".","month",",","year",",","etc",")",",","and","describing","each","of","those","with","a","single","value","that","represents","the","magnitude","in","a","sensible","cycle","length","."]
docstr: :param data: a pandas series with numerical dtype, previously cleaned with dataprep_ml
  :return: encoded data, shape (len(data), self.output_size)
docstr_tok: [":","param","data",":","a","pandas","series","with","numerical","dtype",",","previously","cleaned","with","dataprep_ml",":","return",":","encoded","data",",","shape","(","len","(","data",")",",","self.output_size",")"]
code: def encode(self, data: Union[np.ndarray, pd.Series]) -> torch.Tensor:
      """
      :param data: a pandas series with numerical dtype, previously cleaned with dataprep_ml
      :return: encoded data, shape (len(data), self.output_size)
      """
      if type(data) not in (np.ndarray, pd.Series):
          raise Exception(
              f"Data should be pd.Series or np.ndarray! Got: {type(data)}"
          )
      if isinstance(data, np.ndarray):
          data = pd.Series(data)
  
      data = data.fillna(
          pd.Timestamp.max.timestamp()
      )  # TODO: replace with mean?
      ret = [pd.to_datetime(data, unit="s", origin=-1, utc=True)]
      for i, attr in enumerate(self.constant_keys):
  
          def _get_ts_attr(ts):
              return getattr(ts, attr)
  
          component = ret[0].apply(_get_ts_attr)
          component = component / self.constant_vals[i].item()
          ret.append(component)
  
      out = torch.Tensor(ret[1:])  # drop column with timestamp objects
      out = torch.transpose(
          out, 0, 1
      )  # swap dimensions to shape as (B, self.output_size)
      return out
  
file_path: lightwood/lightwood/encoder/datetime/datetime.py
imports: from typing import Union
  import torch
  import numpy
  import pandas
  from lightwood.encoder.base import BaseEncoder
  from lightwood.helpers.log import log
label_desc: Use image node_id 3 for calling the DatetimeEncoder obj's underlying member method code with example usage: obj.encode(data) and returns: out, getattr