-
-
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 all 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import mmap | ||
import os | ||
import pathlib | ||
import re | ||
from typing import ( | ||
IO, | ||
TYPE_CHECKING, | ||
|
@@ -153,6 +154,16 @@ def urlopen(*args, **kwargs): | |
return urllib.request.urlopen(*args, **kwargs) | ||
|
||
|
||
def is_json(url: FilePathOrBuffer) -> bool: | ||
""" | ||
Returns true if the given string looks like | ||
json | ||
""" | ||
json_pattern = re.compile(r"^\s*[\[{]") | ||
return json_pattern.match(url) is not None | ||
|
||
|
||
|
||
def is_fsspec_url(url: FilePathOrBuffer) -> bool: | ||
""" | ||
Returns true if the given URL looks like | ||
|
@@ -161,6 +172,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.
probably need something like the following for typing
The pre-commit is complaining about too many new lines.