Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

havatv
Copy link
Contributor

@havatv havatv commented Aug 30, 2017

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

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include fixes #11111 in the commit message next to the description
  • Commits which add new features are tagged with [FEATURE] in the commit message
  • Commits which change the UI or existing user workflows are tagged with [needs-docs] in the commit message and containt sufficient information in the commit message to be documented
  • I have read the QGIS Coding Standards and this PR complies with them
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit

@@ -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:
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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.

@nyalldawson
Copy link
Collaborator

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)

@havatv
Copy link
Contributor Author

havatv commented Aug 30, 2017

@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...

@nyalldawson
Copy link
Collaborator

This change was integrated into #5154 - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants