summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMark Wiebe <mwiebe@enthought.com>2011-07-25 18:33:53 -0500
committerCharles Harris <charlesr.harris@gmail.com>2011-08-27 07:26:47 -0600
commitf3d05b6a5b3eb84047296235141a8ba6815df762 (patch)
tree4d092a0c60fe8361cea65547f6b98041b5a3c946 /numpy
parent02b42b5823019052b28e68b01c733b4f281eda59 (diff)
downloadnumpy-f3d05b6a5b3eb84047296235141a8ba6815df762.tar.gz
ENH: missingdata: Really simple printing with NA works in some cases now too
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/arrayprint.py6
-rw-r--r--numpy/core/src/multiarray/mapping.c2
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c16
-rw-r--r--numpy/core/src/multiarray/na_mask.c48
-rw-r--r--numpy/core/src/multiarray/na_mask.h19
5 files changed, 85 insertions, 6 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 8f82ddcd7..0786b2904 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -15,7 +15,7 @@ __docformat__ = 'restructuredtext'
import sys
import numerictypes as _nt
from umath import maximum, minimum, absolute, not_equal, isnan, isinf
-from multiarray import format_longfloat, datetime_as_string, datetime_data
+from multiarray import format_longfloat, datetime_as_string, datetime_data, isna
from fromnumeric import ravel
@@ -477,8 +477,6 @@ def _formatArray(a, format_function, rank, max_line_len,
s, line = _extendLine(s, line, summary_insert1, max_line_len, next_line_prefix)
for i in xrange(trailing_items, 1, -1):
- print "bad index: ", i
- print "length: ", len(a)
word = format_function(a[-i]) + separator
s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)
@@ -637,7 +635,7 @@ class IntegerFormat(object):
pass
def __call__(self, x):
- if _MININT < x < _MAXINT:
+ if not isna(x) and _MININT < x < _MAXINT:
return self.format % x
else:
return "%s" % x
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 0f5028c28..98a8c00f4 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -54,8 +54,6 @@ array_big_item(PyArrayObject *self, npy_intp i)
return NULL;
}
- printf("array_big_item\n");
-
/* Bounds check and get the data pointer */
dim0 = PyArray_DIM(self, 0);
if (i < 0) {
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index d18721333..f10a0de81 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -49,6 +49,7 @@ NPY_NO_EXPORT int NPY_NUMUSERTYPES = 0;
#include "datetime_busday.h"
#include "datetime_busdaycal.h"
#include "na_singleton.h"
+#include "na_mask.h"
/* Only here for API compatibility */
NPY_NO_EXPORT PyTypeObject PyBigArray_Type;
@@ -2464,6 +2465,18 @@ finish:
}
static PyObject *
+array_isna(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
+{
+ PyObject *a;
+ static char *kwlist[] = {"a", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:isna", kwlist, &a)) {
+ return NULL;
+ }
+ return PyArray_IsNA(a);
+}
+
+static PyObject *
array_fastCopyAndTranspose(PyObject *NPY_UNUSED(dummy), PyObject *args)
{
PyObject *a0;
@@ -3517,6 +3530,9 @@ static struct PyMethodDef array_module_methods[] = {
{"einsum",
(PyCFunction)array_einsum,
METH_VARARGS|METH_KEYWORDS, NULL},
+ {"isna",
+ (PyCFunction)array_isna,
+ METH_VARARGS|METH_KEYWORDS, NULL},
{"_fastCopyAndTranspose",
(PyCFunction)array_fastCopyAndTranspose,
METH_VARARGS, NULL},
diff --git a/numpy/core/src/multiarray/na_mask.c b/numpy/core/src/multiarray/na_mask.c
index 0e192ba42..eb3256cdf 100644
--- a/numpy/core/src/multiarray/na_mask.c
+++ b/numpy/core/src/multiarray/na_mask.c
@@ -244,3 +244,51 @@ PyArray_AssignNA(PyArrayObject *arr, NpyNA *na)
Py_DECREF(maskdtype);
return 0;
}
+
+/*
+ * A ufunc-like function, which returns a boolean or an array
+ * of booleans indicating which values are NA.
+ */
+NPY_NO_EXPORT PyObject *
+PyArray_IsNA(PyObject *obj)
+{
+ /* NA objects are NA */
+ if (NpyNA_Check(obj)) {
+ Py_INCREF(Py_True);
+ return Py_True;
+ }
+ /* Otherwise non-array objects are not NA */
+ else if (!PyArray_Check(obj)) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ /* Create a boolean array based on the mask */
+ else {
+ //PyArrayObject *ret;
+ PyArray_Descr *dtype;
+
+ if (PyArray_HASFIELDS((PyArrayObject *)obj)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "field-NA is not supported yet");
+ return NULL;
+ }
+
+ PyErr_SetString(PyExc_RuntimeError,
+ "isna isn't done yet");
+ return NULL;
+
+ dtype = PyArray_DescrFromType(NPY_BOOL);
+ if (dtype == NULL) {
+ return NULL;
+ }
+
+ /* TODO: Set up iterator, etc */
+
+ if (!PyArray_HasNASupport((PyArrayObject *)obj)) {
+ /* TODO */
+ }
+ else {
+ /* TODO */
+ }
+ }
+}
diff --git a/numpy/core/src/multiarray/na_mask.h b/numpy/core/src/multiarray/na_mask.h
new file mode 100644
index 000000000..9cc42b379
--- /dev/null
+++ b/numpy/core/src/multiarray/na_mask.h
@@ -0,0 +1,19 @@
+#ifndef _NPY_PRIVATE__NA_MASK_H_
+#define _NPY_PRIVATE__NA_MASK_H_
+
+/*
+ * Assigns the given NA value to all the elements in the array.
+ *
+ * Returns -1 on failure, 0 on success.
+ */
+NPY_NO_EXPORT int
+PyArray_AssignNA(PyArrayObject *arr, NpyNA *na);
+
+/*
+ * A ufunc-like function, which returns a boolean or an array
+ * of booleans indicating which values are NA.
+ */
+NPY_NO_EXPORT PyObject *
+PyArray_IsNA(PyObject *obj);
+
+#endif