1
1
# -*- coding: utf-8 -*-
2
2
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
+
5
8
import numpy
6
9
from pandas import DataFrame
10
+ import pandas .util .testing as tm
11
+ import pkg_resources
12
+ import pytest
7
13
8
14
import pandas_gbq .exceptions
9
15
from pandas_gbq import gbq
10
16
11
- try :
12
- import mock
13
- except ImportError : # pragma: NO COVER
14
- from unittest import mock
15
17
16
18
pytestmark = pytest .mark .filter_warnings (
17
19
"ignore:credentials from Google Cloud SDK"
18
20
)
21
+ pandas_installed_version = pkg_resources .get_distribution (
22
+ "pandas"
23
+ ).parsed_version
19
24
20
25
21
26
@pytest .fixture
@@ -90,7 +95,6 @@ def no_auth(monkeypatch):
90
95
("INTEGER" , None ), # Can't handle NULL
91
96
("BOOLEAN" , None ), # Can't handle NULL
92
97
("FLOAT" , numpy .dtype (float )),
93
- ("TIMESTAMP" , "datetime64[ns, UTC]" ),
94
98
("DATETIME" , "datetime64[ns]" ),
95
99
],
96
100
)
@@ -104,6 +108,16 @@ def test_should_return_bigquery_correctly_typed(type_, expected):
104
108
assert result == {"x" : expected }
105
109
106
110
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
+
107
121
def test_to_gbq_should_fail_if_invalid_table_name_passed ():
108
122
with pytest .raises (gbq .NotFoundException ):
109
123
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):
200
214
assert len (recwarn ) == 0
201
215
202
216
217
+ @pytest .mark .skipif (
218
+ pandas_installed_version < pkg_resources .parse_version ("0.24.0" ),
219
+ reason = "Requires pandas 0.24+" ,
220
+ )
203
221
def test_to_gbq_with_private_key_new_pandas_warns_deprecation (
204
222
min_bq_version , monkeypatch
205
223
):
@@ -413,6 +431,10 @@ def test_read_gbq_with_verbose_old_pandas_no_warnings(recwarn, min_bq_version):
413
431
assert len (recwarn ) == 0
414
432
415
433
434
+ @pytest .mark .skipif (
435
+ pandas_installed_version < pkg_resources .parse_version ("0.24.0" ),
436
+ reason = "Requires pandas 0.24+" ,
437
+ )
416
438
def test_read_gbq_with_private_key_new_pandas_warns_deprecation (
417
439
min_bq_version , monkeypatch
418
440
):
0 commit comments