Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48612f7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into skip-docfx
2 parents fa7fe50 + aac33df commit 48612f7

23 files changed

+880
-24
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Only run this nox session.
4+
env_vars: {
5+
key: "NOX_SESSION"
6+
value: "prerelease_deps"
7+
}

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
[1]: https://pypi.org/project/google-cloud-bigquery/#history
66

7+
### [2.6.1](https://www.github.com/googleapis/python-bigquery/compare/v2.6.0...v2.6.1) (2020-12-09)
8+
9+
10+
### Bug Fixes
11+
12+
* handle null values in array query parameters ([#426](https://www.github.com/googleapis/python-bigquery/issues/426)) ([78fde4a](https://www.github.com/googleapis/python-bigquery/commit/78fde4a92e61a89d0b490b93acc90fff9635d1bf))
13+
14+
15+
### Documentation
16+
17+
* add examples of `fields` argument to update methods ([#418](https://www.github.com/googleapis/python-bigquery/issues/418)) ([8c7e02b](https://www.github.com/googleapis/python-bigquery/commit/8c7e02b0de2c92ee965414e7c430eb57d1877326))
18+
719
## [2.6.0](https://www.github.com/googleapis/python-bigquery/compare/v2.5.0...v2.6.0) (2020-12-07)
820

921

google/cloud/bigquery/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
def _not_null(value, field):
4242
"""Check whether 'value' should be coerced to 'field' type."""
43-
return value is not None or field.mode != "NULLABLE"
43+
return value is not None or (field is not None and field.mode != "NULLABLE")
4444

4545

4646
def _int_from_json(value, field):

google/cloud/bigquery/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "2.6.0"
15+
__version__ = "2.6.1"

noxfile.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ def snippets(session):
147147
# Skip tests in samples/snippets, as those are run in a different session
148148
# using the nox config from that directory.
149149
session.run("py.test", os.path.join("docs", "snippets.py"), *session.posargs)
150-
session.run("py.test", "samples", "--ignore=samples/snippets", *session.posargs)
150+
session.run(
151+
"py.test",
152+
"samples",
153+
"--ignore=samples/snippets",
154+
"--ignore=samples/geography",
155+
*session.posargs,
156+
)
151157

152158

153159
@nox.session(python="3.8")
@@ -162,6 +168,38 @@ def cover(session):
162168
session.run("coverage", "erase")
163169

164170

171+
@nox.session(python="3.8")
172+
def prerelease_deps(session):
173+
"""Run all tests with prerelease versions of dependencies installed.
174+
175+
https://github.com/googleapis/python-bigquery/issues/95
176+
"""
177+
# PyArrow prerelease packages are published to an alternative PyPI host.
178+
# https://arrow.apache.org/docs/python/install.html#installing-nightly-packages
179+
session.install(
180+
"--extra-index-url", "https://pypi.fury.io/arrow-nightlies/", "--pre", "pyarrow"
181+
)
182+
session.install("--pre", "grpcio", "pandas")
183+
session.install(
184+
"mock",
185+
"pytest",
186+
"google-cloud-testutils",
187+
"pytest-cov",
188+
"freezegun",
189+
"IPython",
190+
)
191+
session.install("-e", ".[all]")
192+
193+
# Print out prerelease package versions.
194+
session.run("python", "-c", "import grpc; print(grpc.__version__)")
195+
session.run("python", "-c", "import pandas; print(pandas.__version__)")
196+
session.run("python", "-c", "import pyarrow; print(pyarrow.__version__)")
197+
198+
# Run all tests, except a few samples tests which require extra dependencies.
199+
session.run("py.test", "tests")
200+
session.run("py.test", "samples/tests")
201+
202+
165203
@nox.session(python="3.8")
166204
def lint(session):
167205
"""Run linters.

samples/geography/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

samples/geography/conftest.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import datetime
16+
import uuid
17+
18+
from google.cloud import bigquery
19+
import pytest
20+
21+
22+
def temp_suffix():
23+
now = datetime.datetime.now()
24+
return f"{now.strftime('%Y%m%d%H%M%S')}_{uuid.uuid4().hex[:8]}"
25+
26+
27+
@pytest.fixture(scope="session")
28+
def bigquery_client():
29+
bigquery_client = bigquery.Client()
30+
return bigquery_client
31+
32+
33+
@pytest.fixture(scope="session")
34+
def project_id(bigquery_client):
35+
return bigquery_client.project
36+
37+
38+
@pytest.fixture
39+
def dataset_id(bigquery_client):
40+
dataset_id = f"geography_{temp_suffix()}"
41+
bigquery_client.create_dataset(dataset_id)
42+
yield dataset_id
43+
bigquery_client.delete_dataset(dataset_id, delete_contents=True)
44+
45+
46+
@pytest.fixture
47+
def table_id(bigquery_client, project_id, dataset_id):
48+
table_id = f"{project_id}.{dataset_id}.geography_{temp_suffix()}"
49+
table = bigquery.Table(table_id)
50+
table.schema = [
51+
bigquery.SchemaField("geo", bigquery.SqlTypeNames.GEOGRAPHY),
52+
]
53+
bigquery_client.create_table(table)
54+
yield table_id
55+
bigquery_client.delete_table(table_id)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def insert_geojson(override_values={}):
17+
# [START bigquery_insert_geojson]
18+
import geojson
19+
from google.cloud import bigquery
20+
21+
bigquery_client = bigquery.Client()
22+
23+
# This example uses a table containing a column named "geo" with the
24+
# GEOGRAPHY data type.
25+
table_id = "my-project.my_dataset.my_table"
26+
# [END bigquery_insert_geojson]
27+
# To facilitate testing, we replace values with alternatives
28+
# provided by the testing harness.
29+
table_id = override_values.get("table_id", table_id)
30+
# [START bigquery_insert_geojson]
31+
32+
# Use the python-geojson library to generate GeoJSON of a line from LAX to
33+
# JFK airports. Alternatively, you may define GeoJSON data directly, but it
34+
# must be converted to a string before loading it into BigQuery.
35+
my_geography = geojson.LineString([(-118.4085, 33.9416), (-73.7781, 40.6413)])
36+
rows = [
37+
# Convert GeoJSON data into a string.
38+
{"geo": geojson.dumps(my_geography)}
39+
]
40+
41+
# table already exists and has a column
42+
# named "geo" with data type GEOGRAPHY.
43+
errors = bigquery_client.insert_rows_json(table_id, rows)
44+
if errors:
45+
raise RuntimeError(f"row insert failed: {errors}")
46+
else:
47+
print(f"wrote 1 row to {table_id}")
48+
# [END bigquery_insert_geojson]
49+
return errors
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import insert_geojson
16+
17+
18+
def test_insert_geojson(table_id):
19+
errors = insert_geojson.insert_geojson(override_values={"table_id": table_id})
20+
assert not errors

samples/geography/insert_wkt.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def insert_wkt(override_values={}):
17+
# [START bigquery_insert_geography_wkt]
18+
from google.cloud import bigquery
19+
import shapely.geometry
20+
import shapely.wkt
21+
22+
bigquery_client = bigquery.Client()
23+
24+
# This example uses a table containing a column named "geo" with the
25+
# GEOGRAPHY data type.
26+
table_id = "my-project.my_dataset.my_table"
27+
# [END bigquery_insert_geography_wkt]
28+
# To facilitate testing, we replace values with alternatives
29+
# provided by the testing harness.
30+
table_id = override_values.get("table_id", table_id)
31+
# [START bigquery_insert_geography_wkt]
32+
33+
# Use the Shapely library to generate WKT of a line from LAX to
34+
# JFK airports. Alternatively, you may define WKT data directly.
35+
my_geography = shapely.geometry.LineString(
36+
[(-118.4085, 33.9416), (-73.7781, 40.6413)]
37+
)
38+
rows = [
39+
# Convert data into a WKT string.
40+
{"geo": shapely.wkt.dumps(my_geography)},
41+
]
42+
43+
# table already exists and has a column
44+
# named "geo" with data type GEOGRAPHY.
45+
errors = bigquery_client.insert_rows_json(table_id, rows)
46+
if errors:
47+
raise RuntimeError(f"row insert failed: {errors}")
48+
else:
49+
print(f"wrote 1 row to {table_id}")
50+
# [END bigquery_insert_geography_wkt]
51+
return errors

0 commit comments

Comments
 (0)