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","."]
code: def decode(
      self, encoded_data: torch.Tensor, return_as_datetime=False
  ) -> list:
      if len(encoded_data.shape) > 2 and encoded_data.shape[0] == 1:
          encoded_data = encoded_data.squeeze(0)
  
      rounded = torch.round(
          torch.multiply(encoded_data, self.constant_vals)
      )
      high_bounded = torch.minimum(rounded, self.max_vals)
      low_bounded = torch.maximum(high_bounded, self.min_vals)
      ret = low_bounded.long()
  
      df = pd.DataFrame(ret, columns=self.constant_keys)
      nan_mask = df[
          (df["year"] == int(self.max_vals[0]))
          & (df["month"] == pd.Timestamp.max.month)
          & (df["day"] == pd.Timestamp.max.day)
      ].index
      dt = pd.to_datetime(df, utc=True)
  
      if not hasattr(dt, "dt"):
          log.warning(
              "DatetimeEncoder has failed to decode using microsecond precision, reverting to nanosecond. This may lead to minor discrepancies in reconstruction."
          )  # noqa
  
      if return_as_datetime is True:
          dt = (
              dt.dt.to_pydatetime()
          )  # return to Python datetime microsecond precision
          decoded = dt
      else:
          decoded = dt.values.astype(np.float64) // 10**9
  
      decoded[nan_mask] = np.nan
      return decoded.tolist()
  
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 4 for calling the DatetimeEncoder obj's underlying member method code with example usage: obj.decode(encoded_data, return_as_datetime) and returns: decoded