Skip to content

Commit

Permalink
chore: sync v3 with master (#851)
Browse files Browse the repository at this point in the history
(no issue)

Just a regular update of the `v3` branch.
  • Loading branch information
plamut authored Aug 5, 2021
1 parent 9319eb1 commit e26d879
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* @googleapis/api-bigquery @googleapis/yoshi-python

# The python-samples-reviewers team is the default owner for samples changes
/samples/ @googleapis/python-samples-owners
/samples/ @googleapis/api-bigquery @googleapis/python-samples-owners
15 changes: 14 additions & 1 deletion .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
branchProtectionRules:
# Identifies the protection rule pattern. Name of the branch to be protected.
# Defaults to `master`
- pattern: '{master,v3}'
- pattern: master
requiresCodeOwnerReviews: true
requiresStrictStatusChecks: true
requiredStatusCheckContexts:
- 'Kokoro'
- 'Kokoro snippets-3.8'
- 'cla/google'
- 'Samples - Lint'
- 'Samples - Python 3.6'
- 'Samples - Python 3.7'
- 'Samples - Python 3.8'
- pattern: v3
requiresCodeOwnerReviews: true
requiresStrictStatusChecks: true
requiredStatusCheckContexts:
- 'Kokoro'
- 'Kokoro snippets-3.8'
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
[1]: https://pypi.org/project/google-cloud-bigquery/#history


### [2.23.2](https://www.github.com/googleapis/python-bigquery/compare/v2.23.1...v2.23.2) (2021-07-29)


### Dependencies

* expand pyarrow pins to support 5.x releases ([#833](https://www.github.com/googleapis/python-bigquery/issues/833)) ([80e3a61](https://www.github.com/googleapis/python-bigquery/commit/80e3a61c60419fb19b70b664c6415cd01ba82f5b))

### [2.23.1](https://www.github.com/googleapis/python-bigquery/compare/v2.23.0...v2.23.1) (2021-07-28)


### Bug Fixes

* `insert_rows()` accepts float column values as strings again ([#824](https://www.github.com/googleapis/python-bigquery/issues/824)) ([d9378af](https://www.github.com/googleapis/python-bigquery/commit/d9378af13add879118a1d004529b811f72c325d6))

## [2.23.0](https://www.github.com/googleapis/python-bigquery/compare/v2.22.1...v2.23.0) (2021-07-27)


Expand Down
12 changes: 7 additions & 5 deletions google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import decimal
import math
import re
from typing import Union

from google.cloud._helpers import UTC
from google.cloud._helpers import _date_from_iso8601_date
Expand Down Expand Up @@ -312,14 +313,15 @@ def _int_to_json(value):
return value


def _float_to_json(value):
def _float_to_json(value) -> Union[None, str, float]:
"""Coerce 'value' to an JSON-compatible representation."""
if value is None:
return None
elif math.isnan(value) or math.isinf(value):
return str(value)
else:
return float(value)

if isinstance(value, str):
value = float(value)

return str(value) if (math.isnan(value) or math.isinf(value)) else float(value)


def _decimal_to_json(value):
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigquery/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "2.23.0"
__version__ = "2.23.2"
4 changes: 2 additions & 2 deletions samples/geography/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
geojson==2.5.0
google-cloud-bigquery==2.22.1
google-cloud-bigquery-storage==2.6.0
google-cloud-bigquery==2.23.2
google-cloud-bigquery-storage==2.6.2
Shapely==1.7.1
2 changes: 1 addition & 1 deletion samples/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
google-cloud-testutils==0.3.0
google-cloud-testutils==1.0.0
pytest==6.2.4
mock==4.0.3
8 changes: 4 additions & 4 deletions samples/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
google-cloud-bigquery==2.22.1
google-cloud-bigquery-storage==2.6.0
google-auth-oauthlib==0.4.4
google-cloud-bigquery==2.23.2
google-cloud-bigquery-storage==2.6.2
google-auth-oauthlib==0.4.5
grpcio==1.39.0
ipython==7.16.1; python_version < '3.7'
ipython==7.17.0; python_version >= '3.7'
matplotlib==3.3.4; python_version < '3.7'
matplotlib==3.4.1; python_version >= '3.7'
pandas==1.1.5; python_version < '3.7'
pandas==1.2.0; python_version >= '3.7'
pyarrow==4.0.1
pyarrow==5.0.0
pytz==2021.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"google-resumable-media >= 0.6.0, < 3.0dev",
"packaging >= 14.3",
"protobuf >= 3.12.0",
"pyarrow >= 3.0.0, < 5.0dev",
"pyarrow >= 3.0.0, < 6.0dev",
"requests >= 2.18.0, < 3.0.0dev",
]
extras = {
Expand Down
40 changes: 26 additions & 14 deletions tests/system/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io
import operator

import google.api_core.retry
import pkg_resources
import pytest
import pytz
Expand All @@ -37,6 +38,10 @@
PANDAS_INT64_VERSION = pkg_resources.parse_version("1.0.0")


class MissingDataError(Exception):
pass


def test_load_table_from_dataframe_w_automatic_schema(bigquery_client, dataset_id):
"""Test that a DataFrame with dtypes that map well to BigQuery types
can be uploaded without specifying a schema.
Expand Down Expand Up @@ -657,27 +662,34 @@ def test_insert_rows_from_dataframe(bigquery_client, dataset_id):
)
for errors in chunk_errors:
assert not errors

# Use query to fetch rows instead of listing directly from the table so
# that we get values from the streaming buffer.
rows = list(
bigquery_client.query(
"SELECT * FROM `{}.{}.{}`".format(
table.project, table.dataset_id, table.table_id
)
)
)

sorted_rows = sorted(rows, key=operator.attrgetter("int_col"))
row_tuples = [r.values() for r in sorted_rows]
expected = [
# Pandas often represents NULL values as NaN. Convert to None for
# easier comparison.
tuple(None if col != col else col for col in data_row)
for data_row in dataframe.itertuples(index=False)
]

assert len(row_tuples) == len(expected)
# Use query to fetch rows instead of listing directly from the table so
# that we get values from the streaming buffer "within a few seconds".
# https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataavailability
@google.api_core.retry.Retry(
predicate=google.api_core.retry.if_exception_type(MissingDataError)
)
def get_rows():
rows = list(
bigquery_client.query(
"SELECT * FROM `{}.{}.{}`".format(
table.project, table.dataset_id, table.table_id
)
)
)
if len(rows) != len(expected):
raise MissingDataError()
return rows

rows = get_rows()
sorted_rows = sorted(rows, key=operator.attrgetter("int_col"))
row_tuples = [r.values() for r in sorted_rows]

for row, expected_row in zip(row_tuples, expected):
assert (
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,21 +653,45 @@ def _call_fut(self, value):
def test_w_none(self):
self.assertEqual(self._call_fut(None), None)

def test_w_non_numeric(self):
with self.assertRaises(TypeError):
self._call_fut(object())

def test_w_integer(self):
result = self._call_fut(123)
self.assertIsInstance(result, float)
self.assertEqual(result, 123.0)

def test_w_float(self):
self.assertEqual(self._call_fut(1.23), 1.23)

def test_w_float_as_string(self):
self.assertEqual(self._call_fut("1.23"), 1.23)

def test_w_nan(self):
result = self._call_fut(float("nan"))
self.assertEqual(result.lower(), "nan")

def test_w_nan_as_string(self):
result = self._call_fut("NaN")
self.assertEqual(result.lower(), "nan")

def test_w_infinity(self):
result = self._call_fut(float("inf"))
self.assertEqual(result.lower(), "inf")

def test_w_infinity_as_string(self):
result = self._call_fut("inf")
self.assertEqual(result.lower(), "inf")

def test_w_negative_infinity(self):
result = self._call_fut(float("-inf"))
self.assertEqual(result.lower(), "-inf")

def test_w_negative_infinity_as_string(self):
result = self._call_fut("-inf")
self.assertEqual(result.lower(), "-inf")


class Test_decimal_to_json(unittest.TestCase):
def _call_fut(self, value):
Expand Down

0 comments on commit e26d879

Please sign in to comment.