Add support for large integer bit flags #56
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.
I was working on regression tests for the
bitmask
module when I have encountered a strangeOverflowError
that was happening in some cases whenignore_flags
contained "too high" bits (for particularbitfield
arguments).Here are several examples:
The second command fails because internally
interpret_bit_flags()
called bybitfield_to_boolean_mask()
convertsnp.uint64(1<<63)
flag to Pythonint
(orlong
). In the first command there is no such conversion. This PR forcesinterpret_bit_flags()
to always return Python integer type. This will lead to the crash shown in the second statement above.... And finally,
Most of these issues are due to the fact when bit flags contain bits beyond what
numpy.int64
ornumpy.uint64
types can hold,numpy
cannot "down-convert" those flags to largest representable bynumpy
type. Nevertheless,numpy
can do this down-conversion fromuint16
touint8
as shown above.This PR adresses these failures by dropping all the bits that cannot be represented by the type of the
bitfield
argument passed tobitfield_to_boolean_mask()
.Finally, this PR adds support for the
long
type in Python 2.7.