{"record":{"id":"2ed9e1f83ebcc1f6","repo":"pathwaycom/pathway","slug":"string-freq-cannot-be-parsed-as-a-duration","errorCode":null,"errorMessage":"string {freq} cannot be parsed as a duration","messagePattern":"string (.+?) cannot be parsed as a duration","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/expressions/date_time.py","lineNumber":15,"sourceCode":"# Copyright © 2026 Pathway\n\n\nfrom warnings import warn\n\nimport pandas as pd\n\nimport pathway.internals.expression as expr\nfrom pathway.internals import api, dtype as dt\n\n\ndef _str_as_duration(freq: str) -> pd.Timedelta:\n    duration = pd.tseries.frequencies.to_offset(freq)\n    if duration is None:\n        raise ValueError(f\"string {freq} cannot be parsed as a duration\")\n    return pd.Timedelta(duration.nanos)\n\n\nclass DateTimeNamespace:\n    \"\"\"A module containing methods related to DateTimes.\n    They can be called using a `dt` attribute of an expression.\n\n    Typical use:\n\n    >>> import pathway as pw\n    >>> table = pw.debug.table_from_markdown(\n    ...     '''\n    ...      |         t1\n    ...    1 | 2023-05-15T14:13:00\n    ... '''\n    ... )\n    >>> table_with_datetime = table.select(t1=table.t1.dt.strptime(\"%Y-%m-%dT%H:%M:%S\"))\n    >>> table_with_days = table_with_datetime.select(day=table_with_datetime.t1.dt.day())","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/expressions/date_time.py#L1-L33","documentation":"Several datetime helpers (e.g. windows/resampling by frequency) convert a pandas-style frequency string into a pd.Timedelta via pandas' to_offset. If pandas cannot interpret the string as an offset alias at all, to_offset returns None and Pathway raises this ValueError telling you the freq string is not parseable as a duration.","triggerScenarios":"Passing a malformed or non-duration pandas offset alias such as ' fortnight', '2xh', 'ABC', an empty string, or a frequency that denotes a period anchored in calendar time that pandas rejects; also typos like 'da' instead of 'D', or trailing whitespace.","commonSituations":"Config-driven pipeline where the frequency comes from a config file/env var with a typo; switching from pandas resample and reusing an alias pandas only accepts in specific cases; locale/CRLF artifacts in copied strings.","solutions":["Use a valid pandas offset alias: 'min'/'T', 'h'/'H', 'D', 'W', 's', or multipliers like '90min', '1h30min'","Strip and validate the string before passing: pd.tseries.frequencies.to_offset(freq) yourself and check it is not None","If the frequency is calendar-aware (month/quarter), check the specific API — some Pathway helpers only accept fixed durations; convert to explicit durations otherwise"],"exampleFix":"// before\nwindows = table.window(frequency='half an hour')  # or a typo like 'hors'\n// after\nwindows = table.window(frequency='30min')","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef valid_freq(freq: str) -> bool:\n    try:\n        return pd.tseries.frequencies.to_offset(freq.strip()) is not None\n    except Exception:\n        return False\n\nassert valid_freq(FREQ), f\"bad frequency: {FREQ!r}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use standard pandas offset aliases: 'min', 'h', 'D', 'W', '30min', '1h30min'","Validate frequency strings from config with pd.tseries.frequencies.to_offset before use","Strip whitespace and reject empty strings at the config boundary"],"tags":["pathway","datetime","frequency","pandas","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}