Bug report #19322
Random selection within subsets throws exception
Status: | Closed | ||
---|---|---|---|
Priority: | High | ||
Assignee: | - | ||
Category: | Processing/QGIS | ||
Affected QGIS version: | 3.2 | Regression?: | Yes |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 27150 |
Description
Random selection within subsets throws an exception if a subset has less element than the value set in 'Number/percentage of selected feature' field and Method is 'Number of selected features'
Error message:
Traceback (most recent call last): File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\algs\qgis\RandomSelectionWithinSubsets.py", line 141, in processAlgorithm selran.extend(random.sample(subset, selValue)) File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\random.py", line 317, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative
It worked on the same data with QGIS 2.18.10 (but was extremely slow)
Associated revisions
[processing] fix Random extract/select within subset when subset is
smaller than number of requested features (fix #19322)
[processing] fix Random extract/select within subset when subset is
smaller than number of requested features (fix #19322)
(cherry-picked from 29207a16)
History
#1 Updated by Giovanni Manghi over 6 years ago
- Status changed from Open to Feedback
Did it worked as expected (with the described values) in previous releases?
#2 Updated by Dénes Szalontai over 6 years ago
- Status changed from Feedback to Open
I checked it in QGIS 3.0.3 and the same issue occurs:
Traceback (most recent call last): File "C:/PROGRA~1/QGIS3~1.0/apps/qgis/./python/plugins\processing\algs\qgis\RandomSelectionWithinSubsets.py", line 137, in processAlgorithm selran.extend(random.sample(subset, selValue)) File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\random.py", line 317, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative
It works well and produces the expected result in QGIS 2.18.10 with the same input data and the same settings.
#3 Updated by Giovanni Manghi over 6 years ago
- Regression? changed from No to Yes
- Priority changed from Normal to High
#4 Updated by Alexander Bruy over 6 years ago
- Category changed from Python plugins to Processing/QGIS
- Status changed from Open to Feedback
Please provide test dataset and steps to reproduce the issue
#5 Updated by Dénes Szalontai over 6 years ago
- File Sample.csv added
- Status changed from Feedback to Open
- Add the attached sample.csv layer with Layer -> Add Layer -> Add Delimited Text Layer (delimiter: semicolon, the first record has field names, EPSG: 4326)
- Start the Random selection within subsets tool from Vector -> Research Tools
- Select Sample as Input layer, SPEEDLIMIT as ID field, Number of selected features as Method and 5 as Number/percentage of selected features
- Hit Run to start processing
Actual behaviour in QGIS 3.x:
An exception is thrown and the execution fails with the error message
Traceback (most recent call last): File "C:/PROGRA~1/QGIS3~1.2/apps/qgis/./python/plugins\processing\algs\qgis\RandomSelectionWithinSubsets.py", line 141, in processAlgorithm selran.extend(random.sample(subset, selValue)) File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\random.py", line 317, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative
Actual behaviour in QGIS 2.18.10:
Process finishes successfully with the expected result
Note: The sample data contains the value 110 less than 5 times (only once) in SPEEDLIMIT column. If I set Number/percentage of selected features to 1 then process finishes successfully in QGIS 3.x as well but it fails with any other values.
Note 2: Random extract within subsets tool fails as well with this data in QGIS 3.x
#6 Updated by Alexander Bruy over 6 years ago
- % Done changed from 0 to 100
- Status changed from Open to Closed
Applied in changeset qgis|29207a1617678eb3a3922ff3dd74c3b6b6b193a5.