|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
| 3 | +import datetime |
3 | 4 | import sys
|
4 |
| -from datetime import datetime |
5 | 5 |
|
6 | 6 | import numpy as np
|
7 | 7 | import pandas
|
@@ -39,7 +39,8 @@ def make_mixed_dataframe_v2(test_size):
|
39 | 39 | ints = np.random.randint(1, 10, size=(1, test_size))
|
40 | 40 | strs = np.random.randint(1, 10, size=(1, test_size)).astype(str)
|
41 | 41 | times = [
|
42 |
| - datetime.now(pytz.timezone("US/Arizona")) for t in range(test_size) |
| 42 | + datetime.datetime.now(pytz.timezone("US/Arizona")) |
| 43 | + for t in range(test_size) |
43 | 44 | ]
|
44 | 45 | return DataFrame(
|
45 | 46 | {
|
@@ -248,6 +249,38 @@ def test_should_properly_handle_null_floats(self, project_id):
|
248 | 249 | )
|
249 | 250 | tm.assert_frame_equal(df, DataFrame({"null_float": [np.nan, 1.0]}))
|
250 | 251 |
|
| 252 | + def test_should_properly_handle_date(self, project_id): |
| 253 | + query = "SELECT DATE(2003, 1, 4) AS date_col" |
| 254 | + df = gbq.read_gbq( |
| 255 | + query, |
| 256 | + project_id=project_id, |
| 257 | + credentials=self.credentials, |
| 258 | + ) |
| 259 | + expected = DataFrame( |
| 260 | + { |
| 261 | + "date_col": pandas.Series( |
| 262 | + [datetime.date(2003, 1, 4)], dtype="datetime64[ns]" |
| 263 | + ) |
| 264 | + }, |
| 265 | + ) |
| 266 | + tm.assert_frame_equal(df, expected) |
| 267 | + |
| 268 | + def test_should_properly_handle_time(self, project_id): |
| 269 | + query = "SELECT TIME_ADD(TIME(3, 14, 15), INTERVAL 926589 MICROSECOND) AS time_col" |
| 270 | + df = gbq.read_gbq( |
| 271 | + query, |
| 272 | + project_id=project_id, |
| 273 | + credentials=self.credentials, |
| 274 | + ) |
| 275 | + expected = DataFrame( |
| 276 | + { |
| 277 | + "time_col": pandas.Series( |
| 278 | + [datetime.time(3, 14, 15, 926589)], dtype="object" |
| 279 | + ) |
| 280 | + }, |
| 281 | + ) |
| 282 | + tm.assert_frame_equal(df, expected) |
| 283 | + |
251 | 284 | def test_should_properly_handle_timestamp_unix_epoch(self, project_id):
|
252 | 285 | query = 'SELECT TIMESTAMP("1970-01-01 00:00:00") AS unix_epoch'
|
253 | 286 | df = gbq.read_gbq(
|
@@ -1113,7 +1146,7 @@ def test_google_upload_errors_should_raise_exception(self, project_id):
|
1113 | 1146 | raise pytest.skip("buggy test")
|
1114 | 1147 |
|
1115 | 1148 | test_id = "5"
|
1116 |
| - test_timestamp = datetime.now(pytz.timezone("US/Arizona")) |
| 1149 | + test_timestamp = datetime.datetime.now(pytz.timezone("US/Arizona")) |
1117 | 1150 | bad_df = DataFrame(
|
1118 | 1151 | {
|
1119 | 1152 | "bools": [False, False],
|
|
0 commit comments