Skip to content
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

Support for binary arrays #53

Open
vlad-nn opened this issue Nov 10, 2021 · 3 comments
Open

Support for binary arrays #53

vlad-nn opened this issue Nov 10, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@vlad-nn
Copy link

vlad-nn commented Nov 10, 2021

NLohmann JSON version 3.10.4 has binary arrays: https://json.nlohmann.me/api/basic_json/binary/
If such array is encountered in JSON object, pyjson::from_json() crashes with stack overflow because it falls to "else // Object" clause and then the for() loop tries to iterate over non-existing values, since binary array is not an object.

Proposed fix:

  1. Add include file:
    #include "pybind11/numpy.h"

  2. In pyjson::from_json() add:
    ...
    else if (j.is_binary())
    {
    const auto &bin = j.get_binary();
    return py::array( bin.size(), bin.data() );
    }
    else // Object
    {
    ...

@martinRenou
Copy link
Collaborator

Thanks for opening an issue!

Would your proposed fix make NumPy a hard dependency?

@vlad-nn
Copy link
Author

vlad-nn commented Nov 10, 2021

IMHO, not.
See, pybind11/numpy.h header is a part of pybind11 distro, and since pybind11 is header-only library, it does not create any extra dependency.
pybind11/numpy.h does not have any pragma linker directives, so I would assume no extra linking.

@martinRenou
Copy link
Collaborator

Cool :)

Would you be willing to open a PR?

@martinRenou martinRenou added the enhancement New feature or request label Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants