Replace numpy-Python comparison with dtype #210
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.
make format && make documentation
has been run.What's changed
Fixes #100. Previously, in #205, we downgraded one line of
enums.py
. The reason for this line was previously unclear, but notably, it always runs: it takes thearray
variable, determines whether it equals 0 (which yieldsTrue
orFalse
), then determines whether the resulting value is a Boolean, which it always is.This was construed as a means of checking whether or not an array is of Boolean type in the comments, but what this piece of code actually does is converts all arrays passed into the function to Numpy's Unicode-string type. However, that is ambiguous due to how it's written, as well as Numpy's own confusing syntax. I believe this code also raises a
FutureWarning
because it takes a Numpyndarray
type and compares it with a Python type, in this case, a number.In order to silence the warning and clean up the code, this PR instead determines whether the inbound array is of dtype "S," which confusingly stands for "bytewise-string." If so, it converts it to "str" type, which yields a dtype "U," or "Unicode-string," array.
Tests
This was tested via a Jupyter notebook with a sample
policyengine-uk
setup that mirrors Nikhil's in #203. That said, it has not been tested withpolicyengine-us
.