Skip to content

Commit b67003f

Browse files
committed
Update tests to match dtypes from to_dataframe().
1 parent 77d2528 commit b67003f

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

tests/system/test_gbq.py

+59-17
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import google.oauth2.service_account
88
import numpy as np
9+
import pandas
910
import pandas.util.testing as tm
10-
import pytest
11-
import pytz
1211
from pandas import DataFrame, NaT, compat
1312
from pandas.compat import range, u
13+
import pytest
14+
import pytz
1415

1516
from pandas_gbq import gbq
1617

@@ -311,7 +312,8 @@ def test_should_properly_handle_timestamp_unix_epoch(self, project_id):
311312
tm.assert_frame_equal(
312313
df,
313314
DataFrame(
314-
{"unix_epoch": [np.datetime64("1970-01-01T00:00:00.000000Z")]}
315+
{"unix_epoch": ["1970-01-01T00:00:00.000000Z"]},
316+
dtype="datetime64[ns, UTC]",
315317
),
316318
)
317319

@@ -323,6 +325,38 @@ def test_should_properly_handle_arbitrary_timestamp(self, project_id):
323325
credentials=self.credentials,
324326
dialect="legacy",
325327
)
328+
tm.assert_frame_equal(
329+
df,
330+
DataFrame(
331+
{"valid_timestamp": ["2004-09-15T05:00:00.000000Z"]},
332+
dtype="datetime64[ns, UTC]",
333+
),
334+
)
335+
336+
def test_should_properly_handle_datetime_unix_epoch(self, project_id):
337+
query = 'SELECT DATETIME("1970-01-01 00:00:00") AS unix_epoch'
338+
df = gbq.read_gbq(
339+
query,
340+
project_id=project_id,
341+
credentials=self.credentials,
342+
dialect="legacy",
343+
)
344+
tm.assert_frame_equal(
345+
df,
346+
DataFrame(
347+
{"unix_epoch": ["1970-01-01T00:00:00.000000Z"]},
348+
dtype="datetime64[ns]",
349+
),
350+
)
351+
352+
def test_should_properly_handle_arbitrary_datetime(self, project_id):
353+
query = 'SELECT DATETIME("2004-09-15 05:00:00") AS valid_timestamp'
354+
df = gbq.read_gbq(
355+
query,
356+
project_id=project_id,
357+
credentials=self.credentials,
358+
dialect="legacy",
359+
)
326360
tm.assert_frame_equal(
327361
df,
328362
DataFrame(
@@ -338,7 +372,7 @@ def test_should_properly_handle_arbitrary_timestamp(self, project_id):
338372
"expression, type_",
339373
[
340374
("current_date()", "<M8[ns]"),
341-
("current_timestamp()", "<M8[ns]"),
375+
("current_timestamp()", "datetime64[ns, UTC]"),
342376
("current_datetime()", "<M8[ns]"),
343377
("TRUE", bool),
344378
("FALSE", bool),
@@ -370,7 +404,20 @@ def test_should_properly_handle_null_timestamp(self, project_id):
370404
credentials=self.credentials,
371405
dialect="legacy",
372406
)
373-
tm.assert_frame_equal(df, DataFrame({"null_timestamp": [NaT]}))
407+
tm.assert_frame_equal(
408+
df,
409+
DataFrame({"null_timestamp": [NaT]}, dtype="datetime64[ns, UTC]"),
410+
)
411+
412+
def test_should_properly_handle_null_datetime(self, project_id):
413+
query = "SELECT CAST(NULL AS DATETIME) AS null_datetime"
414+
df = gbq.read_gbq(
415+
query,
416+
project_id=project_id,
417+
credentials=self.credentials,
418+
dialect="standard",
419+
)
420+
tm.assert_frame_equal(df, DataFrame({"null_datetime": [NaT]}))
374421

375422
def test_should_properly_handle_null_boolean(self, project_id):
376423
query = "SELECT BOOLEAN(NULL) AS null_boolean"
@@ -541,18 +588,13 @@ def test_zero_rows(self, project_id):
541588
credentials=self.credentials,
542589
dialect="legacy",
543590
)
544-
page_array = np.zeros(
545-
(0,),
546-
dtype=[
547-
("title", object),
548-
("id", np.dtype(int)),
549-
("is_bot", np.dtype(bool)),
550-
("ts", "M8[ns]"),
551-
],
552-
)
553-
expected_result = DataFrame(
554-
page_array, columns=["title", "id", "is_bot", "ts"]
555-
)
591+
empty_columns = {
592+
"title": pandas.Series([], dtype=object),
593+
"id": pandas.Series([], dtype=object),
594+
"is_bot": pandas.Series([], dtype=object),
595+
"ts": pandas.Series([], dtype="datetime64[ns, UTC]"),
596+
}
597+
expected_result = DataFrame(empty_columns)
556598
tm.assert_frame_equal(df, expected_result, check_index_type=False)
557599

558600
def test_one_row_one_column(self, project_id):

0 commit comments

Comments
 (0)