Skip to content

Commit

Permalink
updated to_json function with orient=table to raise a ValueError if t…
Browse files Browse the repository at this point in the history
…he column types are anything other than string
  • Loading branch information
chandra-teajunkie committed Feb 17, 2025
1 parent 62483d7 commit 11e2363
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down

0 comments on commit 11e2363

Please sign in to comment.