pathwaycom/pathway · error · ValueError

If fmt is not a string, you need to specify whether objects

Error message

If fmt is not a string, you need to specify whether objects contain a timezone using `contains_timezone` parameter.

What it means

dt.strptime() needs to know whether parsed strings contain a timezone so it can pick the DateTimeUtc or DateTimeNaive engine function. When fmt is a string it infers this from %z/%:z/%Z directives; when fmt is something else (a list of formats, per pandas), inference is impossible, so Pathway requires the contains_timezone flag explicitly and raises this ValueError otherwise.

Source

Thrown at python/pathway/internals/expressions/date_time.py:641

        ...    3 | 2023-03-26T12:13:00-01:00
        ...    4 | 2023-05-15T14:13:23+00:30
        ... '''
        ... )
        >>> fmt = "%Y-%m-%dT%H:%M:%S%z"
        >>> table_with_datetime = table.select(t1=table.t1.dt.strptime(fmt=fmt))
        >>> pw.debug.compute_and_print(table_with_datetime, include_id=False)
        t1
        1970-02-03 12:13:00+00:00
        2023-03-25 10:13:00+00:00
        2023-03-26 13:13:00+00:00
        2023-05-15 13:43:23+00:00
        """

        if contains_timezone is None:
            if isinstance(fmt, str):
                contains_timezone = any(code in fmt for code in ["%z", "%:z", "%Z"])
            else:
                raise ValueError(
                    "If fmt is not a string, you need to specify whether objects"
                    + " contain a timezone using `contains_timezone` parameter."
                )

        if contains_timezone:
            fun = api.Expression.date_time_utc_strptime
            return_type: dt.DType = dt.DATE_TIME_UTC
        else:
            fun = api.Expression.date_time_naive_strptime
            return_type = dt.DATE_TIME_NAIVE

        return expr.MethodCallExpression(
            (((dt.STR, dt.STR), return_type, fun),),
            "dt.strptime",
            self._expression,
            fmt,
        )

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Add contains_timezone=True if the strings can include an offset (e.g. '+02:00', 'Z') or False if they are naive
  2. Prefer a single format string containing %z or %Z so Pathway can infer the timezone automatically
  3. If some rows have offsets and others don't, normalize the strings first (or split the stream) so contains_timezone is unambiguous

Example fix

// before
parsed = pw.this.raw.dt.strptime(fmt=['%Y-%m-%d %H:%M', '%d/%m/%Y %H:%M'])
// after
parsed = pw.this.raw.dt.strptime(
    fmt=['%Y-%m-%d %H:%M', '%d/%m/%Y %H:%M'],
    contains_timezone=False,
)
Defensive patterns

Strategy: validation

Validate before calling

def strptime_args_ready(fmt, contains_timezone) -> bool:
    return isinstance(fmt, str) or contains_timezone is not None

Type guard

def needs_timezone_flag(fmt) -> bool:
    return not isinstance(fmt, str)  # if True: must pass contains_timezone explicitly

Prevention

When it happens

Trigger: Calling pw.this.col.dt.strftime_parse with fmt=['%d-%m-%Y', '%Y/%m/%d %H:%M'] (a list) without contains_timezone; passing a compiled format or non-string object as fmt; passing fmt=None expecting ISO auto-parse.

Common situations: Heterogeneous input files where one format string is not enough; migrating pandas pd.to_datetime(format=[...]) code; formats stored as variables that end up being lists.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/b51ec398a69e96a8. Report an issue: GitHub.