-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Fix dtype int vs char inconsistencies + dtype hashing #231
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0861c7
STY: cleanup hashdesc.c to follow our C conventions.
cournape 40e4393
BUG: fix inconsistencies in dtype flag type at the C level.
cournape 3d8da15
BUG: fix #2017 by ignoring type_num in the hash input.
cournape 27a1bb2
BUG: fix flags type when exposed to python.
cournape b301dfd
STY: more C-style tweaks.
cournape File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: fix inconsistencies in dtype flag type at the C level.
- Loading branch information
commit 40e439348611e5d9ffa2854f114c4df6cd9b4b58
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,7 +323,7 @@ _convert_from_array_descr(PyObject *obj, int align) | |
PyObject *nameslist; | ||
PyArray_Descr *new; | ||
PyArray_Descr *conv; | ||
int dtypeflags = 0; | ||
char dtypeflags = 0; | ||
int maxalign = 0; | ||
|
||
n = PyList_GET_SIZE(obj); | ||
|
@@ -479,7 +479,7 @@ _convert_from_array_descr(PyObject *obj, int align) | |
new->fields = fields; | ||
new->names = nameslist; | ||
new->elsize = totalsize; | ||
new->flags=dtypeflags; | ||
new->flags = dtypeflags; | ||
|
||
/* Structured arrays get a sticky aligned bit */ | ||
if (align) { | ||
|
@@ -512,7 +512,7 @@ _convert_from_list(PyObject *obj, int align) | |
PyObject *nameslist = NULL; | ||
int ret; | ||
int maxalign = 0; | ||
int dtypeflags = 0; | ||
char dtypeflags = 0; | ||
|
||
n = PyList_GET_SIZE(obj); | ||
/* | ||
|
@@ -844,7 +844,7 @@ _convert_from_dict(PyObject *obj, int align) | |
int n, i; | ||
int totalsize, itemsize; | ||
int maxalign = 0; | ||
int dtypeflags = 0; | ||
char dtypeflags = 0; | ||
int has_out_of_order_fields = 0; | ||
|
||
fields = PyDict_New(); | ||
|
@@ -2197,10 +2197,10 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args)) | |
} | ||
|
||
/* | ||
* returns 1 if this data-type has an object portion | ||
* used when setting the state because hasobject is not stored. | ||
* returns NPY_OBJECT_DTYPE_FLAGS if this data-type has an object portion used | ||
* when setting the state because hasobject is not stored. | ||
*/ | ||
static int | ||
static char | ||
_descr_find_object(PyArray_Descr *self) | ||
{ | ||
if (self->flags | ||
|
@@ -2247,7 +2247,8 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) | |
#endif | ||
PyObject *subarray, *fields, *names = NULL, *metadata=NULL; | ||
int incref_names = 1; | ||
int dtypeflags = 0; | ||
int int_dtypeflags = 0; | ||
char dtypeflags; | ||
|
||
if (self->fields == Py_None) { | ||
Py_INCREF(Py_None); | ||
|
@@ -2267,7 +2268,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) | |
#endif | ||
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian, | ||
&subarray, &names, &fields, &elsize, | ||
&alignment, &dtypeflags, &metadata)) { | ||
&alignment, &int_dtypeflags, &metadata)) { | ||
return NULL; | ||
#undef _ARGSTR_ | ||
} | ||
|
@@ -2280,7 +2281,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) | |
#endif | ||
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian, | ||
&subarray, &names, &fields, &elsize, | ||
&alignment, &dtypeflags)) { | ||
&alignment, &int_dtypeflags)) { | ||
return NULL; | ||
#undef _ARGSTR_ | ||
} | ||
|
@@ -2448,7 +2449,19 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) | |
self->alignment = alignment; | ||
} | ||
|
||
self->flags = dtypeflags; | ||
/* We use an integer converted to char for backward compatibility with | ||
* pickled arrays. Pickled arrays created with previous versions encoded | ||
* flags as an int even though it actually was a char in the PyArray_Descr | ||
* structure */ | ||
dtypeflags = int_dtypeflags; | ||
if (dtypeflags != int_dtypeflags) { | ||
PyErr_Format(PyExc_ValueError, | ||
"incorrect value for flags variable (overflow)"); | ||
return NULL; | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self->flags = dtypeflags; | ||
} | ||
|
||
if (version < 3) { | ||
self->flags = _descr_find_object(self); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.