Skip to content

Commit

Permalink
[processing] log cases when subset is smaller than requested number of
Browse files Browse the repository at this point in the history
features

(cherry-picked from b72f5d1)
  • Loading branch information
alexbruy authored and nyalldawson committed Jul 10, 2018
1 parent 5ae2430 commit cf73522
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ def processAlgorithm(self, parameters, context, feedback):
classes[attrs[index]].append(feature)
feedback.setProgress(int(i * total))

for subset in classes.values():
for k, subset in classes.items():
selValue = value if method != 1 else int(round(value * len(subset), 0))
selran.extend(random.sample(subset, min(selValue, len(subset))))
if selValue > len(subset):
selValue = len(subset)
feedback.reportError(self.tr('Subset "{}" is smaller than requested number of features.'.format(k)))
selran.extend(random.sample(subset, selValue))

total = 100.0 / featureCount if featureCount else 1
for (i, feat) in enumerate(selran):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,15 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.setProgress(int(i * total))

selran = []
for subset in classes.values():
for k, subset in classes.items():
if feedback.isCanceled():
break

selValue = value if method != 1 else int(round(value * len(subset), 0))
selran.extend(random.sample(subset, min(selValue, len(subset))))
if selValue > len(subset):
selValue = len(subset)
feedback.reportError(self.tr('Subset "{}" is smaller than requested number of features.'.format(k)))
selran.extend(random.sample(subset, selValue))

layer.selectByIds(selran)
else:
Expand Down

0 comments on commit cf73522

Please sign in to comment.