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

fix: nanargmin with all nan slice #134

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

manuba95
Copy link
Contributor

This fixes an issue in the DiscreteVoronoiModel. The model crashes when frame are all NaN because of the np.nanargmin() function. This is because of type stability of the return of that function as its supposed to return integers. See pydata/xarray#4481 and pydata/xarray#3884.
One easy fix for this would be to apply the np.nanargmin() only to slices that are not all NaN using np.where(). However, masking the hole array before the loop and catching the all NaN slices early might be a more elegant and better performing option.

@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.58%. Comparing base (e1de087) to head (5d10c39).
Report is 1 commits behind head on develop.

Current head 5d10c39 differs from pull request most recent head 277fa24

Please upload reports for the commit 277fa24 to get more accurate results.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #134   +/-   ##
========================================
  Coverage    95.58%   95.58%           
========================================
  Files           47       47           
  Lines         3194     3194           
========================================
  Hits          3053     3053           
  Misses         141      141           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@manuba95
Copy link
Contributor Author

This commit fixes an issue with the previous commit. Although the np.where() is supposed to handle the all-nan slices, the np.nanargmin() is still called upon the entire array, resulting in the same error. This is now fixed by masking the array.
Although it is possible to catch this edge case earlier (e.g. by masking the array before the initial for loop) I think this is currently the approriate solution as other unexpected user choices may result in all-nan slices in the closest_player_index (e.g. manipulation of the mesh grid).
The tests all run properly but I think they should be extended to at least the all-nan slice edge case. Also, there is currently no test for the plotting, which needed a fix as well.
Also, I think it can be up to debate, weather inactive players (or teams) should have a space controll value of 0 (as currently) or if it should be np.NaN.
Here, I would appreciate some feedback before continuing finalizing this PR.

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.

1 participant