Skip to content

Commit

Permalink
avoid monkey patching requests.Session Fixes pydata#301
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Jul 4, 2017
1 parent d69b544 commit 82aa2e0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/source/whatsnew/v0.5.0.txt
Expand Up @@ -22,3 +22,4 @@ Bug Fixes
- Handle commas in large price quotes (:issue:`345`)
- Test suite fixes for test_get_options_data (:issue:`352`)
- Test suite fixes for test_wdi_download (:issue:`350`)
- avoid monkey patching requests.Session (:issue:`301`)
11 changes: 5 additions & 6 deletions pandas_datareader/_utils.py
@@ -1,12 +1,10 @@
import datetime as dt
from pandas import to_datetime
from requests_file import FileAdapter
from pandas_datareader.compat import is_number

import requests
import requests_ftp

requests_ftp.monkeypatch_session()
from pandas import to_datetime
from pandas_datareader.compat import is_number
from requests_file import FileAdapter
from requests_ftp import FTPAdapter


class SymbolWarning(UserWarning):
Expand Down Expand Up @@ -43,5 +41,6 @@ def _init_session(session, retry_count=3):
if session is None:
session = requests.Session()
session.mount('file://', FileAdapter())
session.mount('ftp://', FTPAdapter())
# do not set requests max_retries here to support arbitrary pause
return session
3 changes: 0 additions & 3 deletions pandas_datareader/base.py
Expand Up @@ -13,9 +13,6 @@
from pandas_datareader._utils import (RemoteDataError, SymbolWarning,
_sanitize_dates, _init_session)

import requests_ftp
requests_ftp.monkeypatch_session()


class _BaseReader(object):

Expand Down
5 changes: 5 additions & 0 deletions pandas_datareader/tests/test_base.py
@@ -1,8 +1,13 @@
import pytest
import requests

import pandas_datareader.base as base


class TestBaseReader(object):
def test_requests_not_monkey_patched(self):
assert not hasattr(requests.Session(), 'stor')

def test_valid_retry_count(self):
with pytest.raises(ValueError):
base._BaseReader([], retry_count='stuff')
Expand Down

0 comments on commit 82aa2e0

Please sign in to comment.