From fae9dfca1895e7555f479422b9ab83a083b14957 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk <21087696+oleksandr-pavlyk@users.noreply.github.com> Date: Tue, 12 May 2026 15:06:31 -0500 Subject: [PATCH] Fix for format_axis_value in json format script to handle None value Add tests to cover such input. --- python/scripts/nvbench_json_summary.py | 3 ++ python/test/test_nvbench_json_summary.py | 61 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/python/scripts/nvbench_json_summary.py b/python/scripts/nvbench_json_summary.py index 813b57d..cea0292 100644 --- a/python/scripts/nvbench_json_summary.py +++ b/python/scripts/nvbench_json_summary.py @@ -180,6 +180,9 @@ def format_axis_value( name = axis_value["name"] axis = axes_by_name.get(name, {}) value = axis_value["value"] + if value is None: + return name, "" + if axis.get("type") == "int64" and axis.get("flags") == "pow2": int_value = int(value) exponent = int_value.bit_length() - 1 diff --git a/python/test/test_nvbench_json_summary.py b/python/test/test_nvbench_json_summary.py index f8b3340..d0e6b70 100644 --- a/python/test/test_nvbench_json_summary.py +++ b/python/test/test_nvbench_json_summary.py @@ -196,6 +196,11 @@ def test_json_summary_formats_axis_values_like_markdown_printer(): "type": "float64", "flags": "", }, + "Nullable": { + "name": "Nullable", + "type": "int64", + "flags": "", + }, } assert nvbench_json_summary.format_axis_value( @@ -208,6 +213,62 @@ def test_json_summary_formats_axis_values_like_markdown_printer(): {"name": "Duration", "type": "float64", "value": "0.123456789"}, axes_by_name, ) == ("Duration", "0.12346") + assert nvbench_json_summary.format_axis_value( + {"name": "Nullable", "type": "int64", "value": None}, axes_by_name + ) == ("Nullable", "") + + +def test_json_summary_formats_state_with_null_axis_values(tmp_path): + json_path = tmp_path / "result.json" + json_path.write_text( + json.dumps( + { + "devices": [ + { + "id": 0, + "name": "Test GPU", + } + ], + "benchmarks": [ + { + "name": "no_axes", + "devices": [0], + "axes": None, + "states": [ + { + "name": "Device=0", + "device": 0, + "axis_values": None, + "summaries": [ + { + "tag": "nv/cold/time/gpu/sample_size", + "name": "Samples", + "hint": "sample_size", + "data": [ + { + "name": "value", + "type": "int64", + "value": "7", + } + ], + } + ], + "is_skipped": False, + } + ], + } + ], + } + ), + encoding="utf-8", + ) + + result = nvbench_json_summary.BenchmarkResult.from_json(json_path) + report = nvbench_json_summary.format_result(result) + + assert "## no_axes" in report + assert "| Samples |" in report + assert "| 7x |" in report def test_json_summary_cli_writes_output_file(tmp_path):