Skip to content

Commit 4fc8964

Browse files
authored
docs: address lint errors in code samples (#665)
Towards internal issue 332735129 test: move samples tests to their own kokoro jobs
1 parent c6c487f commit 4fc8964

27 files changed

+401
-46
lines changed

.kokoro/continuous/e2e.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Only run this nox session.
44
env_vars: {
55
key: "NOX_SESSION"
6-
value: "unit_prerelease system_prerelease system_noextras e2e notebook samples"
6+
value: "unit_prerelease system_prerelease system_noextras e2e notebook"
77
}
88

99
env_vars: {

.kokoro/presubmit/e2e-gerrit.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# Only run this nox session.
44
env_vars: {
55
key: "NOX_SESSION"
6-
value: "system_noextras e2e notebook samples"
6+
value: "system_noextras e2e notebook"
77
}

.kokoro/presubmit/e2e.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Only run this nox session.
44
env_vars: {
55
key: "NOX_SESSION"
6-
value: "unit_prerelease system_prerelease system_noextras e2e notebook samples"
6+
value: "unit_prerelease system_prerelease system_noextras e2e notebook"
77
}
88

99
env_vars: {

noxfile.py

-20
Original file line numberDiff line numberDiff line change
@@ -402,26 +402,6 @@ def load(session: nox.sessions.Session):
402402
)
403403

404404

405-
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
406-
def samples(session):
407-
"""Run the samples test suite."""
408-
409-
constraints_path = str(
410-
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
411-
)
412-
413-
# TODO(b/332735129): Remove this session and use python_samples templates
414-
# where each samples directory has its own noxfile.py file, instead.
415-
install_test_extra = True
416-
install_systemtest_dependencies(session, install_test_extra, "-c", constraints_path)
417-
418-
session.run(
419-
"py.test",
420-
"samples",
421-
*session.posargs,
422-
)
423-
424-
425405
@nox.session(python=DEFAULT_PYTHON_VERSION)
426406
def cover(session):
427407
"""Run the final coverage report.

owlbot.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import pandas
7575
import pyarrow
7676
import sqlglot
77-
77+
7878
print(f"Python: {sys.version}")
7979
print(f"bigframes=={bigframes.__version__}")
8080
print(f"google-cloud-bigquery=={google.cloud.bigquery.__version__}")
@@ -83,7 +83,7 @@
8383
print(f"pyarrow=={pyarrow.__version__}")
8484
print(f"sqlglot=={sqlglot.__version__}")
8585
```
86-
86+
8787
#### Steps to reproduce
8888
""",
8989
),
@@ -148,3 +148,5 @@
148148
# ----------------------------------------------------------------------------
149149

150150
s.shell.run(["nox", "-s", "format"], hide_output=False)
151+
for noxfile in REPO_ROOT.glob("samples/**/noxfile.py"):
152+
s.shell.run(["nox", "-s", "format"], cwd=noxfile.parent, hide_output=False)

samples/snippets/bqml_getting_started_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_bqml_getting_started(random_model_id):
16+
def test_bqml_getting_started(random_model_id: str) -> None:
1717
your_model_id = random_model_id # for example: bqml_tutorial.sample_model
1818

1919
# [START bigquery_dataframes_bqml_getting_started_tutorial]

samples/snippets/clustering_model_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_clustering_model():
16+
def test_clustering_model() -> None:
1717
# [START bigquery_dataframes_clustering_model]
1818
from bigframes.ml.cluster import KMeans
1919
import bigframes.pandas as bpd

samples/snippets/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def project_id(bigquery_client: bigquery.Client) -> str:
4646

4747

4848
@pytest.fixture(autouse=True)
49-
def reset_session():
49+
def reset_session() -> None:
5050
"""An autouse fixture ensuring each sample runs in a fresh session.
5151
5252
This allows us to have samples that query data in different locations.

samples/snippets/create_kmeans_model_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
# limitations under the License.
1414

1515

16-
def test_kmeans_sample(project_id: str, random_model_id_eu: str):
16+
def test_kmeans_sample(project_id: str, random_model_id_eu: str) -> None:
1717
your_gcp_project_id = project_id
1818
your_model_id = random_model_id_eu
1919
# [START bigquery_dataframes_bqml_kmeans]
2020
import datetime
2121

22+
import pandas as pd
23+
2224
import bigframes
2325
import bigframes.pandas as bpd
2426

@@ -92,7 +94,9 @@ def test_kmeans_sample(project_id: str, random_model_id_eu: str):
9294
stationstats = merged_df.groupby(["station_name", "isweekday"]).agg(
9395
{"duration": ["mean", "count"], "distance_from_city_center": "max"}
9496
)
95-
stationstats.columns = ["duration", "num_trips", "distance_from_city_center"]
97+
stationstats.columns = pd.Index(
98+
["duration", "num_trips", "distance_from_city_center"]
99+
)
96100
stationstats = stationstats.sort_values(
97101
by="distance_from_city_center", ascending=True
98102
).reset_index()

samples/snippets/create_multiple_timeseries_forecasting_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_multiple_timeseries_forecasting_model(random_model_id):
16+
def test_multiple_timeseries_forecasting_model(random_model_id: str) -> None:
1717
your_model_id = random_model_id
1818

1919
# [START bigquery_dataframes_bqml_arima_multiple_step_2_visualize]

samples/snippets/create_single_timeseries_forecasting_model_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_create_single_timeseries():
17-
16+
def test_create_single_timeseries() -> None:
1817
# [START bigquery_dataframes_single_timeseries_forecasting_model_tutorial]
1918
import bigframes.pandas as bpd
2019

samples/snippets/explore_query_result_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_bigquery_dataframes_explore_query_result():
16+
def test_bigquery_dataframes_explore_query_result() -> None:
1717
import bigframes.pandas as bpd
1818

1919
# [START bigquery_dataframes_explore_query_result]

samples/snippets/gemini_model_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_gemini_text_generator_model():
16+
def test_gemini_text_generator_model() -> None:
1717
# Determine project id, in this case prefer the one set in the environment
1818
# variable GOOGLE_CLOUD_PROJECT (if any)
1919
import os

samples/snippets/gen_ai_model_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_llm_model():
16+
def test_llm_model() -> None:
1717
# Determine project id, in this case prefer the one set in the environment
1818
# variable GOOGLE_CLOUD_PROJECT (if any)
1919
import os

samples/snippets/load_data_from_bigquery_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_bigquery_dataframes_load_data_from_bigquery():
16+
def test_bigquery_dataframes_load_data_from_bigquery() -> None:
1717
# [START bigquery_dataframes_load_data_from_bigquery]
1818
# Create a DataFrame from a BigQuery table:
1919
import bigframes.pandas as bpd

samples/snippets/load_data_from_biquery_job_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_bigquery_dataframes_load_data_from_bigquery_job():
16+
def test_bigquery_dataframes_load_data_from_bigquery_job() -> None:
1717
# Determine project id, in this case prefer the one set in the environment
1818
# variable GOOGLE_CLOUD_PROJECT (if any)
1919
import os

samples/snippets/load_data_from_csv_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
def test_bigquery_dataframes_load_data_from_csv():
16+
def test_bigquery_dataframes_load_data_from_csv() -> None:
1717
# [START bigquery_dataframes_load_data_from_csv]
1818
import bigframes.pandas as bpd
1919

0 commit comments

Comments
 (0)