pathwaycom/pathway · error · ValueError
statistical.diff(): Invalid column reference for the paramet
Error message
statistical.diff(): Invalid column reference for the parameter timestamp, found a string. Did you mean this.{timestamp} instead of {repr(timestamp)}? What it means
statistical.diff() computes the difference of each value column with respect to the previous row, ordered by a timestamp column. The timestamp parameter must be a pw.ColumnReference (or something resolvable through self[...]); passing a bare Python string is almost always the mistake of giving a column name instead of the column itself, so the method raises this ValueError and the message explicitly suggests the this.<name> reference form.
Source
Thrown at python/pathway/stdlib/ordered/diff.py:89
... 6 | 0 | 16
... '''
... )
>>> table += table.diff(pw.this.timestamp, pw.this.values, instance=pw.this.instance)
>>> pw.debug.compute_and_print(table, include_id=False)
timestamp | instance | values | diff_values
1 | 0 | 1 |
2 | 1 | 2 |
3 | 0 | 7 | 6
3 | 1 | 4 | 2
6 | 0 | 16 | 9
6 | 1 | 11 | 7
"""
if isinstance(timestamp, pw.ColumnReference):
timestamp = self[timestamp]
else:
if isinstance(timestamp, str):
raise ValueError(
"statistical.diff(): Invalid column reference for the parameter timestamp,"
+ f" found a string. Did you mean this.{timestamp} instead of {repr(timestamp)}?"
)
raise ValueError(
"statistical.diff(): Invalid column reference for the parameter timestamp."
)
ordered_table = self.sort(key=timestamp, instance=instance)
for value in values:
if isinstance(value, pw.ColumnReference):
value = self[value]
else:
if isinstance(value, str):
raise ValueError(
"statistical.diff(): Invalid column reference for the parameter value,"
+ f" found a string. Did you mean this.{value} instead of {repr(value)}?"
)View on GitHub (pinned to fa2f74a464)
Solutions
- Pass a column reference: timestamp=pw.this.ts (or table.ts).
- If building calls dynamically from names, resolve the reference first: timestamp=getattr(pw.this, name).
Example fix
# before t.statistical.diff(timestamp="ts", values=[pw.this.val]) # after t.statistical.diff(timestamp=pw.this.ts, values=[pw.this.val])
Defensive patterns
Strategy: type-guard
Type guard
import pathway as pw
def as_column_reference(table, timestamp):
if isinstance(timestamp, str):
return table[timestamp] # or getattr(pw.this, timestamp)
if isinstance(timestamp, pw.ColumnReference):
return timestamp
raise TypeError("timestamp must be a pw.ColumnReference") Try / catch
try:
t.statistical.diff(timestamp=ts, values=[pw.this.v])
except ValueError as e:
if "found a string" in str(e):
t.statistical.diff(timestamp=pw.this[ts], values=[pw.this.v])
else:
raise Prevention
- Always pass pw.this.col references, not names, to Pathway APIs that take ColumnReference parameters.
- When generating calls from schema metadata, resolve names to references with getattr(pw.this, name) at the call boundary.
When it happens
Trigger: Calling table.statistical.diff(timestamp="ts", values=[...]) — i.e. a string column name — instead of timestamp=pw.this.ts. Any str value hits the string-specific branch with the did-you-mean hint; other invalid types raise the generic variant.
Common situations: Habit from pandas/Spark APIs where column names are passed as strings; dynamic code building kwargs from schema column-name lists; refactoring from methods that accept both names and references.
Related errors
- Table.__getitem__ argument has to be a ColumnReference to th
- primary_key column {primary_key._name!r} does not belong to
- vector column {vector._name!r} does not belong to the provid
- parameters `schema` and `id_from` are mutually exclusive
- invalid ssl mode '{ssl_mode}', expected one of disable, allo
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/02148ce77be20bcc.
Report an issue: GitHub.