docstr: Test decoding robustness against invalid magnitudes in datetime encodings.
docstr_tok: ["Test","decoding","robustness","against","invalid","magnitudes","in","datetime","encodings","."]
code: def test_cap_invalid_dates(self):
      """
      Test decoding robustness against invalid magnitudes in datetime encodings.
      """
      data = [self._create_timestamp() for _ in range(100)]
      limits = {
          "lower": {
              "month": 1,
              "day": 1,
              "hour": 0,
              "minute": 0,
              "second": 0,
              "corruption": -0.5,
          },
          "upper": {
              "month": 12,
              "day": 31,
              "hour": 23,
              "minute": 59,
              "second": 59,
              "corruption": 1.5,
          },
      }
      normalizer = DatetimeNormalizerEncoder()
      normalizer.prepare([])
  
      # change descriptor to invalid values in each dimension (out of 0-1 range)
      for limit in limits.values():
          for i, attr in zip(range(7), normalizer.fields):
              if attr in ("year", "weekday"):
                  continue
              else:
                  vector = normalizer.encode(data)
                  vector[:, :, i] = limit["corruption"]
                  recons = datetime.fromtimestamp(
                      normalizer.decode(vector)[0]
                  )
  
                  # decoding correctly caps the invalid vector component
                  self.assertEqual(getattr(recons, attr), limit[attr])
  
file_path: lightwood/tests/unit_tests/encoder/date/test_datetime.py
imports: import unittest
  from datetime import datetime
  import numpy
  import pandas
  import torch
  from lightwood.encoder.datetime.datetime import DatetimeEncoder
  from lightwood.encoder.datetime.datetime_sin_normalizer import DatetimeNormalizerEncoder
label_desc: Use image node_id 6 for calling the TestDatetimeEncoder obj's underlying member method code with example usage: obj.test_cap_invalid_dates() without return types