Skip to content

Commit 4d7b73c

Browse files
author
Christopher Doris
committed
conversion of numpy.bool_ to Bool
1 parent aca2701 commit 4d7b73c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

docs/src/conversion-to-julia.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ From Python, the arguments to a Julia function will be converted according to th
4747
| `ctypes.c_voidp` | `Ptr{Cvoid}`, `Ptr` |
4848
| `ctypes.c_char_p` | `Cstring`, `Ptr{Cchar}`, `Ptr` |
4949
| `ctypes.c_wchar_p` | `Cwstring`, `Ptr{Cwchar}`, `Ptr` |
50-
| `numpy.intXX`/`numpy.uintXX`/`numpy.floatXX` | `Integer`, `Rational`, `Real`, `Number` |
50+
| `numpy.bool_`/`numpy.intXX`/`numpy.uintXX`/`numpy.floatXX` | `Bool`, `Integer`, `Rational`, `Real`, `Number` |
5151
| Objects satisfying the buffer or array interface | `Array`, `AbstractArray` |
5252
| **Low priority (fallback to `Py`).** | |
5353
| Anything | `Py` |

docs/src/releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
* `Serialization.serialize` can use `dill` instead of `pickle` by setting the env var `JULIA_PYTHONCALL_PICKLE=dill`.
5+
* Added conversion from `numpy.bool_` to `Bool` and other number types.
56

67
## 0.9.20 (2024-05-01)
78
* The IPython extension is now automatically loaded upon import if IPython is detected.

src/Convert/numpy.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function (::pyconvert_rule_numpysimplevalue{R,SAFE})(::Type{T}, x::Py) where {R,
1010
end
1111

1212
const NUMPY_SIMPLE_TYPES = [
13+
("bool_", Bool),
1314
("int8", Int8),
1415
("int16", Int16),
1516
("int32", Int32),
@@ -27,17 +28,18 @@ const NUMPY_SIMPLE_TYPES = [
2728
]
2829

2930
function init_numpy()
30-
for (t,T) in NUMPY_SIMPLE_TYPES
31-
isint = occursin("int", t)
32-
isuint = occursin("uint", t)
31+
for (t, T) in NUMPY_SIMPLE_TYPES
32+
isbool = occursin("bool", t)
33+
isint = occursin("int", t) || isbool
34+
isuint = occursin("uint", t) || isbool
3335
isfloat = occursin("float", t)
3436
iscomplex = occursin("complex", t)
3537
isreal = isint || isfloat
3638
isnumber = isreal || iscomplex
3739

3840
name = "numpy:$t"
39-
rule = pyconvert_rule_numpysimplevalue{T, false}()
40-
saferule = pyconvert_rule_numpysimplevalue{T, true}()
41+
rule = pyconvert_rule_numpysimplevalue{T,false}()
42+
saferule = pyconvert_rule_numpysimplevalue{T,true}()
4143

4244
pyconvert_add_rule(name, T, saferule, PYCONVERT_PRIORITY_ARRAY)
4345
isuint && pyconvert_add_rule(name, UInt, sizeof(T) sizeof(UInt) ? saferule : rule)

0 commit comments

Comments
 (0)