-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Make field to calculate statistics on optional in Statistics by category in Processing… #5095
Conversation
…s by category in Processing
@@ -90,7 +91,10 @@ def processAlgorithm(self, parameters, context, feedback): | |||
feedback.setProgress(int(current * total)) | |||
attrs = feat.attributes() | |||
try: | |||
value = float(attrs[value_field_index]) | |||
if value_field_index > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be >= 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, very sorry about that. I did the testing on another computer...
if value_field_index > 0: | ||
value = float(attrs[value_field_index]) | ||
else: | ||
value = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be NULL
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that 0 would be safer (and it works fine in my tests), as I was not sure about how qgsstatisticalsummary would handle NULLs. But whatever works is of course OK.
Would an alternate approach here be to leave the field as mandatory, but allow non numeric fields? We could potentially adapt the calculated stats by field type (like the non grouped stats alg does) |
@nyalldawson, allowing non-numerical fields is a good solution (as we need at least one field for the function to make sense), but I am far more comfortable when modifying the (isolated) Python Processing code - and even then I make stupid mistakes... |
This change was integrated into #5154 - thanks! |
Description
Make Field to calculate statistics on optional in Statistics by categories.
Field to calculate statistics on has been made optional and values set to 0.
This results in a table with 0 or NAN values in all the statistics columns except for count.
Checklist
fixes #11111
in the commit message next to the description[FEATURE]
in the commit message[needs-docs]
in the commit message and containt sufficient information in the commit message to be documentedscripts/prepare-commit.sh
script before each commit