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

ENH: Use tz-aware dtype for timestamp columns #269

Merged
merged 7 commits into from
Apr 3, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix unit tests on old pandas
  • Loading branch information
tswast committed Apr 3, 2019
commit daf315e0f446307e9e7d81d3c9d9bb58bffae921
36 changes: 29 additions & 7 deletions tests/unit/test_gbq.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# -*- coding: utf-8 -*-

import pandas.util.testing as tm
import pytest
try:
import mock
except ImportError: # pragma: NO COVER
from unittest import mock

import numpy
from pandas import DataFrame
import pandas.util.testing as tm
import pkg_resources
import pytest

import pandas_gbq.exceptions
from pandas_gbq import gbq

try:
import mock
except ImportError: # pragma: NO COVER
from unittest import mock

pytestmark = pytest.mark.filter_warnings(
"ignore:credentials from Google Cloud SDK"
)
pandas_installed_version = pkg_resources.get_distribution(
"pandas"
).parsed_version


@pytest.fixture
Expand Down Expand Up @@ -90,7 +95,6 @@ def no_auth(monkeypatch):
("INTEGER", None), # Can't handle NULL
("BOOLEAN", None), # Can't handle NULL
("FLOAT", numpy.dtype(float)),
("TIMESTAMP", "datetime64[ns, UTC]"),
("DATETIME", "datetime64[ns]"),
],
)
Expand All @@ -104,6 +108,16 @@ def test_should_return_bigquery_correctly_typed(type_, expected):
assert result == {"x": expected}


def test_should_return_bigquery_correctly_typed_timestamp():
result = gbq._bqschema_to_nullsafe_dtypes(
[dict(name="x", type="TIMESTAMP", mode="NULLABLE")]
)
if pandas_installed_version < pkg_resources.parse_version("0.24.0"):
assert result == {"x": "datetime64[ns]"}
else:
assert result == {"x": "datetime64[ns, UTC]"}


def test_to_gbq_should_fail_if_invalid_table_name_passed():
with pytest.raises(gbq.NotFoundException):
gbq.to_gbq(DataFrame([[1]]), "invalid_table_name", project_id="1234")
Expand Down Expand Up @@ -200,6 +214,10 @@ def test_to_gbq_with_verbose_old_pandas_no_warnings(recwarn, min_bq_version):
assert len(recwarn) == 0


@pytest.mark.skipif(
pandas_installed_version < pkg_resources.parse_version("0.24.0"),
reason="Requires pandas 0.24+",
)
def test_to_gbq_with_private_key_new_pandas_warns_deprecation(
min_bq_version, monkeypatch
):
Expand Down Expand Up @@ -413,6 +431,10 @@ def test_read_gbq_with_verbose_old_pandas_no_warnings(recwarn, min_bq_version):
assert len(recwarn) == 0


@pytest.mark.skipif(
pandas_installed_version < pkg_resources.parse_version("0.24.0"),
reason="Requires pandas 0.24+",
)
def test_read_gbq_with_private_key_new_pandas_warns_deprecation(
min_bq_version, monkeypatch
):
Expand Down