Skip to content

Commit 2f347c0

Browse files
author
Pyry Kovanen
committed
Prevent empty data from being coerced to float64
1 parent fd8fa93 commit 2f347c0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pandas/io/json/json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ def _try_convert_types(self):
658658

659659
def _try_convert_data(self, name, data, use_dtypes=True,
660660
convert_dates=True):
661+
print(data)
661662
""" try to parse a ndarray like into a column by inferring dtype """
662663

663664
# don't try to coerce, unless a force conversion
@@ -686,7 +687,7 @@ def _try_convert_data(self, name, data, use_dtypes=True,
686687

687688
result = False
688689

689-
if data.dtype == 'object':
690+
if len(data) and data.dtype == 'object':
690691

691692
# try float
692693
try:

pandas/tests/io/json/test_json_table_schema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for Table Schema integration."""
22
import json
3+
import io
34
from collections import OrderedDict
45

56
import numpy as np
@@ -566,6 +567,6 @@ def test_empty_frame_roundtrip(self):
566567
# GH 21287
567568
df = pd.DataFrame([], columns=['a', 'b', 'c'])
568569
expected = df.copy()
569-
out = df.to_json(None, orient='table')
570+
out = df.to_json(orient='table')
570571
result = pd.read_json(out, orient='table')
571-
pd.testing.assert_frame_equal(expected, result)
572+
tm.assert_frame_equal(expected, result)

0 commit comments

Comments
 (0)