Skip to content

Wrong buffer format returned for similar numpy arrays passed to pybind11 function #1806

Closed
@JanuszL

Description

@JanuszL

Issue description

Function accepting pybind11::buffer reports different underlying type when provided with (at least at the first glance) numpy arrays. I can only guess it may be more related to numpy which somehow fails to comply with python's buffer protocol in some cases. But I want to make sure that pybind11 doesn't do anything that could affect this.

Reproducible example code

a = np.array([1, 2], dtype=np.longlong)
b = np.array([1, 2], dtype=np.int64)
some_native_function_accepting_py11buffer(a)
some_native_function_accepting_py11buffer(b)

a reports to have q format while b l which is wrong in b case. Numpy claims dtype as int64 for both of them.
Full repro attached, just issue run.sh (and make sure that pybind11 is present in the same dir as run.sh).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions