-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
use requests when it is installed #28874
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
Conversation
pandas/io/excel/_base.py
Outdated
@@ -336,10 +336,10 @@ def read_excel( | |||
|
|||
|
|||
class _BaseExcelReader(metaclass=abc.ABCMeta): | |||
def __init__(self, filepath_or_buffer): | |||
def __init__(self, filepath_or_buffer, session=None): |
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.
I'm a bit lost on how to pass the session
object to this class, right now it defaults
to None
b/c it does not get the value from read_excel
.
pandas/io/excel/_base.py
Outdated
@@ -20,7 +20,7 @@ | |||
_stringify_path, | |||
_validate_header_arg, | |||
get_filepath_or_buffer, | |||
urlopen, | |||
_urlopen, |
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.
can you use the non-private version
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.
Done.
r.raise_for_status() | ||
content = r.content | ||
r.close() | ||
except ImportError: |
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.
can you use pandas.compat._optional.import_optional_dependency here
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.
Not sure if I got it right.
Haven't read through the attached issue but this is a little more complicated than I would have hoped for. Is there a reason why you think this is in scope of pandas? Pandas can operate for the most part on items that adhered to the IOBase definition. I don't think dealing with the |
pandas/io/parsers.py
Outdated
@@ -342,6 +342,9 @@ | |||
values. The options are `None` for the ordinary converter, | |||
`high` for the high-precision converter, and `round_trip` for the | |||
round-trip converter. | |||
session : requests.Session | |||
object with the a requests session configuration for remote file. | |||
(requires the requests library) |
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.
add a version added tag
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.
Not sure what that means.
pandas/io/common.py
Outdated
compression = None | ||
content_encoding = None | ||
try: | ||
import requests |
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.
need to use the pandas.compat._optional.import_optional_dependency
I'm assuming you are taking about the Some background. At NOAA we need the |
IIRC pandas_datareader supports requests Sessions |
I know. That is what inspired the original poster of this PR. I'm traveling back home today and I'll address the review comments during the weekend. Thanks! |
I guess I'm not clear on what Sessions are doing here. Neither of the issues that this closes reference Session objects anywhere - are you sure this closes them? Can you add test cases? |
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.
I guess I'm not clear on what Sessions are doing here. Neither of the issues that this closes reference Session objects anywhere - are you sure this closes them?
The original issue was #16716 by @skynss and the original PR used session. See #17087
Allow us to pass user/password, for example, for password protected servers.
One can also use a local .netrc
file. Let's remove the session for now to see if we can make progress.
Can you add test cases?
Sure. Writing those, just wanted to be sure this will get a green signal before investing more time on it.
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.
FWIW, we've been having multiple conversations about how users pass through kwargs from a read like pd.read_csv(...)
to the "file open" call. Sometimes it's just the builtin open(path)
, but in this case it might be requests.get(...)
At some point, I'd like to unify these into a backend_kwargs
or open_kwargs
dict that gets passed through (but that's for a separate issue. I'll try to open one).
r = urllib.request.urlopen(*args, **kwargs) | ||
content = r.read() | ||
content_encoding = r.headers.get("Content-Encoding", None) | ||
if content_encoding == "gzip": |
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.
I think this also needs to be under the except ImportError
? From what I can tell, requests .content
will automatically decode gzip: https://requests.readthedocs.io/en/master/user/quickstart/#binary-response-content
@ocefpaf still active? Can you address comments and check CI failures? |
I'll probably have some time for this during the end of the year break. If someone wants to pick it up from here before that please feel free to do so. |
@ocefpaf if you can merge master and see if you can get passing would be great. |
Hi @ocefpaf - sorry to chase you up, just wanted to ask whether you're still working on this :) |
Closing as I think stale, but certainly ping if you'd like to continue |
closes #16716
closes #28825
closes #28826
solves #16910
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Continuation of #21504 and #17087
This PR is not ready but I'd appreciate any early comment/feedback.