{"record":{"id":"b51ec398a69e96a8","repo":"pathwaycom/pathway","slug":"if-fmt-is-not-a-string-you-need-to-specify-whethe","errorCode":null,"errorMessage":"If fmt is not a string, you need to specify whether objects contain a timezone using `contains_timezone` parameter.","messagePattern":"If fmt is not a string, you need to specify whether objects contain a timezone using `contains_timezone` parameter\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/expressions/date_time.py","lineNumber":641,"sourceCode":"        ...    3 | 2023-03-26T12:13:00-01:00\n        ...    4 | 2023-05-15T14:13:23+00:30\n        ... '''\n        ... )\n        >>> fmt = \"%Y-%m-%dT%H:%M:%S%z\"\n        >>> table_with_datetime = table.select(t1=table.t1.dt.strptime(fmt=fmt))\n        >>> pw.debug.compute_and_print(table_with_datetime, include_id=False)\n        t1\n        1970-02-03 12:13:00+00:00\n        2023-03-25 10:13:00+00:00\n        2023-03-26 13:13:00+00:00\n        2023-05-15 13:43:23+00:00\n        \"\"\"\n\n        if contains_timezone is None:\n            if isinstance(fmt, str):\n                contains_timezone = any(code in fmt for code in [\"%z\", \"%:z\", \"%Z\"])\n            else:\n                raise ValueError(\n                    \"If fmt is not a string, you need to specify whether objects\"\n                    + \" contain a timezone using `contains_timezone` parameter.\"\n                )\n\n        if contains_timezone:\n            fun = api.Expression.date_time_utc_strptime\n            return_type: dt.DType = dt.DATE_TIME_UTC\n        else:\n            fun = api.Expression.date_time_naive_strptime\n            return_type = dt.DATE_TIME_NAIVE\n\n        return expr.MethodCallExpression(\n            (((dt.STR, dt.STR), return_type, fun),),\n            \"dt.strptime\",\n            self._expression,\n            fmt,\n        )\n","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/expressions/date_time.py#L623-L659","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add contains_timezone=True if the strings can include an offset (e.g. '+02:00', 'Z') or False if they are naive","Prefer a single format string containing %z or %Z so Pathway can infer the timezone automatically","If some rows have offsets and others don't, normalize the strings first (or split the stream) so contains_timezone is unambiguous"],"exampleFix":"// before\nparsed = pw.this.raw.dt.strptime(fmt=['%Y-%m-%d %H:%M', '%d/%m/%Y %H:%M'])\n// after\nparsed = pw.this.raw.dt.strptime(\n    fmt=['%Y-%m-%d %H:%M', '%d/%m/%Y %H:%M'],\n    contains_timezone=False,\n)","handlingStrategy":"validation","validationCode":"def strptime_args_ready(fmt, contains_timezone) -> bool:\n    return isinstance(fmt, str) or contains_timezone is not None","typeGuard":"def needs_timezone_flag(fmt) -> bool:\n    return not isinstance(fmt, str)  # if True: must pass contains_timezone explicitly","tryCatchPattern":null,"preventionTips":["Always pass contains_timezone when fmt is a list or non-string","Prefer a single format string with %z/%Z so Pathway infers the timezone","Decide upfront whether source strings carry offsets and set the flag accordingly"],"tags":["pathway","datetime","strptime","timezone","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}