File tree Expand file tree Collapse file tree 1 file changed +3
-13
lines changed Expand file tree Collapse file tree 1 file changed +3
-13
lines changed Original file line number Diff line number Diff line change @@ -1053,7 +1053,9 @@ template <> class type_caster<bool> {
10531053 if (!src) return false ;
10541054 else if (src.ptr () == Py_True) { value = true ; return true ; }
10551055 else if (src.ptr () == Py_False) { value = false ; return true ; }
1056- else if (convert) {
1056+ else if (convert || !strcmp (" numpy.bool_" , Py_TYPE (src.ptr ())->tp_name )) {
1057+ // (allow non-implicit conversion for numpy booleans)
1058+
10571059 Py_ssize_t res = -1 ;
10581060 if (src.is_none ()) {
10591061 res = 0 ; // None is implicitly converted to False
@@ -1076,18 +1078,6 @@ template <> class type_caster<bool> {
10761078 value = (bool ) res;
10771079 return true ;
10781080 }
1079- return false ;
1080- }
1081- else if (hasattr (src, " dtype" )) {
1082- // Allow non-implicit conversion for numpy booleans
1083- //
1084- // Note: this will only run in the first (noconvert) pass;
1085- // during the second pass, it will be handled by __bool__ logic.
1086- auto dtype = src.attr (" dtype" );
1087- if (hasattr (dtype, " kind" ) && dtype.attr (" kind" ).cast <char >() == ' b' ) {
1088- value = PyObject_IsTrue (src.ptr ()) == 1 ;
1089- return true ;
1090- }
10911081 }
10921082 return false ;
10931083 }
You can’t perform that action at this time.
0 commit comments