Skip to content

Commit 11e2363

Browse files
updated to_json function with orient=table to raise a ValueError if the column types are anything other than string
1 parent 62483d7 commit 11e2363

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/core/generic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ def to_json(
23782378
Describing the data, where data component is like ``orient='records'``.
23792379
23802380
Note that If `orient='table'`, column names must be strings.
2381-
Using numeric column names will raise a `ValueError`.
2381+
Using non string column names will raise a `ValueError`.
23822382
23832383
date_format : {{None, 'epoch', 'iso'}}
23842384
Type of date conversion. 'epoch' = epoch milliseconds,
@@ -2450,7 +2450,7 @@ def to_json(
24502450
schema.
24512451
24522452
When using ``orient='table'``, column names must be strings due to JSON
2453-
requiring string keys. If column names are numeric (integers or floats),
2453+
requiring string keys. If column names are anything other than string,
24542454
a `ValueError` will be raised.
24552455
24562456
Examples
@@ -2594,7 +2594,7 @@ def to_json(
25942594

25952595
if orient == "table":
25962596
if hasattr(self, "columns") and any(
2597-
isinstance(col, (int, float)) for col in self.columns
2597+
not isinstance(col, str) for col in self.columns
25982598
):
25992599
raise ValueError(
26002600
"Column names must be strings for JSON serialization with "

0 commit comments

Comments
 (0)