8000 BUG numpy.frombuffer fails on zero-sized dtype · Issue #12043 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG numpy.frombuffer fails on zero-sized dtype #12043

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
pierreglaser opened this issue Sep 27, 2018 · 1 comment
Closed

BUG numpy.frombuffer fails on zero-sized dtype #12043

pierreglaser opened this issue Sep 27, 2018 · 1 comment

Comments

@pierreglaser
Copy link
Contributor
pierreglaser commented Sep 27, 2018

Hi,
Trying to create an numpy array with a zero sized dtype

import numpy
numpy.frombuffer(b'',dtype='S')

raises

ValueError: itemsize cannot be zero in type

(Version: numpy==1.15.1, python 3.7.0b3)

This comes from a check in the PyArray_FromBuffer method in ctors.c

    if (PyDataType_ISUNSIZED(type)) {
        PyErr_SetString(PyExc_ValueError,
                        "itemsize cannot be zero in type");
        Py_DECREF(type);
        return NULL;
    }

Issue #3926 was facing a similar problem: it couldn't pickle-depickle empty-strings, due to a similar check, and was adressed by removing the check on the size (PR #5475)

My opinion is that we can produce a similar solution, but I am waiting for senior contributors to weigh in on that.

Related: PR #12011 that uses frombuffer to reconstruct serialized arrays.

Pinging @ogrisel

@pierreglaser
Copy link
Contributor Author

After giving it more thoughts, reconstructing an array from a buffer using a zero-sized dtype should be undefined. Closing as not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0