-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.read_json
throwing error on bytes
input
#46935
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
Comments
Thanks @galipremsagar for the report. This may have happened to work previously, but off the top of my head I'm not sure how much support pandas still has since we dropped Python 2 for accepting Will label as a regression for now, pending further investigation. first bad commit: [5f36af3] MAINT: rename IOError -> OSError (#43366) cc @mwtoews |
The documentation for
so raising (One exception is Nevertheless, the input of "buffer" would need to be processed somehow to valid JSON. [{"amount": 100, "name": "Alice"},
{"amount": 200, "name": "Bob"},
{"amount": 300, "name": "Charlie"},
{"amount": 400, "name": "Dennis"}] |
An alternative solution using the original "buffer" input, splitting on newlines: parts = [pd.read_json(itm, orient="index") for itm in buffer.decode().split("\n") if itm]
df = pd.concat(parts, axis=1).T.reset_index(drop=True) |
Potential duplicate of #45935 |
agreed. The comments in #45935 do not account for the issue being a regression (an undocumented behavior change) and should not have been changed without deprecation, but one could equally argue that this was not a breaking api change since the documentation does not include bytes as an accepted type. will close as no action for same reasons as commented in #45935, but feel free to comment here if strongly disagree. |
- pandas.read_json needs to take in a decoded string - see pandas-dev/pandas#46935
- pandas.read_json needs to take in a decoded string - see pandas-dev/pandas#46935
- pandas.read_json needs to take in a decoded string - see pandas-dev/pandas#46935
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
When a
bytes
input is passed topd.read_json
it parsed the input and returned data frame until 1.3.x versions. But throwing an error in 1.4.2 version.Expected Behavior
Same as previous versions? or if this is a breaking behavior not explicitly called out in the changelog?
Installed Versions
In [4]: pd.show_versions()
AssertionError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 pd.show_versions()
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/pandas/util/_print_versions.py:109, in show_versions(as_json)
94 """
95 Provide useful information, important for bug reports.
96
(...)
106 * If True, outputs info in JSON format to the console.
107 """
108 sys_info = _get_sys_info()
--> 109 deps = _get_dependency_info()
111 if as_json:
112 j = {"system": sys_info, "dependencies": deps}
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/pandas/util/_print_versions.py:88, in _get_dependency_info()
86 result: dict[str, JSONSerializable] = {}
87 for modname in deps:
---> 88 mod = import_optional_dependency(modname, errors="ignore")
89 result[modname] = get_version(mod) if mod else None
90 return result
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/pandas/compat/_optional.py:138, in import_optional_dependency(name, extra, errors, min_version)
133 msg = (
134 f"Missing optional dependency '{install_name}'. {extra} "
135 f"Use pip or conda to install {install_name}."
136 )
137 try:
--> 138 module = importlib.import_module(name)
139 except ImportError:
140 if errors == "raise":
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/importlib/init.py:127, in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File :1014, in _gcd_import(name, package, level)
File :991, in find_and_load(name, import)
File :975, in find_and_load_unlocked(name, import)
File :671, in _load_unlocked(spec)
File :843, in exec_module(self, module)
File :219, in _call_with_frames_removed(f, *args, **kwds)
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/setuptools/init.py:8, in
5 import re
6 import warnings
----> 8 import _distutils_hack.override # noqa: F401
10 import distutils.core
11 from distutils.errors import DistutilsOptionError
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/_distutils_hack/override.py:1, in
----> 1 import('_distutils_hack').do_override()
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/_distutils_hack/init.py:72, in do_override()
70 if enabled():
71 warn_distutils_present()
---> 72 ensure_local_distutils()
File /nvme/0/pgali/envs/cudfdev/lib/python3.8/site-packages/_distutils_hack/init.py:59, in ensure_local_distutils()
57 # check that submodules load as expected
58 core = importlib.import_module('distutils.core')
---> 59 assert '_distutils' in core.file, core.file
60 assert 'setuptools._distutils.log' not in sys.modules
AssertionError: /nvme/0/pgali/envs/cudfdev/lib/python3.8/distutils/core.py
The text was updated successfully, but these errors were encountered: