Skip to content

Commit 84d31a7

Browse files
Merge branch 'main' into b479135143
2 parents baf76e6 + 92d6169 commit 84d31a7

20 files changed

+213
-111
lines changed

bigquery-datatransfer/snippets/manage_transfer_configs.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,6 @@
1313
# limitations under the License.
1414

1515

16-
def list_configs(override_values={}):
17-
# [START bigquerydatatransfer_list_configs]
18-
from google.cloud import bigquery_datatransfer
19-
20-
transfer_client = bigquery_datatransfer.DataTransferServiceClient()
21-
22-
project_id = "my-project"
23-
# [END bigquerydatatransfer_list_configs]
24-
# To facilitate testing, we replace values with alternatives
25-
# provided by the testing harness.
26-
project_id = override_values.get("project_id", project_id)
27-
# [START bigquerydatatransfer_list_configs]
28-
parent = transfer_client.common_project_path(project_id)
29-
30-
configs = transfer_client.list_transfer_configs(parent=parent)
31-
print("Got the following configs:")
32-
for config in configs:
33-
print(f"\tID: {config.name}, Schedule: {config.schedule}")
34-
# [END bigquerydatatransfer_list_configs]
35-
36-
3716
def update_config(override_values={}):
3817
# [START bigquerydatatransfer_update_config]
3918
from google.cloud import bigquery_datatransfer

bigquery-datatransfer/snippets/manage_transfer_configs_test.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
from . import manage_transfer_configs
1616

1717

18-
def test_list_configs(capsys, project_id, transfer_config_name):
19-
manage_transfer_configs.list_configs({"project_id": project_id})
20-
out, _ = capsys.readouterr()
21-
assert "Got the following configs:" in out
22-
assert transfer_config_name in out
23-
24-
2518
def test_update_config(capsys, transfer_config_name):
2619
manage_transfer_configs.update_config(
2720
{

language/snippets/generated-samples/v1/language_sentiment_text_test.py renamed to bigquery/python-db-dtypes-pandas/__init__.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
# Copyright 2018 Google, Inc.
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
import language_sentiment_text
16-
17-
18-
def test_analyze_sentiment_text_positive(capsys):
19-
language_sentiment_text.sample_analyze_sentiment("Happy Happy Joy Joy")
20-
out, _ = capsys.readouterr()
21-
assert "Score: 0." in out
22-
23-
24-
def test_analyze_sentiment_text_negative(capsys):
25-
language_sentiment_text.sample_analyze_sentiment("Angry Angry Sad Sad")
26-
out, _ = capsys.readouterr()
27-
assert "Score: -0." in out

bigquery/python-db-dtypes-pandas/pytest.ini

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2021 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.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2021 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+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be imported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
"ignored_versions": ["2.7", "3.7", "3.8"],
26+
# Old samples are opted out of enforcing Python type hints
27+
# All new samples should feature them
28+
"enforce_type_hints": True,
29+
# An envvar key for determining the project id to use. Change it
30+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
31+
# build specific Cloud project. You can also use your own string
32+
# to use your own Cloud project.
33+
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
34+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
35+
# If you need to use a specific version of pip,
36+
# change pip_version_override to the string representation
37+
# of the version number, for example, "20.2.4"
38+
"pip_version_override": None,
39+
# A dictionary you want to inject into your test. Don't put any
40+
# secrets here. These values will override predefined values.
41+
"envs": {},
42+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2021 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 pandas_date_and_time():
17+
# [START bigquery_pandas_date_create]
18+
19+
import datetime
20+
21+
import pandas as pd
22+
23+
import db_dtypes # noqa import to register dtypes
24+
25+
dates = pd.Series([datetime.date(2021, 9, 17), "2021-9-18"], dtype="dbdate")
26+
27+
# [END bigquery_pandas_date_create]
28+
# [START bigquery_pandas_date_as_datetime]
29+
30+
datetimes = dates.astype("datetime64")
31+
32+
# [END bigquery_pandas_date_as_datetime]
33+
# [START bigquery_pandas_date_sub]
34+
35+
dates2 = pd.Series(["2021-1-1", "2021-1-2"], dtype="dbdate")
36+
diffs = dates - dates2
37+
38+
# [END bigquery_pandas_date_sub]
39+
# [START bigquery_pandas_date_add_offset]
40+
41+
do = pd.DateOffset(days=1)
42+
after = dates + do
43+
before = dates - do
44+
45+
# [END bigquery_pandas_date_add_offset]
46+
# [START bigquery_pandas_time_create]
47+
48+
times = pd.Series([datetime.time(1, 2, 3, 456789), "12:00:00.6"], dtype="dbtime")
49+
50+
# [END bigquery_pandas_time_create]
51+
# [START bigquery_pandas_time_as_timedelta]
52+
53+
timedeltas = times.astype("timedelta64")
54+
55+
# [END bigquery_pandas_time_as_timedelta]
56+
57+
# Combine datetime64 and timedelta64 to confirm adding dates and times are
58+
# equivalent.
59+
combined0 = datetimes + timedeltas
60+
61+
# [START bigquery_pandas_combine_date_time]
62+
63+
combined = dates + times
64+
65+
# [END bigquery_pandas_combine_date_time]
66+
67+
return (
68+
dates,
69+
datetimes,
70+
dates2,
71+
diffs,
72+
do,
73+
after,
74+
before,
75+
times,
76+
timedeltas,
77+
combined,
78+
combined0,
79+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2021 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+
17+
import numpy as np
18+
from pandas import Timestamp
19+
20+
21+
def test_pandas_date_and_time():
22+
from .pandas_date_and_time import pandas_date_and_time
23+
24+
(
25+
dates,
26+
_,
27+
dates2,
28+
diffs,
29+
do,
30+
after,
31+
before,
32+
times,
33+
_,
34+
combined,
35+
combined0,
36+
) = pandas_date_and_time()
37+
38+
assert str(dates.dtype) == "dbdate"
39+
assert list(dates) == [datetime.date(2021, 9, 17), datetime.date(2021, 9, 18)]
40+
41+
assert np.array_equal(
42+
diffs,
43+
dates.astype("datetime64") - dates2.astype("datetime64"),
44+
)
45+
46+
assert np.array_equal(after, dates.astype("object") + do)
47+
assert np.array_equal(before, dates.astype("object") - do)
48+
49+
assert str(times.dtype) == "dbtime"
50+
assert list(times) == [
51+
datetime.time(1, 2, 3, 456789),
52+
datetime.time(12, 0, 0, 600000),
53+
]
54+
55+
for c in combined0, combined:
56+
assert str(c.dtype) == "datetime64[ns]"
57+
assert list(c) == [
58+
Timestamp("2021-09-17 01:02:03.456789"),
59+
Timestamp("2021-09-18 12:00:00.600000"),
60+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest==8.4.2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
db-dtypes
2+
numpy
3+
pandas
4+
pyarrow

0 commit comments

Comments
 (0)