forked from googleapis/python-bigquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_load_table_dataframe.py
More file actions
72 lines (63 loc) · 2.43 KB
/
test_load_table_dataframe.py
File metadata and controls
72 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from .. import load_table_dataframe
pandas = pytest.importorskip("pandas")
pyarrow = pytest.importorskip("pyarrow")
def test_load_table_dataframe(capsys, client, random_table_id):
table = load_table_dataframe.load_table_dataframe(random_table_id)
out, _ = capsys.readouterr()
expected_column_names = [
"wikidata_id",
"title",
"release_year",
"length_minutes",
"release_date",
"dvd_release",
]
assert "Loaded 4 rows and {} columns".format(len(expected_column_names)) in out
column_names = [field.name for field in table.schema]
assert column_names == expected_column_names
column_types = [field.field_type for field in table.schema]
assert column_types == [
"STRING",
"STRING",
"INTEGER",
"FLOAT",
"TIMESTAMP",
"DATETIME",
]
df = client.list_rows(table).to_dataframe()
df.sort_values("release_year", inplace=True)
assert df["title"].tolist() == [
u"And Now for Something Completely Different",
u"Monty Python and the Holy Grail",
u"Life of Brian",
u"The Meaning of Life",
]
assert df["release_year"].tolist() == [1971, 1975, 1979, 1983]
assert df["length_minutes"].tolist() == [88.0, 91.5, 94.25, 112.5]
assert df["release_date"].tolist() == [
pandas.Timestamp("1971-09-28T22:59:07+00:00"),
pandas.Timestamp("1975-04-09T22:59:02+00:00"),
pandas.Timestamp("1979-08-18T03:59:05+00:00"),
pandas.Timestamp("1983-05-09T11:00:00+00:00"),
]
assert df["dvd_release"].tolist() == [
pandas.Timestamp("2003-10-22T10:00:00"),
pandas.Timestamp("2002-07-16T09:00:00"),
pandas.Timestamp("2008-01-14T08:00:00"),
pandas.Timestamp("2002-01-22T07:00:00"),
]
assert df["wikidata_id"].tolist() == [u"Q16403", u"Q25043", u"Q24953", u"Q24980"]