{"record":{"id":"81c94275d03a35b1","repo":"pathwaycom/pathway","slug":"cannot-flatten-column-of-type-dtype","errorCode":null,"errorMessage":"Cannot flatten column of type {dtype}.","messagePattern":"Cannot flatten column of type (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/column.py","lineNumber":1085,"sourceCode":"            return dtype.wrapped\n        if isinstance(dtype, dt.Tuple):\n            if dtype in (dt.ANY_TUPLE, dt.Tuple()):\n                return dt.ANY\n            assert not isinstance(dtype.args, EllipsisType)\n            return_dtype = dtype.args[0]\n            for single_dtype in dtype.args[1:]:\n                return_dtype = dt.types_lca(return_dtype, single_dtype, raising=False)\n            return return_dtype\n        elif dtype == dt.STR:\n            return dt.STR\n        elif dtype == dt.ANY:\n            return dt.ANY\n        elif isinstance(dtype, dt.Array):\n            return dtype.strip_dimension()\n        elif dtype == dt.JSON:\n            return dt.JSON\n        else:\n            raise TypeError(f\"Cannot flatten column of type {dtype}.\")\n\n    @cached_property\n    def universe(self) -> Universe:\n        ret = Universe()\n        if self.orig_universe.is_empty():\n            ret.register_as_empty(no_warn=False)\n        return ret\n\n    @cached_property\n    def flatten_result_column(self) -> Column:\n        return MaterializedColumn(\n            self.universe,\n            cp.ColumnProperties(\n                dtype=self._get_flatten_column_dtype(),\n                append_only=self.flatten_column.properties.append_only,\n            ),\n        )\n","sourceCodeStart":1067,"sourceCodeEnd":1103,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/column.py#L1067-L1103","documentation":"Table.flatten() computes the output dtype by inspecting the input column's type: LIST/ARRAY (minus one dimension), STR (chars), JSON, and ANY are supported. For any other dtype (INT, FLOAT, BOOL, DATE, etc.) there is no element type to flatten to, so a TypeError is raised at graph-construction time.","triggerScenarios":"Calling t.flatten() (Table.flatten, which flattens t.this) or column.flatten() on a column typed int, float, bool, Optional[int], Pointer, DATE_TIME, or a tuple type not handled by the LCA branch.","commonSituations":"Applying flatten to a column whose schema declares a scalar; assuming flatten works like pandas explode on any dtype; dtype ANY_json vs plain scalars confusion after schema changes.","solutions":["Verify the column dtype with t.schema or t.flatten_column.dtype before calling flatten.","Flatten only LIST/ARRAY columns; for strings use t.column.dt.flatten() semantics (string flattening is supported for STR) — do not flatten numeric columns.","If the column should be a list, fix the input schema/connector type mapping so the column is parsed as list[T]."],"exampleFix":"# before\nt = t.select(t.numbers)  # numbers: int due to wrong schema\nresult = t.flatten()\n\n# after\n# fix the schema so the column is a list\nclass InputSchema(pw.Schema):\n    values: list[int]\nt = pw.io.csv.read(path, schema=InputSchema)\nresult = t.flatten()","handlingStrategy":"validation","validationCode":"import pathway as dt_types\nfrom pathway.internals import dtype as dt\ncol_dtype = table.flatten_column.dtype\nflattenable = col_dtype in (dt.STR, dt.ANY, dt.JSON) or isinstance(col_dtype, (dt.List, dt.Array))\nassert flattenable, f'cannot flatten dtype {col_dtype}'","typeGuard":"from pathway.internals import dtype as dt\n\ndef dtype_flattenable(d) -> bool:\n    return d in (dt.STR, dt.ANY, dt.JSON) or isinstance(d, (dt.List, dt.Array))","tryCatchPattern":null,"preventionTips":["Declare explicit schemas on connectors so list columns are list[T], not inferred scalars.","Check table.schema before flatten in generic/reusable pipelines."],"tags":["pathway","flatten","dtype","type-error"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}