Skip to content
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

AttributeError when use_bqstorage_api=True on empty df #299

Closed
Bizetremi opened this issue Dec 5, 2019 · 2 comments · Fixed by #310
Closed

AttributeError when use_bqstorage_api=True on empty df #299

Bizetremi opened this issue Dec 5, 2019 · 2 comments · Fixed by #310
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Bizetremi
Copy link

Bizetremi commented Dec 5, 2019

The following error is thrown when using pandas_gbq.read_gbq with use_bqstorage_api=True when the query returns no data.

(use_bqstorage_api=True)
File '/env/local/lib/python3.7/site-packages/pandas_gbq/gbq.py', line 1034, in read_gbq
progress_bar_type=progress_bar_type,
File '/env/local/lib/python3.7/site-packages/pandas_gbq/gbq.py', line 532, in run_query
progress_bar_type=progress_bar_type,
File '/env/local/lib/python3.7/site-packages/pandas_gbq/gbq.py', line 576, in _download_results
df = _localize_df(schema_fields, df)
File '/env/local/lib/python3.7/site-packages/pandas_gbq/gbq.py', line 808, in _localize_df
if field['type'].upper() == 'TIMESTAMP' and df[column].dt.tz is None:
File '/env/local/lib/python3.7/site-packages/pandas/core/generic.py', line 5175, in getattr
return object.getattribute(self, name)
File '/env/local/lib/python3.7/site-packages/pandas/core/accessor.py', line 175, in get
accessor_obj = self._accessor(obj)
File '/env/local/lib/python3.7/site-packages/pandas/core/indexes/accessors.py', line 343, in new
raise AttributeError('Can only use .dt accessor with datetimelike ' 'values')
AttributeError: Can only use .dt accessor with datetimelike values

@tswast tswast added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Dec 6, 2019
@tswast tswast self-assigned this Dec 6, 2019
@tswast tswast added the priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. label Feb 6, 2020
@tswast
Copy link
Collaborator

tswast commented Feb 11, 2020

I'm not able to reproduce with a plain empty result set. This test passes:

def test_empty_results(method_under_test):
    """Test with an empty dataframe.

    See: https://github.com/pydata/pandas-gbq/issues/299
    """
    df = method_under_test(
        "SELECT * FROM (SELECT 1) AS tbl WHERE TRUE = FALSE;",
        use_bqstorage_api=True,
    )
    assert len(df.index) == 0

Based on the stacktrace, I'll try a query where a timestamp column is in the results.

@tswast
Copy link
Collaborator

tswast commented Feb 11, 2020

Based on the stacktrace, I'll try a query where a timestamp column is in the results.

Confirmed. The test fails with the query "SELECT * FROM (SELECT TIMESTAMP('2020-02-11 16:33:32-06:00')) WHERE TRUE = FALSE;".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants