xtensor-stack / xtensor-python

Python bindings for xtensor
BSD 3-Clause "New" or "Revised" License
345 stars 58 forks source link

pyarray and pytensor names in auto-generated docstring #141

Closed PerretB closed 6 years ago

PerretB commented 6 years ago

Pyarray and pytensor rely on pybind11 make_caster<T>::name() to determine the string representation of its value_type (which is then used for the auto-generated docstring). However, make_caster assigns the name "int" to every integral type and "float" to every floating type (except for "char"->"str" and "bool"->"bool").

While this makes perfect sens for vanilla Python, this becomes confusing with Numpy where the precise numeric type is important. For example, defining the two overloaded test functions in the module m:

m.def("test", [](xt::pyarray<int>&a){});
m.def("test", [](xt::pyarray<long>&a){});

leads to the following docstring:

    test(*args, **kwargs)
    Overloaded function.

    1. test(arg0: numpy.ndarray[int]) -> None
    2. test(arg0: numpy.ndarray[int]) -> None

where the two overloads seem to have an identical signature.

Would it be possible to bypass pybind11 make_caster for types that corresponds to numpy dtypes such that we would get a correct docstring ? (something like: )

    1. test(arg0: numpy.ndarray[int32]) -> None
    2. test(arg0: numpy.ndarray[int64]) -> None
SylvainCorlay commented 6 years ago

Thanks @PerretB I agree that specifying the int32 and int64 flavors in the python docstrings would make a lot more sense.

wolfv commented 6 years ago

Done! :)