{"record":{"id":"02148ce77be20bcc","repo":"pathwaycom/pathway","slug":"statistical-diff-invalid-column-reference-for-t","errorCode":null,"errorMessage":"statistical.diff(): Invalid column reference for the parameter timestamp, found a string. Did you mean this.{timestamp} instead of {repr(timestamp)}?","messagePattern":"statistical\\.diff\\(\\): Invalid column reference for the parameter timestamp, found a string\\. Did you mean this\\.(.+?) instead of (.+?)\\?","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/stdlib/ordered/diff.py","lineNumber":89,"sourceCode":"    ... 6         | 0        | 16\n    ... '''\n    ... )\n    >>> table += table.diff(pw.this.timestamp, pw.this.values, instance=pw.this.instance)\n    >>> pw.debug.compute_and_print(table, include_id=False)\n    timestamp | instance | values | diff_values\n    1         | 0        | 1      |\n    2         | 1        | 2      |\n    3         | 0        | 7      | 6\n    3         | 1        | 4      | 2\n    6         | 0        | 16     | 9\n    6         | 1        | 11     | 7\n    \"\"\"\n\n    if isinstance(timestamp, pw.ColumnReference):\n        timestamp = self[timestamp]\n    else:\n        if isinstance(timestamp, str):\n            raise ValueError(\n                \"statistical.diff(): Invalid column reference for the parameter timestamp,\"\n                + f\" found a string. Did you mean this.{timestamp} instead of {repr(timestamp)}?\"\n            )\n        raise ValueError(\n            \"statistical.diff(): Invalid column reference for the parameter timestamp.\"\n        )\n\n    ordered_table = self.sort(key=timestamp, instance=instance)\n\n    for value in values:\n        if isinstance(value, pw.ColumnReference):\n            value = self[value]\n        else:\n            if isinstance(value, str):\n                raise ValueError(\n                    \"statistical.diff(): Invalid column reference for the parameter value,\"\n                    + f\" found a string. Did you mean this.{value} instead of {repr(value)}?\"\n                )","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/stdlib/ordered/diff.py#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before\nt.statistical.diff(timestamp=\"ts\", values=[pw.this.val])\n\n# after\nt.statistical.diff(timestamp=pw.this.ts, values=[pw.this.val])","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"import pathway as pw\n\ndef as_column_reference(table, timestamp):\n    if isinstance(timestamp, str):\n        return table[timestamp]  # or getattr(pw.this, timestamp)\n    if isinstance(timestamp, pw.ColumnReference):\n        return timestamp\n    raise TypeError(\"timestamp must be a pw.ColumnReference\")","tryCatchPattern":"try:\n    t.statistical.diff(timestamp=ts, values=[pw.this.v])\nexcept ValueError as e:\n    if \"found a string\" in str(e):\n        t.statistical.diff(timestamp=pw.this[ts], values=[pw.this.v])\n    else:\n        raise","preventionTips":["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."],"tags":["pathway","statistical","diff","column-reference","api-misuse"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}