-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix issue #36271 to disambiguate json string #36273
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
Changes from 8 commits
8c40f23
e5777f4
ed49bfe
0d7e063
3706d18
210d659
6b2c98c
6019978
def1881
943f644
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ | |
|
||
from pandas.core.dtypes.common import is_file_like | ||
|
||
from pandas._libs.json import loads | ||
|
||
lzma = import_lzma() | ||
|
||
|
||
|
@@ -153,6 +155,19 @@ def urlopen(*args, **kwargs): | |
return urllib.request.urlopen(*args, **kwargs) | ||
|
||
|
||
def is_json(url: FilePathOrBuffer) -> bool: | ||
""" | ||
Returns true if the given string looks like | ||
something json.loads can handle | ||
""" | ||
try: | ||
loads(url) | ||
|
||
return True | ||
except: | ||
return False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be simplified There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, I committed your suggestion |
||
|
||
|
||
def is_fsspec_url(url: FilePathOrBuffer) -> bool: | ||
""" | ||
Returns true if the given URL looks like | ||
|
@@ -161,6 +176,7 @@ def is_fsspec_url(url: FilePathOrBuffer) -> bool: | |
return ( | ||
isinstance(url, str) | ||
and "://" in url | ||
and not is_json(url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For pandas maintainers: should this check only be done within read_json (which will presumably call json.loads anyway, repeating the work) ? Are there any other similar cases that the string passed might be handled as a path, or decoded directly, that I might have missed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tbachlechner if you really think t his out to be caught then i suppose a 'better' check instead of |
||
and not url.startswith(("http://", "https://")) | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cannot do this generally as its completely non-performant