pathwaycom/pathway · error · ValueError

string {freq} cannot be parsed as a duration

Error message

string {freq} cannot be parsed as a duration

What it means

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.

Source

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

# Copyright © 2026 Pathway


from warnings import warn

import pandas as pd

import pathway.internals.expression as expr
from pathway.internals import api, dtype as dt


def _str_as_duration(freq: str) -> pd.Timedelta:
    duration = pd.tseries.frequencies.to_offset(freq)
    if duration is None:
        raise ValueError(f"string {freq} cannot be parsed as a duration")
    return pd.Timedelta(duration.nanos)


class DateTimeNamespace:
    """A module containing methods related to DateTimes.
    They can be called using a `dt` attribute of an expression.

    Typical use:

    >>> import pathway as pw
    >>> table = pw.debug.table_from_markdown(
    ...     '''
    ...      |         t1
    ...    1 | 2023-05-15T14:13:00
    ... '''
    ... )
    >>> table_with_datetime = table.select(t1=table.t1.dt.strptime("%Y-%m-%dT%H:%M:%S"))
    >>> table_with_days = table_with_datetime.select(day=table_with_datetime.t1.dt.day())

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Use a valid pandas offset alias: 'min'/'T', 'h'/'H', 'D', 'W', 's', or multipliers like '90min', '1h30min'
  2. Strip and validate the string before passing: pd.tseries.frequencies.to_offset(freq) yourself and check it is not None
  3. If the frequency is calendar-aware (month/quarter), check the specific API — some Pathway helpers only accept fixed durations; convert to explicit durations otherwise

Example fix

// before
windows = table.window(frequency='half an hour')  # or a typo like 'hors'
// after
windows = table.window(frequency='30min')
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd

def valid_freq(freq: str) -> bool:
    try:
        return pd.tseries.frequencies.to_offset(freq.strip()) is not None
    except Exception:
        return False

assert valid_freq(FREQ), f"bad frequency: {FREQ!r}"

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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