Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Release date: UNRELEASED

### Bug fixes

* Fixed the `stat` command printing bounds as `np.float64(...)` instead of plain numbers (#871, thanks to @Miabeyefendi)
* Fixed `snap`, `squiggles`, `linesimplify` and `random` crashing with a traceback on invalid numeric values (zero pitch, zero period/quantization, negative tolerance, negative count); they now report a regular usage error (#855, thanks to @Miabeyefendi)
* Fixed layers being merged when reading a SVG whose groups share the same `inkscape:label` (e.g. as produced by `splitdist` followed by `write`); the `inkscape:label` attribute is now ignored when it would assign the same layer ID to two groups, in which case the `id` attribute (or, lacking digits, the group's appearing order) is used instead (#855)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,13 @@ def test_splitdist_preserves_metadata():
)


def test_stat_bounds_are_plain_floats(runner):
result = runner.invoke(cli, "line 0 0 10 20 stat", catch_exceptions=False)
assert result.exit_code == 0
assert "Bounds: (0.0, 0.0, 10.0, 20.0)" in result.output
assert "np.float64" not in result.output


@pytest.mark.parametrize(
["cmd", "message"],
[
Expand Down
11 changes: 9 additions & 2 deletions vpype_cli/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ def has_layers_only(self, lids: Sequence[int]) -> bool:
return self.has_layers(lids) and len(self.layers.keys()) == len(lids)


def _format_bounds(bounds) -> str:
"""Format bounds as a plain tuple of floats (no NumPy scalar repr)."""
if bounds is None:
return "None"
return str(tuple(float(v) for v in bounds))


@cli.command(group="Output")
@global_processor
def stat(document: vp.Document):
Expand Down Expand Up @@ -150,7 +157,7 @@ def stat(document: vp.Document):
" Mean segment length:",
str(length / layer.segment_count() if layer.segment_count() else "n/a"),
)
print(f" Bounds: {layer.bounds()}")
print(f" Bounds: {_format_bounds(layer.bounds())}")
print(" Properties:")
for key, value in layer.metadata.items():
print(f" {key}: {value!r}")
Expand All @@ -165,7 +172,7 @@ def stat(document: vp.Document):
" Mean segment length:",
str(length_tot / document.segment_count() if document.segment_count() else "n/a"),
)
print(f" Bounds: {document.bounds()}")
print(f" Bounds: {_format_bounds(document.bounds())}")
print(" Global properties:")
for key, value in document.metadata.items():
print(f" {key}: {value!r}")
Expand Down
Loading