diff options
author | Mark Wiebe <mwiebe@enthought.com> | 2011-07-22 15:29:13 -0500 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-08-27 07:26:46 -0600 |
commit | fecb76173a5ac2555f4aa9062388ca62d1f781c8 (patch) | |
tree | b229fe480f404ee85556e0681732a1388c80d403 /numpy | |
parent | 47b86408deb225b6eac8fe398189adaa607c9c20 (diff) | |
download | numpy-fecb76173a5ac2555f4aa9062388ca62d1f781c8.tar.gz |
ENH: missingdata: Use NPY_NA_NOPAYLOAD instead of constant 255 everywhere
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/na_singleton.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/numpy/core/src/multiarray/na_singleton.c b/numpy/core/src/multiarray/na_singleton.c index b0c7ec3fe..f7097b340 100644 --- a/numpy/core/src/multiarray/na_singleton.c +++ b/numpy/core/src/multiarray/na_singleton.c @@ -29,8 +29,7 @@ na_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) self = (NpyNA_fieldaccess *)subtype->tp_alloc(subtype, 0); if (self != NULL) { - /* 255 signals no payload */ - self->payload = 255; + self->payload = NPY_NA_NOPAYLOAD; self->dtype = NULL; self->is_singleton = 0; } @@ -52,9 +51,9 @@ na_init(NpyNA_fieldaccess *self, PyObject *args, PyObject *kwds) return -1; } - /* Use 255 as the signal that no payload is set */ + /* Using NPY_MAX_INT as the default for 'payload' */ if (payload == NPY_MAX_INT) { - self->payload = 255; + self->payload = NPY_NA_NOPAYLOAD; } else if (payload < 0 || payload > 127) { PyErr_Format(PyExc_ValueError, @@ -105,7 +104,7 @@ static PyObject * na_repr(NpyNA_fieldaccess *self) { if (self->dtype == NULL) { - if (self->payload == 255) { + if (self->payload == NPY_NA_NOPAYLOAD) { return PyUString_FromString("NA"); } else { @@ -114,7 +113,7 @@ na_repr(NpyNA_fieldaccess *self) } else { PyObject *s; - if (self->payload == 255) { + if (self->payload == NPY_NA_NOPAYLOAD) { s = PyUString_FromString("NA(dtype="); } else { @@ -135,7 +134,7 @@ na_repr(NpyNA_fieldaccess *self) static PyObject * na_str(NpyNA_fieldaccess *self) { - if (self->payload == 255) { + if (self->payload == NPY_NA_NOPAYLOAD) { return PyUString_FromString("NA"); } else { @@ -164,8 +163,7 @@ na_richcompare(NpyNA_fieldaccess *self, PyObject *other, int cmp_op) static PyObject * na_payload_get(NpyNA_fieldaccess *self) { - /* If no payload is set, the value stored is 255 */ - if (self->payload == 255) { + if (self->payload == NPY_NA_NOPAYLOAD) { Py_INCREF(Py_None); return Py_None; } @@ -186,9 +184,8 @@ na_payload_set(NpyNA_fieldaccess *self, PyObject *value) "make a new copy like 'numpy.NA(payload)'"); return -1; } - /* Deleting the payload sets it to 255, the signal for no payload */ else if (value == NULL || value == Py_None) { - self->payload = 255; + self->payload = NPY_NA_NOPAYLOAD; } else { /* Use PyNumber_Index to ensure an integer in Python >= 2.5*/ @@ -619,7 +616,8 @@ NPY_NO_EXPORT PyTypeObject NpyNA_Type = { NPY_NO_EXPORT NpyNA_fieldaccess _Npy_NASingleton = { PyObject_HEAD_INIT(&NpyNA_Type) - 255, /* payload (255 means no payload) */ - NULL, /* dtype */ - 1 /* is_singleton */ + NPY_NA_NOPAYLOAD, /* payload */ + NULL, /* dtype */ + 1 /* is_singleton */ }; + |