Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG : read_json with table='orient' causes unexpected type coercion #21408

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pandas/io/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ def _try_convert_data(self, name, data, use_dtypes=True,
except (TypeError, ValueError):
pass

# do't coerce 0-len data
if len(data) and (data.dtype == 'float' or data.dtype == 'object'):
# don't coerce 0-len data
if len(data) and (data.dtype == 'object'):

# coerce ints if we can
# coerce int if we can
try:
new_data = data.astype('int64')
if (new_data == data).all():
Expand All @@ -721,13 +721,23 @@ def _try_convert_data(self, name, data, use_dtypes=True,
# coerce ints to 64
if data.dtype == 'int':

# coerce floats to 64
# coerce ints to 64
try:
data = data.astype('int64')
result = True
except (TypeError, ValueError):
pass

# coerce floats to 64
if data.dtype == 'float':

# coerce floats to 64
try:
data = data.astype('float64')
result = True
except (TypeError, ValueError):
pass

return data, result

def _try_convert_to_date(self, data):
Expand Down