-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
BUG: bool(dtype) is True #8279
BUG: bool(dtype) is True #8279
Conversation
return 1; | ||
} | ||
|
||
static PyNumberMethods descr_as_number = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not Python 3 compatible, see doc/Py3K.rst.txt
or grep for examples. Also, Python tends to 0
rather than NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed.
6e10894
to
da91cf9
Compare
@@ -3600,6 +3600,31 @@ arraydescr_richcompare(PyArray_Descr *self, PyObject *other, int cmp_op) | |||
return result; | |||
} | |||
|
|||
static Py_ssize_t | |||
descr_nonzero(PyObject *self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong return type. The CPython typedef is
typedef int (*inquiry)(PyObject *);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Should be good now.
da91cf9
to
fe3f5aa
Compare
Seems a small thing really, should we just put this in? The only thing I could find against is whether @jcrist maybe you can add a short mention to the 1.13 release notes (or am I overdoing release notes ;)). |
@seberg I don't have a problem with this, go ahead. A release note would be good, someone may actually be using current behavior to check for fields. Hmm, what is the recommended way to do that? |
Hmmm, true, I guess you can check whether |
@seberg Yep, a grep turns up |
Yeah, we should have a `.hasfields` just so there is something
"obvious" :))
|
@jcrist Could you add something to the |
Previously `bool(dtype(...))` would fallback to the default implementation of `__nonzero__`, which checks if `len(object) > 0`. Since `dtype` objects implement `__len__` as the number of record fields, `bool` of scalar dtypes like `bool(dtype('i8'))` would evaluate as `False`. This fixes that by implementing `__nonzero__` to always return True. Fixes numpy#6294.
fe3f5aa
to
6cbb46e
Compare
Apologies for the delay here. I've added a release note. |
@jcrist Thanks. |
This is >= 1.13 xref numpy/numpy#8279 closes pandas-dev#15199
This is >= 1.13 xref numpy/numpy#8279 closes pandas-dev#15199
This is >= 1.13 xref numpy/numpy#8279 closes pandas-dev#15199
Previously
bool(dtype(...))
would fallback to the defaultimplementation of
__nonzero__
, which checks iflen(object) > 0
.Since
dtype
objects implement__len__
as the number of recordfields,
bool
of scalar dtypes likebool(dtype('i8'))
would evaluateas
False
. This fixes that by implementing__nonzero__
to alwaysreturn True.
Fixes #6294.