BUG: fix compatibility with NumPy 2.3#616
Conversation
Signed-off-by: DerWeh <[email protected]>
Signed-off-by: DerWeh <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #616 +/- ##
===========================================
- Coverage 72.47% 58.40% -14.07%
===========================================
Files 73 73
Lines 10318 10322 +4
===========================================
- Hits 7478 6029 -1449
- Misses 2840 4293 +1453
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @DerWeh -- This is great; however I would prefer to convert from bool and np.bool_ into np.int32 inside the _native.py file so that callers to measure_feature and fill_feature do not need to understand these lower-level concepts. |
|
In this case, I need more information how exactly you want to handle this. A cast to >> import numpy as np
>> np.int32(3.0)
np.int32(3)
>> np.int32(np.pi)
np.int32(3)
>> np.int32("3")
np.int32(3)Do you want to accept such inputs? And if we automatically cast, why cast to integer and not to boolean? Boolean is a different conversion as 'something' equals to True, and 'nothing' to False: Do you really want to silently accept all kind of inputs that can be converted to an integer or boolean? Or should we issue warnings upon conversion? Or manually check for allowed inputs? From the name How do you want this behavior? Can/should we separate such larger change from the current bug fix? Currently, I need to downgrade NumPy and explicitly demand Concerning the CI:
|
|
C++ has a bool type, but C does not, so the type passed between python and C via ctypes needs to be something like int32. int32 tends to be the most cross-language compatible type, so that's why it was chosen instead of uint32, int8, int64, etc. R for example supports int32, but not the others. The _native.py file was designed as an interop layer such that code within _native.py is allowed to do low-level unsafe things and is allowed to look more C-like. The functions exposed by _native.py should accept python types. So, fill_feature and measure_feature should accept python bool types like bool or np.bool_, but not integers. fill_feature and measure_feature should convert the python bool types they receive into the int32 type expected by the C layer. I would do something like: above this (and similar code within _native.py): interpret/python/interpret-core/interpret/utils/_native.py Lines 714 to 716 in 251cf9b For the ruff error, run: |
Signed-off-by: DerWeh <[email protected]>
Signed-off-by: DerWeh <[email protected]>
|
@paulbkoch I applied For the rest, this PR should be good now. |
Signed-off-by: Paul Koch <[email protected]>
|
The new release just out v0.6.12 has this fix. |
The C++ data type
BoolEBMis defined asint32_t, thus an integer not anp.bool_should be passed to these functions.NumPy 2.3 removes following behavior:
(gh-28254)
I assume that due to this pending deprecation previously it was allowed to pass a
boolas anint32_tas it could be interpreted as index and therefore as number.Note the subtle difference: Python's
boolis anumbers.Integralandnumbers.Number:But
np.bool_is not:Neither, Python's
boolnor NumPy'snp.bool_are NumPy integers or numbers:NumPy's
boolcorresponds tobooldefined in stdbool.h.FYI: as you work with
cytpes: NumPy offers also some convenience functions to handle pointers and arrays, as well as a platform independentload_libraryimplementation.https://numpy.org/doc/stable/reference/routines.ctypeslib.html