From 11e23635074f9685c4d7a69353172d3bcf484467 Mon Sep 17 00:00:00 2001 From: Chandrasekar Sivaraman Date: Mon, 17 Feb 2025 20:14:18 +0100 Subject: [PATCH] updated to_json function with orient=table to raise a ValueError if the column types are anything other than string --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8352ce0f9ac77..38399ada6dcc2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2378,7 +2378,7 @@ def to_json( Describing the data, where data component is like ``orient='records'``. Note that If `orient='table'`, column names must be strings. - Using numeric column names will raise a `ValueError`. + Using non string column names will raise a `ValueError`. date_format : {{None, 'epoch', 'iso'}} Type of date conversion. 'epoch' = epoch milliseconds, @@ -2450,7 +2450,7 @@ def to_json( schema. When using ``orient='table'``, column names must be strings due to JSON - requiring string keys. If column names are numeric (integers or floats), + requiring string keys. If column names are anything other than string, a `ValueError` will be raised. Examples @@ -2594,7 +2594,7 @@ def to_json( if orient == "table": if hasattr(self, "columns") and any( - isinstance(col, (int, float)) for col in self.columns + not isinstance(col, str) for col in self.columns ): raise ValueError( "Column names must be strings for JSON serialization with "