Skip to content

Commit e6fbc0f

Browse files
guillesdevertlammerts
authored andcommitted
run pre-commit
1 parent 62b450b commit e6fbc0f

5 files changed

Lines changed: 40 additions & 20 deletions

File tree

duckdb/query_graph/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .__main__ import translate_json_to_html
1+
from .__main__ import translate_json_to_html # noqa: D104
22

3-
__all__ = ["translate_json_to_html"]
3+
__all__ = ["translate_json_to_html"]

duckdb/query_graph/__main__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
color: #b3b3b3;
265265
}
266266
}
267-
"""
267+
""" # noqa: W293
268268

269269

270270
class NodeTiming: # noqa: D101
@@ -325,8 +325,7 @@ def get_child_timings(top_node: object, query_timings: object, depth: int = 0) -
325325

326326

327327
def get_f7fff0_shade_hex(fraction: float) -> str:
328-
"""
329-
Returns a shade between very light (#f7fff0) and a slightly darker green-yellow,
328+
"""Returns a shade between very light (#f7fff0) and a slightly darker green-yellow,
330329
depending on the fraction (0..1)
331330
"""
332331
fraction = max(0, min(1, fraction))
@@ -345,10 +344,8 @@ def get_f7fff0_shade_hex(fraction: float) -> str:
345344

346345
def get_node_body(
347346
name: str, result: str, cpu_time: float, card: int, est: int, result_size: int, extra_info: str
348-
) -> str: # noqa: D103
349-
"""
350-
Generate the HTML body for a single node in the tree.
351-
"""
347+
) -> str:
348+
"""Generate the HTML body for a single node in the tree."""
352349
node_style = f"background-color: {get_f7fff0_shade_hex(float(result) / cpu_time)};"
353350
new_name = "BRIDGE" if (name == "INVALID") else name.replace("_", " ")
354351
formatted_num = f"{float(result):.4f}"
@@ -362,7 +359,7 @@ def get_node_body(
362359
body += f"<p>estimate: {est}</p>"
363360
body += f"<p>result size: {result_size} bytes</p>"
364361
body += "<details>"
365-
body += f"<summary>Extra info</summary>"
362+
body += "<summary>Extra info</summary>"
366363
body += '<div class="node-details">'
367364
body += f"<p>{extra_info}</p>"
368365
# TODO: Expand on timing. Usually available from a detailed profiling # noqa: TD002, TD003
@@ -411,6 +408,7 @@ def generate_tree_recursive(json_graph: object, cpu_time: float) -> str: # noqa
411408

412409
# For generating the table in the top left with expandable phases
413410
def generate_timing_html(graph_json: object, query_timings: object) -> object:
411+
"""Generates timing HTML table with expandable phases."""
414412
json_graph = json.loads(graph_json)
415413
gather_timing_information(json_graph, query_timings)
416414
table_head = """
@@ -500,7 +498,7 @@ def generate_metric_grid_html(graph_json: str) -> str: # noqa: D103
500498
else "N/A",
501499
}
502500
metric_grid_html = """<div class="metrics-grid">"""
503-
for key in metrics.keys():
501+
for key in metrics:
504502
metric_grid_html += f"""
505503
<div class="metric-box">
506504
<div class="metric-title">{key}</div>

src/duckdb_py/duckdb_python.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ static void InitializeConnectionMethods(py::module_ &m) {
132132
}
133133
return conn->GetProfilingInformation(format);
134134
},
135-
"Get profiling information from a query", py::kw_only(), py::arg("format") = "json",
136-
py::arg("connection") = py::none());
135+
"Get profiling information from a query", py::kw_only(), py::arg("format") = "json",
136+
py::arg("connection") = py::none());
137137
m.def(
138138
"enable_profiling",
139139
[](shared_ptr<DuckDBPyConnection> conn = nullptr) {

src/duckdb_py/pyconnection.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ static void InitializeConnectionMethods(py::class_<DuckDBPyConnection, shared_pt
286286
py::arg("extension"), py::kw_only(), py::arg("force_install") = false, py::arg("repository") = py::none(),
287287
py::arg("repository_url") = py::none(), py::arg("version") = py::none());
288288
m.def("load_extension", &DuckDBPyConnection::LoadExtension, "Load an installed extension", py::arg("extension"));
289-
m.def("get_profiling_information", &DuckDBPyConnection::GetProfilingInformation, "Get profiling information for a query", py::arg("format") = "json");
289+
m.def("get_profiling_information", &DuckDBPyConnection::GetProfilingInformation,
290+
"Get profiling information for a query", py::arg("format") = "json");
290291
m.def("enable_profiling", &DuckDBPyConnection::EnableProfiling, "Enable profiling for subsequent queries");
291292
m.def("disable_profiling", &DuckDBPyConnection::DisableProfiling, "Disable profiling for subsequent queries");
292293
} // END_OF_CONNECTION_METHODS
@@ -351,7 +352,9 @@ py::str DuckDBPyConnection::GetProfilingInformation(const py::str &format) {
351352
} else if (format == "graphviz") {
352353
format_enum = ProfilerPrintFormat::GRAPHVIZ;
353354
} else {
354-
throw InvalidInputException("Invalid ProfilerPrintFormat string: " + std::string(format) + ". Valid options are: query_tree, json, query_tree_optimizer, no_output, html, graphviz.");
355+
throw InvalidInputException(
356+
"Invalid ProfilerPrintFormat string: " + std::string(format) +
357+
". Valid options are: query_tree, json, query_tree_optimizer, no_output, html, graphviz.");
355358
}
356359
auto &connection = con.GetConnection();
357360
py::str profiling_info = connection.GetProfilingInformation(format_enum);

tests/fast/test_profiler.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import pytest
21
import json
2+
3+
import pytest
4+
35
import duckdb
46
from duckdb.query_graph import translate_json_to_html
57

8+
69
@pytest.fixture(scope="session")
710
def profiling_connection():
811
con = duckdb.connect()
@@ -11,19 +14,35 @@ def profiling_connection():
1114
yield con
1215
con.close()
1316

17+
1418
class TestProfiler:
15-
def test_profiler_matches_expected_format(self, profiling_connection, tmp_path_factory):
19+
def test_profiler_matches_expected_format(self, profiling_connection, tmp_path_factory):
1620
# Test String returned
1721
profiling_info_json = profiling_connection.get_profiling_information(format="json")
1822
assert isinstance(profiling_info_json, str)
19-
23+
2024
# Test expected metrics are there and profiling is json loadable
2125
profiling_dict = json.loads(profiling_info_json)
22-
expected_keys = {'query_name', 'total_bytes_written', 'total_bytes_read', 'system_peak_temp_dir_size', 'system_peak_buffer_memory', 'rows_returned', 'result_set_size', 'latency', 'cumulative_rows_scanned', 'cumulative_cardinality', 'cpu_time', 'extra_info', 'blocked_thread_time', 'children'}
26+
expected_keys = {
27+
"query_name",
28+
"total_bytes_written",
29+
"total_bytes_read",
30+
"system_peak_temp_dir_size",
31+
"system_peak_buffer_memory",
32+
"rows_returned",
33+
"result_set_size",
34+
"latency",
35+
"cumulative_rows_scanned",
36+
"cumulative_cardinality",
37+
"cpu_time",
38+
"extra_info",
39+
"blocked_thread_time",
40+
"children",
41+
}
2342
assert profiling_dict.keys() == expected_keys
2443

2544
def test_profiler_html_output(self, profiling_connection, tmp_path_factory):
2645
tmp_dir = tmp_path_factory.mktemp("profiler", numbered=True)
2746
profiling_info_json = profiling_connection.get_profiling_information(format="json")
2847
# Test HTML execution works, nothing to assert!
29-
translate_json_to_html(input_text = profiling_info_json, output_file = f"{tmp_dir}/profiler_output.html")
48+
translate_json_to_html(input_text=profiling_info_json, output_file=f"{tmp_dir}/profiler_output.html")

0 commit comments

Comments
 (0)