Skip to content

Commit 5584531

Browse files
committed
style: fix line length lints in formatting_helpers and __init__
1 parent 6377840 commit 5584531

4 files changed

Lines changed: 127 additions & 49 deletions

File tree

packages/bigframes/bigframes/formatting_helpers.py

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ def repr_query_job(query_job: Optional[bigquery.QueryJob]):
7171
if query_job is None:
7272
return "No job information available"
7373
if query_job.dry_run:
74-
return f"Computation deferred. Computation will process {get_formatted_bytes(query_job.total_bytes_processed)}"
74+
return (
75+
f"Computation deferred. Computation will process "
76+
f"{get_formatted_bytes(query_job.total_bytes_processed)}"
77+
)
7578
res = "Query Job Info"
7679
for key, value in query_job_prop_pairs.items():
7780
job_val = getattr(query_job, value)
@@ -105,11 +108,15 @@ def repr_query_job_html(query_job: Optional[bigquery.QueryJob]):
105108
if query_job is None:
106109
return "No job information available"
107110
if query_job.dry_run:
108-
return f"Computation deferred. Computation will process {get_formatted_bytes(query_job.total_bytes_processed)}"
111+
return (
112+
f"Computation deferred. Computation will process "
113+
f"{get_formatted_bytes(query_job.total_bytes_processed)}"
114+
)
109115

110116
# We can reuse the plaintext repr for now or make a nicer table.
111-
# For deferred mode consistency, let's just wrap the text in a pre block or similar,
112-
# but the request implies we want a distinct HTML representation if possible.
117+
# For deferred mode consistency, let's just wrap the text in a pre
118+
# block or similar, but the request implies we want a distinct HTML
119+
# representation if possible.
113120
# However, existing repr_query_job returns a simple string.
114121
# Let's format it as a simple table or list.
115122

@@ -123,7 +130,10 @@ def repr_query_job_html(query_job: Optional[bigquery.QueryJob]):
123130
location=query_job.location,
124131
job_id=query_job.job_id,
125132
)
126-
res += f'<li>Job: <a target="_blank" href="{url}">{query_job.job_id}</a></li>'
133+
res += (
134+
f'<li>Job: <a target="_blank" href="{url}">'
135+
f"{query_job.job_id}</a></li>"
136+
)
127137
elif key == "Slot Time":
128138
res += f"<li>{key}: {get_formatted_time(job_val)}</li>"
129139
elif key == "Bytes Processed":
@@ -138,7 +148,7 @@ def repr_query_job_html(query_job: Optional[bigquery.QueryJob]):
138148

139149

140150
def progress_callback(
141-
envelope: bigframes.core.events.EventEnvelope,
151+
envelope: Any,
142152
):
143153
"""Displays a progress bar while the query is running"""
144154
global current_display_id
@@ -147,13 +157,19 @@ def progress_callback(
147157
import bigframes._config
148158
import bigframes.core.events
149159
except ImportError:
150-
# Since this gets called from __del__, skip if the import fails to avoid
160+
# Since this gets called from __del__, skip if the import fails
161+
# to avoid
151162
# ImportError: sys.meta_path is None, Python is likely shutting down.
152163
# This will allow cleanup to continue.
153164
return
154165

155-
event = envelope.event
156-
progress_bar = envelope.progress_bar
166+
if isinstance(envelope, bigframes.core.events.EventEnvelope):
167+
event = envelope.event
168+
progress_bar = envelope.progress_bar
169+
else:
170+
event = envelope
171+
progress_bar = bigframes.core.events._DEFAULT
172+
157173
if progress_bar == bigframes.core.events._DEFAULT:
158174
progress_bar = bigframes._config.options.display.progress_bar
159175

@@ -235,7 +251,8 @@ def wait_for_job(job: GenericJob, progress_bar: Optional[str] = None):
235251
job.result()
236252
job.reload()
237253
display.update_display(
238-
display.HTML(get_base_job_loading_html(job)), display_id=display_id
254+
display.HTML(get_base_job_loading_html(job)),
255+
display_id=display_id,
239256
)
240257
elif progress_bar == "terminal":
241258
inital_loading_bar = get_base_job_loading_string(job)
@@ -289,7 +306,10 @@ def render_job_link_html(
289306
job_id=job_id,
290307
)
291308
if job_url:
292-
job_link = f' [<a target="_blank" href="{job_url}">Job {project_id}:{location}.{job_id} details</a>]'
309+
job_link = (
310+
f' [<a target="_blank" href="{job_url}">'
311+
f"Job {project_id}:{location}.{job_id} details</a>]"
312+
)
293313
else:
294314
job_link = ""
295315
return job_link
@@ -326,7 +346,10 @@ def get_job_url(
326346
"""
327347
if project_id is None or location is None or job_id is None:
328348
return None
329-
return f"""https://console.cloud.google.com/bigquery?project={project_id}&j=bq:{location}:{job_id}&page=queryresults"""
349+
return (
350+
f"https://console.cloud.google.com/bigquery?project={project_id}"
351+
f"&j=bq:{location}:{job_id}&page=queryresults"
352+
)
330353

331354

332355
def render_bqquery_sent_event_html(
@@ -351,7 +374,10 @@ def render_bqquery_sent_event_html(
351374
job_id=event.job_id,
352375
request_id=event.request_id,
353376
)
354-
query_text_details = f"<details><summary>SQL</summary><pre>{html.escape(event.query)}</pre></details>"
377+
query_text_details = (
378+
f"<details><summary>SQL</summary><pre>"
379+
f"{html.escape(event.query)}</pre></details>"
380+
)
355381

356382
return f"""
357383
Query started{query_id}.{job_link}{query_text_details}
@@ -400,7 +426,10 @@ def render_bqquery_retry_event_html(
400426
job_id=event.job_id,
401427
request_id=event.request_id,
402428
)
403-
query_text_details = f"<details><summary>SQL</summary><pre>{html.escape(event.query)}</pre></details>"
429+
query_text_details = (
430+
f"<details><summary>SQL</summary><pre>"
431+
f"{html.escape(event.query)}</pre></details>"
432+
)
404433

405434
return f"""
406435
Retrying query{query_id}.{job_link}{query_text_details}
@@ -446,7 +475,10 @@ def render_bqquery_received_event_html(
446475
query_plan_details = ""
447476
if event.query_plan:
448477
plan_str = "\n".join([str(entry) for entry in event.query_plan])
449-
query_plan_details = f"<details><summary>Query Plan</summary><pre>{html.escape(plan_str)}</pre></details>"
478+
query_plan_details = (
479+
f"<details><summary>Query Plan</summary><pre>"
480+
f"{html.escape(plan_str)}</pre></details>"
481+
)
450482

451483
return f"""
452484
Query{query_id} is {event.state}.{job_link}{query_plan_details}
@@ -509,7 +541,9 @@ def render_bqquery_finished_event_plaintext(
509541

510542
bytes_str = ""
511543
if event.total_bytes_processed is not None:
512-
bytes_str = f" {humanize.naturalsize(event.total_bytes_processed)} processed."
544+
bytes_str = (
545+
f" {humanize.naturalsize(event.total_bytes_processed)} processed."
546+
)
513547

514548
slot_time_str = ""
515549
if event.slot_millis is not None:
@@ -575,7 +609,9 @@ def get_formatted_time(val):
575609
Duration string
576610
"""
577611
try:
578-
return humanize.naturaldelta(datetime.timedelta(milliseconds=float(val)))
612+
return humanize.naturaldelta(
613+
datetime.timedelta(milliseconds=float(val))
614+
)
579615
except Exception:
580616
return val
581617

@@ -594,7 +630,10 @@ def get_formatted_bytes(val):
594630

595631

596632
def get_bytes_processed_string(val: Any):
597-
"""Try to get bytes processed string. Return empty if passed non int value"""
633+
"""Try to get bytes processed string.
634+
635+
Return empty if passed non int value.
636+
"""
598637
bytes_processed_string = ""
599638
if isinstance(val, int):
600639
bytes_processed_string = f"""{get_formatted_bytes(val)} processed. """

packages/bigframes/bigframes/functions/_function_session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
import inspect
2121
import sys
2222
import threading
23+
import warnings
2324
from typing import (
25+
TYPE_CHECKING,
2426
Any,
25-
cast,
2627
Dict,
2728
Literal,
2829
Mapping,
2930
Optional,
3031
Sequence,
31-
TYPE_CHECKING,
3232
Union,
33+
cast,
3334
)
34-
import warnings
3535

3636
import google.api_core.exceptions
3737
from google.cloud import (
@@ -41,9 +41,9 @@
4141
resourcemanager_v3,
4242
)
4343

44-
from bigframes import clients
4544
import bigframes.exceptions as bfe
4645
import bigframes.formatting_helpers as bf_formatting
46+
from bigframes import clients
4747
from bigframes.functions import function as bq_functions
4848
from bigframes.functions import udf_def
4949

packages/bigframes/bigframes/functions/function.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
from __future__ import annotations
1616

17-
import logging
18-
from typing import Callable, Optional, Protocol, runtime_checkable, TYPE_CHECKING
19-
2017
import dataclasses
18+
import logging
19+
from typing import TYPE_CHECKING, Callable, Optional, Protocol, runtime_checkable
2120

2221
import google.api_core.exceptions
2322
from google.cloud import bigquery
@@ -28,8 +27,8 @@
2827

2928
if TYPE_CHECKING:
3029
import bigframes.core.col
31-
from bigframes.session import Session
3230
import bigframes.series
31+
from bigframes.session import Session
3332

3433
logger = logging.getLogger(__name__)
3534

@@ -163,7 +162,8 @@ class Udf(Protocol):
163162
"""
164163

165164
@property
166-
def udf_def(self) -> udf_def.BigqueryUdf: ...
165+
def udf_def(self) -> udf_def.BigqueryUdf:
166+
...
167167

168168

169169
class BigqueryCallableRoutine:
@@ -192,8 +192,8 @@ def __call__(self, *args, **kwargs):
192192
if self._local_fun:
193193
return self._local_fun(*args, **kwargs)
194194
# avoid circular imports
195-
from bigframes.core.compile.sqlglot import sql as sg_sql
196195
import bigframes.session._io.bigquery as bf_io_bigquery
196+
from bigframes.core.compile.sqlglot import sql as sg_sql
197197

198198
args_string = ", ".join([sg_sql.to_sql(sg_sql.literal(v)) for v in args])
199199
sql = f"SELECT `{str(self._udf_def.routine_ref)}`({args_string})"

0 commit comments

Comments
 (0)