{"record":{"id":"e4221506c2913440","repo":"pola-rs/polars","slug":"cannot-describe-a-dataframe-that-has-no-columns","errorCode":null,"errorMessage":"cannot describe a DataFrame that has no columns","messagePattern":"cannot describe a DataFrame that has no columns","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":6010,"sourceCode":"        │ ---        ┆ ---      ┆ ---      ┆ ---      ┆ ---  ┆ ---                 ┆ ---      │\n        │ str        ┆ f64      ┆ f64      ┆ f64      ┆ str  ┆ str                 ┆ str      │\n        ╞════════════╪══════════╪══════════╪══════════╪══════╪═════════════════════╪══════════╡\n        │ count      ┆ 3.0      ┆ 2.0      ┆ 3.0      ┆ 3    ┆ 3                   ┆ 3        │\n        │ null_count ┆ 0.0      ┆ 1.0      ┆ 0.0      ┆ 0    ┆ 0                   ┆ 0        │\n        │ mean       ┆ 2.266667 ┆ 45.0     ┆ 0.666667 ┆ null ┆ 2021-07-02 16:00:00 ┆ 16:07:10 │\n        │ std        ┆ 1.101514 ┆ 7.071068 ┆ null     ┆ null ┆ null                ┆ null     │\n        │ min        ┆ 1.0      ┆ 40.0     ┆ 0.0      ┆ xx   ┆ 2020-01-01          ┆ 10:20:30 │\n        │ 10%        ┆ 1.36     ┆ 41.0     ┆ null     ┆ null ┆ 2020-04-20          ┆ 11:13:34 │\n        │ 30%        ┆ 2.08     ┆ 43.0     ┆ null     ┆ null ┆ 2020-11-26          ┆ 12:59:42 │\n        │ 50%        ┆ 2.8      ┆ 45.0     ┆ null     ┆ null ┆ 2021-07-05          ┆ 14:45:50 │\n        │ 70%        ┆ 2.88     ┆ 47.0     ┆ null     ┆ null ┆ 2022-02-07          ┆ 18:09:34 │\n        │ 90%        ┆ 2.96     ┆ 49.0     ┆ null     ┆ null ┆ 2022-09-13          ┆ 21:33:18 │\n        │ max        ┆ 3.0      ┆ 50.0     ┆ 1.0      ┆ zz   ┆ 2022-12-31          ┆ 23:15:10 │\n        └────────────┴──────────┴──────────┴──────────┴──────┴─────────────────────┴──────────┘\n        \"\"\"  # noqa: W505\n        if not self.columns:\n            msg = \"cannot describe a DataFrame that has no columns\"\n            raise TypeError(msg)\n\n        return self.lazy().describe(\n            percentiles=percentiles, interpolation=interpolation\n        )\n\n    def get_column_index(self, name: str) -> int:\n        \"\"\"\n        Find the index of a column by name.\n\n        Parameters\n        ----------\n        name\n            Name of the column to find.\n\n        Examples\n        --------\n        >>> df = pl.DataFrame(\n        ...     {\"foo\": [1, 2, 3], \"bar\": [6, 7, 8], \"ham\": [\"a\", \"b\", \"c\"]}","sourceCodeStart":5992,"sourceCodeEnd":6028,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L5992-L6028","documentation":"DataFrame.describe() computes per-column statistics (count, null_count, mean, std, min, percentiles, max), which requires at least one column. A DataFrame with zero columns has nothing to summarize, so polars raises TypeError (note: TypeError, not ValueError) with this message. The check happens up front, before delegating to the lazy describe implementation.","triggerScenarios":"pl.DataFrame().describe(); df.select([]).describe(); df.drop(df.columns).describe(); calling describe() on a frame whose schema came back empty from a scan/read of an empty file.","commonSituations":"Generic EDA/reporting loops that call describe() on every loaded table including empty ones; unit tests with empty fixtures; dynamic column selection or drop logic that can reduce width to 0; reading a truncated/empty CSV or Parquet with zero columns.","solutions":["Guard the call: only describe frames with columns, e.g. `stats = df.describe() if df.width else None`","If the frame was not expected to be empty, fix the upstream load (wrong path, empty file, over-filtered select, bad drop list)","For optional preview paths, fall back to logging df.schema or df.shape instead"],"exampleFix":"# before\nstats = df.describe()  # crashes when df has no columns\n\n# after\nstats = df.describe() if df.width else None\nprint(df.schema if df.width else 'empty frame')","handlingStrategy":"validation","validationCode":"if not df.columns:\n    raise ValueError(f'cannot describe empty frame with shape {df.shape}')\nstats = df.describe()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard generic EDA loops with `if df.width:` before calling describe","Log df.shape/schema when a load yields zero columns — it usually signals an upstream read problem","In tests, include an empty-frame case for any helper that calls describe"],"tags":["polars","dataframe","describe","empty-data","typeerror","statistics"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}