apache/beam · error · TypeError

Cannot interpret as Timestamp.

Error message

Cannot interpret %s %s as Timestamp.

What it means

Timestamp.of() accepts a Timestamp, int/float seconds, or a datetime.datetime; anything else (string, None, Decimal, etc.) raises this TypeError. It is the coercion entry point, so it reports the value and its type to make the bad input obvious.

Solutions

  1. Parse strings first: Timestamp.of_rfc3339(s) or Timestamp.from_rfc3339(s)
  2. Convert to int/float seconds or datetime.datetime before calling
  3. Check for None and supply a default Timestamp.now() or skip the record

Example fix

// before
Timestamp.of(row['event_time'])  # str
// after
ts = Timestamp.of_rfc3339(row['event_time'])
Defensive patterns

Strategy: type-guard

Validate before calling

if value is None:
    raise ValueError('event time missing')
if isinstance(value, str):
    value = Timestamp.from_rfc3339(value)

Type guard

def is_timestamp_coercible(v) -> bool:
    return isinstance(v, (Timestamp, int, float, datetime.datetime))

Try / catch

try:
    ts = Timestamp.of(value)
except TypeError:
    ts = Timestamp.of_rfc3339(str(value))

Prevention

When it happens

Trigger: Timestamp.of('2024-01-01T00:00:00Z') — strings are NOT parsed; Timestamp.of(None) from an upstream missing value; Timestamp.of(decimal.Decimal(1.5)).

Common situations: Assuming Timestamp.of parses RFC 3339 strings (use of_rfc3339/from_rfc3339 instead); passing Optional values straight from a dict/protobuf without a None check; handing in numpy types in edge cases.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/760921c59bdae787. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/utils/timestamp.py:143

    """Return the Timestamp for the given number of seconds.

    If the input is already a Timestamp, the input itself will be returned.

    Args:
      seconds: Number of seconds as int, float, long, or Timestamp.

    Returns:
      Corresponding Timestamp object.
    """

    if isinstance(seconds, Timestamp):
      return seconds
    elif isinstance(seconds, (int, float)):
      return Timestamp(seconds)
    elif isinstance(seconds, datetime.datetime):
      return Timestamp.from_utc_datetime(seconds)
    else:
      raise TypeError(
          'Cannot interpret %s %s as Timestamp.' % (seconds, type(seconds)))

  @staticmethod
  def now() -> 'Timestamp':
    return Timestamp(seconds=time.time())

  @staticmethod
  def _epoch_datetime_utc() -> datetime.datetime:
    return datetime.datetime.fromtimestamp(0, pytz.utc)

  @classmethod
  def from_utc_datetime(cls, dt: datetime.datetime) -> 'Timestamp':
    """Create a ``Timestamp`` instance from a ``datetime.datetime`` object.

    Args:
      dt: A ``datetime.datetime`` object in UTC (offset-aware).
    """
    if dt.tzinfo is None:

View on GitHub (pinned to 12126d8942)