Add check if radars tuple is not empty #991
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the same PR as #990 (reopened as I have forgotten to add the check to the
map_to_grid
function).In some edge cases (in my case when radars tuple is created in a loop) the empty tuple can be passed to the
gates_to _grid
ormap_to_grid
functions. In that casetuple index out of range
error occures whenradars[0].altitude['data']
is acessed, and it is not always obvious what is the cause of that error.I propose to add a simple check if
radars
tuple length is equal to 0. If yes then ValueError exception is raised with a more meaningful error message indicating what the issue is.The placement of that
if
statement is just after conversion of singleRadar
object intoradars
tuple, so that tuple length can be checked without worring about edge cases.In this solution also length of
gatefilters
tuple is implicitly checked asgatefilters
must have the same length asradars
.The check is also added to
grid_from_radars
function as there is no need to call the gridding functions if the radars tuple is empty.