Fix test case to be platform independent, note ARROW-1345. Improve quality of error message

Change-Id: I3bef642f3620396ea728b54fefe780b915d8fc32
This commit is contained in:
Wes McKinney committed 2017-08-09 14:09:39 -04:00
1 parent f4f44c18e7
commit f403f9dd2e
5 files changed
+46 -4

No files matched your search

+35
View File
@@ -64,6 +64,41 @@ class Ndarray1DIndexer {
int64_t stride_;
};
static inline std::string GetNumPyTypeName(int npy_type) {
#define TYPE_CASE(TYPE, NAME) \
case NPY_##TYPE: \
return NAME;
switch (npy_type) {
TYPE_CASE(BOOL, "bool")
TYPE_CASE(INT8, "int8")
TYPE_CASE(INT16, "int16")
TYPE_CASE(INT32, "int32")
TYPE_CASE(INT64, "int64")
#if (NPY_INT64 != NPY_LONGLONG)
TYPE_CASE(LONGLONG, "longlong")
#endif
TYPE_CASE(UINT8, "uint8")
TYPE_CASE(UINT16, "uint16")
TYPE_CASE(UINT32, "uint32")
TYPE_CASE(UINT64, "uint64")
#if (NPY_UINT64 != NPY_ULONGLONG)
TYPE_CASE(ULONGLONG, "ulonglong")
#endif
TYPE_CASE(FLOAT16, "float16")
TYPE_CASE(FLOAT32, "float32")
TYPE_CASE(FLOAT64, "float64")
TYPE_CASE(DATETIME, "datetime64")
TYPE_CASE(OBJECT, "object")
TYPE_CASE(VOID, "void")
default:
break;
}
#undef TYPE_CASE
return "unrecognized type in GetNumPyTypeName";
}
} // namespace py
} // namespace arrow
+6 -2
View File
@@ -151,8 +151,12 @@ Status CheckFlatNumpyArray(PyArrayObject* numpy_array, int np_type) {
return Status::Invalid("only handle 1-dimensional arrays");
}
if (PyArray_DESCR(numpy_array)->type_num != np_type) {
return Status::Invalid("can only handle exact conversions");
const int received_type = PyArray_DESCR(numpy_array)->type_num;
if (received_type != np_type) {
std::stringstream ss;
ss << "trying to convert NumPy type " << GetNumPyTypeName(np_type) << " but got "
<< GetNumPyTypeName(received_type);
return Status::Invalid(ss.str());
}
return Status::OK();
+2 -1
View File
@@ -65,7 +65,7 @@ cdef int check_status(const CStatus& status) nogil except -1:
return 0
with gil:
message = frombytes(status.ToString())
message = frombytes(status.message())
if status.IsInvalid():
raise ArrowInvalid(message)
elif status.IsIOError():
@@ -85,4 +85,5 @@ cdef int check_status(const CStatus& status) nogil except -1:
elif status.IsPlasmaStoreFull():
raise PlasmaStoreFull(message)
else:
message = frombytes(status.ToString())
raise ArrowException(message)
+1
View File
@@ -42,6 +42,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
CStatus()
c_string ToString()
c_string message()
c_bool ok()
c_bool IsIOError()
+2 -1
View File
@@ -99,7 +99,8 @@ def dataframe_with_lists(include_index=False):
[0, 1, 2, 3, 4],
None,
[0],
np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9] * 2)[::2]
np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9] * 2,
dtype=np.int64)[::2]
]
fields.append(pa.field('double', pa.list_(pa.float64())))
arrays['double'] = [