RuntimeWarning when converting R vector into numpy array

Issue #58 resolved
Joseph Xu created an issue

Not much to explain, just a test case:


import numpy import rpy2.robjects as rob print numpy.array(rob.FloatVector([1,2,3])) getbuffer main:1: RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size. [ 1. 2. 3.] }}}

Even though it claims the sizes don't match, they in fact do, so it's not a functionality problem, just that the warning message is very annoying. I'm using python 2.7 with rpy2 2.1.7 and numpy 1.5.0.

Comments (8)

  1. Laurent Gautier
    • changed status to new
    • changed milestone to 2.2.0

    It seems that the very recent numpy 1.5 has moved to the preferential use of buffers whenever available, and rpy2 has buffers as an undocumented feature since 2.1.x. (the getbuffer printed is from a printf() call left behind).

    The error message is generated by numpy, and I am currently missing why it does. buffer format string says 'f' (that is a Python float, which I understood to correspond to an R double), and the len and itemsize are defined as:

      view->len = GET_LENGTH(sexp) * sizeof(double);
      view->itemsize = sizeof(double);

    When tracking thing down to numpy, I can spot the problem coming from the descr->elsize != view->itemsize, with descr tracked as coming from the nested calls.

      NPY_NO_EXPORT int_array_from_buffer_3118(PyObject *obj, PyObject **out);
      NPY_NO_EXPORT PyArray_Descr* _descriptor_from_pep3118_format(char *s);

    and finally

     descr = (PyArray_Descr*)PyObject_CallMethod(
            _numpy_internal, "_dtype_from_pep3118", "O", str);

    I gave up there. May be something to bring up on the numpy list.

  2. Laurent Gautier
    • changed milestone to 2.1.9

    I got an answer from the numpy list, and I have committed what should be a fix for the current problem. It will be part of the next bugfix release (2.1.9) when more testing has been done.

    The buffer interface has been been very little tested (I am still mainly developping with Python 2.6.x and numpy < 1.5). Further bug reports are welcome.

  3. Joseph Xu reporter
    • changed status to new

    I just pulled the hg repo and it works well for me. Thanks a lot for the quick fix.

  4. Log in to comment