{"record":{"id":"a9bbd2bcb9f00184","repo":"apache/beam","slug":"cannot-interpret-s-s-as-subseconds","errorCode":null,"errorMessage":"Cannot interpret %s %s as subseconds.","messagePattern":"Cannot interpret (.+?) (.+?) as subseconds\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/timestamp.py","lineNumber":86,"sourceCode":"\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(\n            'micros and subseconds are mutually exclusive, got micros=%s, '\n            'subseconds=%s.' % (micros, subseconds))\n      if precision != Timestamp.MICROS_PRECISION:","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/timestamp.py#L68-L104","documentation":"Timestamp.__init__ also validates the subseconds argument: it must be an int or float. Passing any other type raises this TypeError. (Note the same class raises the analogous messages for seconds and precision.)","triggerScenarios":"Constructing Timestamp(seconds=..., subseconds=<non-numeric>) e.g. subseconds='5', subseconds=None, or a Decimal/str fraction passed through from user input or serialized data.","commonSituations":"String fractional seconds from JSON ('0.5') passed directly; Decimal values from financial data; None used as a default for subseconds; numpy str_ scalars.","solutions":["Cast the value: Timestamp(seconds=s, subseconds=float(sub)).","Parse numeric strings before passing.","Replace None with 0 (the default) when subseconds is absent.","Convert Decimal/np scalars via float()/item()."],"exampleFix":"# before\nTimestamp(seconds=10, subseconds='0.25')\n# after\nTimestamp(seconds=10, subseconds=float('0.25'))","handlingStrategy":"type-guard","validationCode":"def subseconds_or_zero(v):\n    return float(v) if isinstance(v, (int, float, str)) else 0.0\nTimestamp(seconds=s, subseconds=subseconds_or_zero(sub))","typeGuard":"def is_numeric_subseconds(v):\n    return v is None or isinstance(v, (int, float))","tryCatchPattern":"try:\n    ts = Timestamp(seconds=s, subseconds=sub)\nexcept TypeError as e:\n    if 'as subseconds' in str(e):\n        ts = Timestamp(seconds=s, subseconds=float(sub))\n    else:\n        raise","preventionTips":["Cast Decimal/str fractions with float() before passing","Use 0 (not None) for missing subseconds","Validate numeric fields when deserializing timestamp data","Add unit tests covering non-numeric subsecond inputs"],"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"}