You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@harry-clarke indeed it is not supported, we only test use cases with positive indexes. - is parsed as a range separator, not a minus sign. Could you tell us a bit more about your use case where that would be useful?
Funnily, it's just because I've been making my way through the Advent of Code challenges, and I wanted a RangeSet for intersecting rows and columns with shapes.
>>> RangeSet(range(-5,7))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sthiell/github/thiell/clustershell/lib/ClusterShell/RangeSet.py", line 124, in __init__
self._parse(pattern)
File "/home/sthiell/github/thiell/clustershell/lib/ClusterShell/RangeSet.py", line 178, in _parse
raise RangeSetParseError(subrange, msg)
ClusterShell.RangeSet.RangeSetParseError: cannot convert string to integer : "-5"
For now, you could use 1.8.4, but I will see if we can restore functionality in 1.9.x and officially support negative ranges. I will post updates in this ticket. Thanks for the report!
Activity
thiell commentedon Dec 26, 2022
@harry-clarke indeed it is not supported, we only test use cases with positive indexes.
-
is parsed as a range separator, not a minus sign. Could you tell us a bit more about your use case where that would be useful?harry-clarke commentedon Dec 26, 2022
Funnily, it's just because I've been making my way through the Advent of Code challenges, and I wanted a RangeSet for intersecting rows and columns with shapes.
In its simplest form, I want to do:
harry-clarke commentedon Dec 26, 2022
At least for now, can we provide a
ValueError
when passing in ranges with negative values?I don't mind creating a PR
Ideally, it would be good to remove the dependency on string parsing for interpreting ranges, which should reduce complexity a bit.
thiell commentedon Dec 26, 2022
I checked and it is an unexpected change (or "regression") between 1.8.x and 1.9.
In 1.9, we actually changed the way the inner set handles indices: we now rely on strings instead of integers. This allows
RangeSet
to support complex cases of zero padding, for things like 01-05,001-002 (seehttps://clustershell.readthedocs.io/en/latest/tools/nodeset.html?#zero-padding)
With 1.8.4:
With 1.9:
For now, you could use 1.8.4, but I will see if we can restore functionality in 1.9.x and officially support negative ranges. I will post updates in this ticket. Thanks for the report!
RangeSet: support negative ranges (#515) (#518)