diff --git a/ci/print_versions.py b/ci/print_versions.py index 0df8bb7e28786..58f232775d461 100755 --- a/ci/print_versions.py +++ b/ci/print_versions.py @@ -129,4 +129,22 @@ except: print("html5lib: Not installed") +try: + import apiclient + print("apiclient: %s" % apiclient.__version__) +except: + print("apiclient: Not installed") + +try: + import oauth2client + print("oauth2client: %s" % oauth2client.__version__) +except: + print("oauth2client: Not installed") + +try: + import httplib2 + print("httplib2: %s" % httplib2.__version__) +except: + print("httplib2: Not installed") + print("\n") diff --git a/ci/requirements-2.6.txt b/ci/requirements-2.6.txt index 5038b9e2b6552..2be45a647ac76 100644 --- a/ci/requirements-2.6.txt +++ b/ci/requirements-2.6.txt @@ -4,3 +4,5 @@ python-dateutil==1.5 pytz==2013b http://www.crummy.com/software/BeautifulSoup/bs4/download/4.2/beautifulsoup4-4.2.0.tar.gz html5lib==1.0b2 +google-api-python-client==1.2 +httplib2==0.8 diff --git a/ci/requirements-2.7.txt b/ci/requirements-2.7.txt index 6a94d48ad7a5f..4715f97ac91f6 100644 --- a/ci/requirements-2.7.txt +++ b/ci/requirements-2.7.txt @@ -16,3 +16,6 @@ scikits.timeseries==0.91.3 MySQL-python==1.2.4 scipy==0.10.0 beautifulsoup4==4.2.1 +google-api-python-client==1.2 +httplib2==0.8 +python-gflags==2.0 diff --git a/ci/requirements-2.7_LOCALE.txt b/ci/requirements-2.7_LOCALE.txt index 70c398816f23c..2d1ffc7ded787 100644 --- a/ci/requirements-2.7_LOCALE.txt +++ b/ci/requirements-2.7_LOCALE.txt @@ -14,3 +14,4 @@ html5lib==1.0b2 lxml==3.2.1 scipy==0.10.0 beautifulsoup4==4.2.1 +google-api-python-client==1.2 diff --git a/doc/source/install.rst b/doc/source/install.rst index 4d9864b272c2a..243da9460b41d 100644 --- a/doc/source/install.rst +++ b/doc/source/install.rst @@ -148,6 +148,10 @@ Optional Dependencies to get the necessary dependencies for installation of `lxml`_. This will prevent further headaches down the line. + * `google-api-python-client ``__ + * Needed for :mod:`pandas.io.ga` + .. _html5lib: https://github.com/html5lib/html5lib-python .. _BeautifulSoup4: http://www.crummy.com/software/BeautifulSoup diff --git a/pandas/io/ga.py b/pandas/io/ga.py index dcbecd74886ac..e080ae1701aa1 100644 --- a/pandas/io/ga.py +++ b/pandas/io/ga.py @@ -15,8 +15,18 @@ import pandas.io.auth as auth from pandas.util.decorators import Appender, Substitution -from apiclient.errors import HttpError -from oauth2client.client import AccessTokenRefreshError +try: + from apiclient.errors import HttpError + _APICLIENT_INSTALLED = True +except: + _APICLIENT_INSTALLED = False + +try: + from oauth2client.client import AccessTokenRefreshError + _OAUTH2_INSTALLED = True +except: + _OAUTH2_INSTALLED = False + from pandas.compat import zip, u TYPE_MAP = {u('INTEGER'): int, u('FLOAT'): float, u('TIME'): int} @@ -97,6 +107,12 @@ def reset_token_store(): @Substitution(extras=_AUTH_PARAMS) @Appender(_GA_READER_DOC) def read_ga(metrics, dimensions, start_date, **kwargs): + + if not _OAUTH2_INSTALLED: + raise ImportError('Could not import OAuth2.0 Client.') + elif not _APICLIENT_INSTALLED: + raise ImportError('Could not import Google Python API.') + lst = ['secrets', 'scope', 'token_file_name', 'redirect'] reader_kwds = dict((p, kwargs.pop(p)) for p in lst if p in kwargs) reader = GAnalytics(**reader_kwds) @@ -254,13 +270,15 @@ def get_data(self, metrics, start_date, end_date=None, raise ValueError('Google API returns maximum of 10,000 rows, ' 'please set chunksize') - account = self.get_account(account_name, account_id) - web_property = self.get_web_property(account.get('id'), property_name, - property_id) - profile = self.get_profile(account.get('id'), web_property.get('id'), - profile_name, profile_id) + if not profile_id: + account = self.get_account(account_name, account_id) + web_property = self.get_web_property(account.get('id'), + property_name, property_id) + profile = self.get_profile(account.get('id'), + web_property.get('id'), profile_name, + profile_id) - profile_id = profile.get('id') + profile_id = profile.get('id') if index_col is None and dimensions is not None: if isinstance(dimensions, compat.string_types): diff --git a/pandas/io/tests/test_ga.py b/pandas/io/tests/test_ga.py index e33b75c569fef..7676c8e1d3845 100644 --- a/pandas/io/tests/test_ga.py +++ b/pandas/io/tests/test_ga.py @@ -13,8 +13,8 @@ from pandas.io.ga import GAnalytics, read_ga from pandas.io.auth import AuthenticationConfigError, reset_token_store from pandas.io import auth -except ImportError: - raise nose.SkipTest +except (Exception) as detail: + raise nose.SkipTest(detail) class TestGoogle(unittest.TestCase):