Skip to content

MAINT: Refactor more compat checks into compat init #311

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

Merged
merged 1 commit into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions pandas_datareader/_utils.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
import datetime as dt
from distutils.version import LooseVersion

import pandas as pd
from pandas import to_datetime
from requests_file import FileAdapter
from pandas_datareader.compat import is_number

import requests
from requests_file import FileAdapter
import requests_ftp
requests_ftp.monkeypatch_session()


if pd.compat.PY3:
from urllib.error import HTTPError # noqa
else:
from urllib2 import HTTPError # noqa

PANDAS_VERSION = LooseVersion(pd.__version__)

if PANDAS_VERSION >= LooseVersion('0.19.0'):
PANDAS_0190 = True
from pandas.api.types import is_number # noqa
else:
PANDAS_0190 = False
from pandas.core.common import is_number # noqa

if PANDAS_VERSION >= LooseVersion('0.17.0'):
PANDAS_0170 = True
else:
PANDAS_0170 = False

if PANDAS_VERSION >= LooseVersion('0.16.0'):
PANDAS_0160 = True
else:
PANDAS_0160 = False

if PANDAS_VERSION >= LooseVersion('0.14.0'):
PANDAS_0140 = True
else:
PANDAS_0140 = False
requests_ftp.monkeypatch_session()


class SymbolWarning(UserWarning):
Expand Down
17 changes: 14 additions & 3 deletions pandas_datareader/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# flake8: noqa
import pandas as pd
import pandas.compat as compat

from io import BytesIO
from distutils.version import LooseVersion

pandas_version = LooseVersion(pd.__version__)
if pandas_version <= '0.19.2':
PANDAS_VERSION = LooseVersion(pd.__version__)

PANDAS_0190 = (PANDAS_VERSION >= LooseVersion('0.19.0'))
PANDAS_0170 = (PANDAS_VERSION >= LooseVersion('0.17.0'))
PANDAS_0160 = (PANDAS_VERSION >= LooseVersion('0.16.0'))

if PANDAS_0190:
from pandas.api.types import is_number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be >= 0.19.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do see how PANDAS_0190 is defined?

else:
from pandas.core.common import is_number

if compat.PY3:
from urllib.error import HTTPError
else:
from pandas.api.types import is_number
from urllib2 import HTTPError
2 changes: 1 addition & 1 deletion pandas_datareader/io/sdmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pandas.compat as compat

from pandas_datareader.io.util import _read_content
from pandas_datareader._utils import HTTPError
from pandas_datareader.compat import HTTPError


_STRUCTURE = '{http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure}'
Expand Down
2 changes: 1 addition & 1 deletion pandas_datareader/tests/test_eurostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas.util.testing as tm
import pandas_datareader.data as web

from pandas_datareader._utils import PANDAS_0170
from pandas_datareader.compat import PANDAS_0170


class TestEurostat(tm.TestCase):
Expand Down
17 changes: 3 additions & 14 deletions pandas_datareader/tests/test_wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pandas_datareader.wb import (search, download, get_countries,
get_indicators, WorldBankReader)
from pandas_datareader._utils import PANDAS_0170, PANDAS_0160, PANDAS_0140
from pandas_datareader.compat import PANDAS_0170, PANDAS_0160


class TestWB(tm.TestCase):
Expand Down Expand Up @@ -70,12 +70,7 @@ def test_wdi_download(self):
# Round, to ignore revisions to data.
result = np.round(result, decimals=-3)

if PANDAS_0140:
expected.index.names = ['country', 'year']
else:
# prior versions doesn't allow to set multiple names to MultiIndex
# Thus overwrite it with the result
expected.index = result.index
expected.index.names = ['country', 'year']
tm.assert_frame_equal(result, expected)

# pass start and end as string
Expand Down Expand Up @@ -114,13 +109,7 @@ def test_wdi_download_str(self):
result = result.sort()
result = np.round(result, decimals=-3)

if PANDAS_0140:
expected.index.names = ['country', 'year']
else:
# prior versions doesn't allow to set multiple names to MultiIndex
# Thus overwrite it with the result
expected.index = result.index

expected.index.names = ['country', 'year']
tm.assert_frame_equal(result, expected)

result = WorldBankReader(inds, countries=cntry_codes,
Expand Down
2 changes: 1 addition & 1 deletion pandas_datareader/wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from pandas_datareader.base import _BaseReader
from pandas_datareader._utils import PANDAS_0170
from pandas_datareader.compat import PANDAS_0170

# This list of country codes was pulled from wikipedia during October 2014.
# While some exceptions do exist, it is the best proxy for countries supported
Expand Down