{"record":{"id":"7aa29791b9538865","repo":"apache/beam","slug":"cannot-interpret-s-s-as-seconds","errorCode":null,"errorMessage":"Cannot interpret %s %s as seconds.","messagePattern":"Cannot interpret (.+?) (.+?) as seconds\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/timestamp.py","lineNumber":83,"sourceCode":"  nanos). Defaults to microseconds.\n  If ``seconds`` is a float, the fractional part will be captured up\n  to ``precision`` digits.\n\n  Lossy conversion operations will throw an error unless\n  ``allow_lossy_conversion=True`` is specified (e.g. see ``to_utc_datetime``).\n  \"\"\"\n  MICROS_PRECISION = 6\n  NANOS_PRECISION = 9\n\n  def __init__(\n      self,\n      seconds: Union[int, float] = 0,\n      subseconds: Union[int, float] = 0,\n      precision: int = MICROS_PRECISION,\n      *,\n      micros: Optional[Union[int, float]] = None) -> None:\n    if not isinstance(seconds, (int, float)):\n      raise TypeError(\n          'Cannot interpret %s %s as seconds.' % (seconds, type(seconds)))\n    if not isinstance(subseconds, (int, float)):\n      raise TypeError(\n          'Cannot interpret %s %s as subseconds.' %\n          (subseconds, type(subseconds)))\n    if not isinstance(precision, int):\n      raise TypeError(\n          'Cannot interpret %s %s as precision.' % (precision, type(precision)))\n    if not 0 <= precision <= Timestamp.NANOS_PRECISION:\n      raise ValueError(\n          'Timestamp precision must be between 0 and %d (inclusive), '\n          'but was %d.' % (Timestamp.NANOS_PRECISION, precision))\n    if micros is not None:\n      if not isinstance(micros, (int, float)):\n        raise TypeError(\n            'Cannot interpret %s %s as micros.' % (micros, type(micros)))\n      if subseconds:\n        raise ValueError(","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/timestamp.py#L65-L101","documentation":"Timestamp.__init__ validates that the seconds argument is an int or float before converting to microseconds; anything else (str, Decimal, datetime, None) raises this TypeError. Beam's Timestamp intentionally does not coerce arbitrary types to avoid silent precision/semantic bugs.","triggerScenarios":"Constructing Timestamp(seconds=<non-numeric>) e.g. Timestamp('123'), Timestamp(datetime.now()), Timestamp(None), or passing a pandas/numpy non-int-float scalar into an API that builds a Timestamp from seconds.","commonSituations":"Feeding a timestamp string parsed from JSON/CSV directly into Timestamp; passing datetime objects instead of converting with Timestamp.from_utc_datetime(); numpy types (np.float32 usually fine via float, but object/Decimal dtypes are not).","solutions":["Convert to float/int first: Timestamp(float(s)).","Use Timestamp.from_utc_datetime(dt) for datetime objects.","Parse string timestamps with datetime.fromisoformat()/strptime, then convert.","Cast numpy scalars with .item() or float() before constructing."],"exampleFix":"# before\nTimestamp('1699999999.5')\n# after\nTimestamp(float('1699999999.5'))\n# or for datetime:\nTimestamp.from_utc_datetime(datetime.datetime.utcnow())","handlingStrategy":"type-guard","validationCode":"def as_timestamp(v):\n    if isinstance(v, datetime.datetime):\n        return Timestamp.from_utc_datetime(v)\n    if isinstance(v, str):\n        return Timestamp(float(v))\n    if not isinstance(v, (int, float)):\n        raise TypeError(f'non-numeric timestamp {v!r}')\n    return Timestamp(v)","typeGuard":"def is_timestamp_input(v):\n    return isinstance(v, (int, float)) and not isinstance(v, bool)","tryCatchPattern":"try:\n    ts = Timestamp(seconds=v)\nexcept TypeError as e:\n    if 'as seconds' in str(e):\n        ts = Timestamp(float(v))\n    else:\n        raise","preventionTips":["Convert datetime objects with Timestamp.from_utc_datetime","Cast strings/numpy scalars to float before constructing Timestamps","Validate input types at data-ingestion boundaries","Never pass None where seconds is required"],"tags":["python","type-mismatch","timestamp","apache-beam"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}