Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions with ndarray parameters of type npy_bool always raise a ValueError #2675

Closed
telamonian opened this issue Oct 23, 2018 · 0 comments · Fixed by #2676
Closed

functions with ndarray parameters of type npy_bool always raise a ValueError #2675

telamonian opened this issue Oct 23, 2018 · 0 comments · Fixed by #2676

Comments

@telamonian
Copy link
Contributor

Here's a potential bug that I came across when answering a question on Stack Overflow.

Given a boolFunc.pyx file that looks like this:

import numpy as np
cimport numpy as np

def boolFunc(np.ndarray[np.npy_bool, ndim=1] npdata):
    return npdata

if you try to import and use it in python code:

from boolFunc import boolFunc
import numpy as np

# generate random boolArr
arr = np.random.randint(0,2, size=3, dtype=int)
boolArr = np.array(arr, dtype=bool)

# test cython function
boolFunc(boolArr)

you always get a particular ValueError:

ValueError: Does not understand character buffer dtype format string ('?')

This seems like it should work as is. In fact, this does work for other numpy types (eg npy_int, npy_double, etc). On the other hand, adding cast=True to the signature of boolFunc:

def boolFunc(np.ndarray[np.npy_bool, ndim=1, cast=True] npdata):

fixes the error, but casting shouldn't be necessary here since we're explicitly passing in a bool type ndarray.

telamonian added a commit to telamonian/cython that referenced this issue Oct 23, 2018
@scoder scoder added this to the 3.0 milestone Oct 31, 2018
scoder pushed a commit that referenced this issue Sep 10, 2019
@scoder scoder modified the milestones: 3.0, 0.29.14 Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants