Skip to content

docs: address lint errors in code samples #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .kokoro/continuous/e2e.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "unit_prerelease system_prerelease system_noextras e2e notebook samples"
value: "unit_prerelease system_prerelease system_noextras e2e notebook"
}

env_vars: {
Expand Down
2 changes: 1 addition & 1 deletion .kokoro/presubmit/e2e-gerrit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "system_noextras e2e notebook samples"
value: "system_noextras e2e notebook"
}
2 changes: 1 addition & 1 deletion .kokoro/presubmit/e2e.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "unit_prerelease system_prerelease system_noextras e2e notebook samples"
value: "unit_prerelease system_prerelease system_noextras e2e notebook"
}

env_vars: {
Expand Down
20 changes: 0 additions & 20 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,6 @@ def load(session: nox.sessions.Session):
)


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def samples(session):
"""Run the samples test suite."""

constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)

# TODO(b/332735129): Remove this session and use python_samples templates
# where each samples directory has its own noxfile.py file, instead.
install_test_extra = True
install_systemtest_dependencies(session, install_test_extra, "-c", constraints_path)

session.run(
"py.test",
"samples",
*session.posargs,
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def cover(session):
"""Run the final coverage report.
Expand Down
6 changes: 4 additions & 2 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import pandas
import pyarrow
import sqlglot

print(f"Python: {sys.version}")
print(f"bigframes=={bigframes.__version__}")
print(f"google-cloud-bigquery=={google.cloud.bigquery.__version__}")
Expand All @@ -83,7 +83,7 @@
print(f"pyarrow=={pyarrow.__version__}")
print(f"sqlglot=={sqlglot.__version__}")
```

#### Steps to reproduce
""",
),
Expand Down Expand Up @@ -148,3 +148,5 @@
# ----------------------------------------------------------------------------

s.shell.run(["nox", "-s", "format"], hide_output=False)
for noxfile in REPO_ROOT.glob("samples/**/noxfile.py"):
s.shell.run(["nox", "-s", "format"], cwd=noxfile.parent, hide_output=False)
2 changes: 1 addition & 1 deletion samples/snippets/bqml_getting_started_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


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

# [START bigquery_dataframes_bqml_getting_started_tutorial]
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/clustering_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_clustering_model():
def test_clustering_model() -> None:
# [START bigquery_dataframes_clustering_model]
from bigframes.ml.cluster import KMeans
import bigframes.pandas as bpd
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def project_id(bigquery_client: bigquery.Client) -> str:


@pytest.fixture(autouse=True)
def reset_session():
def reset_session() -> None:
"""An autouse fixture ensuring each sample runs in a fresh session.

This allows us to have samples that query data in different locations.
Expand Down
8 changes: 6 additions & 2 deletions samples/snippets/create_kmeans_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# limitations under the License.


def test_kmeans_sample(project_id: str, random_model_id_eu: str):
def test_kmeans_sample(project_id: str, random_model_id_eu: str) -> None:
your_gcp_project_id = project_id
your_model_id = random_model_id_eu
# [START bigquery_dataframes_bqml_kmeans]
import datetime

import pandas as pd

import bigframes
import bigframes.pandas as bpd

Expand Down Expand Up @@ -92,7 +94,9 @@ def test_kmeans_sample(project_id: str, random_model_id_eu: str):
stationstats = merged_df.groupby(["station_name", "isweekday"]).agg(
{"duration": ["mean", "count"], "distance_from_city_center": "max"}
)
stationstats.columns = ["duration", "num_trips", "distance_from_city_center"]
stationstats.columns = pd.Index(
["duration", "num_trips", "distance_from_city_center"]
)
stationstats = stationstats.sort_values(
by="distance_from_city_center", ascending=True
).reset_index()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_multiple_timeseries_forecasting_model(random_model_id):
def test_multiple_timeseries_forecasting_model(random_model_id: str) -> None:
your_model_id = random_model_id

# [START bigquery_dataframes_bqml_arima_multiple_step_2_visualize]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.


def test_create_single_timeseries():

def test_create_single_timeseries() -> None:
# [START bigquery_dataframes_single_timeseries_forecasting_model_tutorial]
import bigframes.pandas as bpd

Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/explore_query_result_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_bigquery_dataframes_explore_query_result():
def test_bigquery_dataframes_explore_query_result() -> None:
import bigframes.pandas as bpd

# [START bigquery_dataframes_explore_query_result]
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/gemini_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_gemini_text_generator_model():
def test_gemini_text_generator_model() -> None:
# Determine project id, in this case prefer the one set in the environment
# variable GOOGLE_CLOUD_PROJECT (if any)
import os
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/gen_ai_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_llm_model():
def test_llm_model() -> None:
# Determine project id, in this case prefer the one set in the environment
# variable GOOGLE_CLOUD_PROJECT (if any)
import os
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/load_data_from_bigquery_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_bigquery_dataframes_load_data_from_bigquery():
def test_bigquery_dataframes_load_data_from_bigquery() -> None:
# [START bigquery_dataframes_load_data_from_bigquery]
# Create a DataFrame from a BigQuery table:
import bigframes.pandas as bpd
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/load_data_from_biquery_job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_bigquery_dataframes_load_data_from_bigquery_job():
def test_bigquery_dataframes_load_data_from_bigquery_job() -> None:
# Determine project id, in this case prefer the one set in the environment
# variable GOOGLE_CLOUD_PROJECT (if any)
import os
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/load_data_from_csv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


def test_bigquery_dataframes_load_data_from_csv():
def test_bigquery_dataframes_load_data_from_csv() -> None:
# [START bigquery_dataframes_load_data_from_csv]
import bigframes.pandas as bpd

Expand Down
Loading