Skip to content

Commit 45c7821

Browse files
committed
Fix unit tests on old pandas
1 parent d14746e commit 45c7821

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

tests/unit/test_gbq.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# -*- coding: utf-8 -*-
22

3-
import pandas.util.testing as tm
4-
import pytest
3+
try:
4+
import mock
5+
except ImportError: # pragma: NO COVER
6+
from unittest import mock
7+
58
import numpy
69
from pandas import DataFrame
10+
import pandas.util.testing as tm
11+
import pkg_resources
12+
import pytest
713

814
import pandas_gbq.exceptions
915
from pandas_gbq import gbq
1016

11-
try:
12-
import mock
13-
except ImportError: # pragma: NO COVER
14-
from unittest import mock
1517

1618
pytestmark = pytest.mark.filter_warnings(
1719
"ignore:credentials from Google Cloud SDK"
1820
)
21+
pandas_installed_version = pkg_resources.get_distribution(
22+
"pandas"
23+
).parsed_version
1924

2025

2126
@pytest.fixture
@@ -90,7 +95,6 @@ def no_auth(monkeypatch):
9095
("INTEGER", None), # Can't handle NULL
9196
("BOOLEAN", None), # Can't handle NULL
9297
("FLOAT", numpy.dtype(float)),
93-
("TIMESTAMP", "datetime64[ns, UTC]"),
9498
("DATETIME", "datetime64[ns]"),
9599
],
96100
)
@@ -104,6 +108,16 @@ def test_should_return_bigquery_correctly_typed(type_, expected):
104108
assert result == {"x": expected}
105109

106110

111+
def test_should_return_bigquery_correctly_typed_timestamp():
112+
result = gbq._bqschema_to_nullsafe_dtypes(
113+
[dict(name="x", type="TIMESTAMP", mode="NULLABLE")]
114+
)
115+
if pandas_installed_version < pkg_resources.parse_version("0.24.0"):
116+
assert result == {"x": "datetime64[ns]"}
117+
else:
118+
assert result == {"x": "datetime64[ns, UTC]"}
119+
120+
107121
def test_to_gbq_should_fail_if_invalid_table_name_passed():
108122
with pytest.raises(gbq.NotFoundException):
109123
gbq.to_gbq(DataFrame([[1]]), "invalid_table_name", project_id="1234")
@@ -200,6 +214,10 @@ def test_to_gbq_with_verbose_old_pandas_no_warnings(recwarn, min_bq_version):
200214
assert len(recwarn) == 0
201215

202216

217+
@pytest.mark.skipif(
218+
pandas_installed_version < pkg_resources.parse_version("0.24.0"),
219+
reason="Requires pandas 0.24+",
220+
)
203221
def test_to_gbq_with_private_key_new_pandas_warns_deprecation(
204222
min_bq_version, monkeypatch
205223
):
@@ -413,6 +431,10 @@ def test_read_gbq_with_verbose_old_pandas_no_warnings(recwarn, min_bq_version):
413431
assert len(recwarn) == 0
414432

415433

434+
@pytest.mark.skipif(
435+
pandas_installed_version < pkg_resources.parse_version("0.24.0"),
436+
reason="Requires pandas 0.24+",
437+
)
416438
def test_read_gbq_with_private_key_new_pandas_warns_deprecation(
417439
min_bq_version, monkeypatch
418440
):

0 commit comments

Comments
 (0)