8000 BUG: Fix index type casting in read_json with orient='table' and float index (#25433) by albertvillanova · Pull Request #25434 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix index type casting in read_json with orient='table' and float index (#25433) #25434

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

Merged
merged 7 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address requested changes
  • Loading branch information
Albert Villanova del Moral committed Feb 26, 2019
commit fd0822b77015edd5b31c72f60ee6c2a153072c0a
21 changes: 13 additions & 8 deletions pandas/io/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,24 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=None,
'table' as an allowed value for the ``orient`` argument

typ : type of object to recover (series or frame), default 'frame'
dtype : boolean or dict, default True
dtype : boolean or dict, default None
If True, infer dtypes; if a dict of column to dtype, then use those;
if False, then don't infer dtypes at all, applies only to the data.

For all ``orient`` values except ``'table'``, default is True.

.. versionchanged:: 0.25.0

Not applicable with ``orient='table'``.
Not applicable for ``orient='table'``.

convert_axes : boolean, default True
convert_axes : boolean, default None
Try to convert the axes to the proper dtypes.

For all ``orient`` values except ``'table'``, default is True.

.. versionchanged:: 0.25.0

Not applicable with ``orient='table'``.
Not applicable for ``orient='table'``.

convert_dates : boolean, default True
List of columns to parse for dates; If True, then try to parse
Expand Down Expand Up @@ -423,9 +427,10 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=None,
if orient == 'table' and convert_axes:
raise ValueError("cannot pass both convert_axes and orient='table'")

dtype = orient != 'table' if dtype is None else dtype
if convert_axes is None:
convert_axes = orient != 'table'
if dtype is None and orient != 'table':
dtype = True
if convert_axes is None and orient != 'table':
convert_axes = True

compression = _infer_compression(path_or_buf, compression)
filepath_or_buffer, _, compression, should_close = get_filepath_or_buffer(
Expand Down Expand Up @@ -699,7 +704,7 @@ def _try_convert_data(self, name, data, use_dtypes=True,

# don't try to coerce, unless a force conversion
if use_dtypes:
if self.dtype is False:
if not self.dtype:
return data, False
elif self.dtype is True:
pass
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,5 +570,4 @@ def test_empty_frame_roundtrip(self):
expected = df.copy()
out = df.to_json(orient='table')
result = pd.read_json(out, orient='table')
# TODO: When DF coercion issue (#21345) is resolved tighten type checks
tm.assert_frame_equal(expected, result)
0