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

Add const T to docstring generation. #3020

Merged
merged 11 commits into from
Jun 8, 2021

Conversation

jhale
Copy link
Contributor

@jhale jhale commented May 26, 2021

Description

When using const T in pyarray auto-generated documentation shows long double type.

Suggested changelog entry:

Fix auto-generated documentation string when using ``const T`` in ``pyarray_t``.

@rwgk
Copy link
Collaborator

rwgk commented May 27, 2021

Hi @jhale, I think the valgrind error is unrelated (looks like pocketfft suppression needs to be updated again), but could you please add a test that fails without your change, and passes with your change?

@rwgk
Copy link
Collaborator

rwgk commented May 27, 2021

I fixed the valgrind error. If you rebase this PR on master the CI should come back clean.

@jhale
Copy link
Contributor Author

jhale commented Jun 7, 2021

I've added a test that fails on master and passes with my branch.

On master the returned docstring for both is: const_float(arg0: numpy.ndarray[numpy.longdouble]) -> None\n

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please fix the Format issue? — I usually blindly run pre-commit run --all-files. See .github/CONTRIBUTING.md.

Please ignore the Centos 8 failure, that's a general breakage as of ~4 days ago.

@@ -481,6 +481,9 @@ def test_index_using_ellipsis():
a = m.index_using_ellipsis(np.zeros((5, 6, 7)))
assert a.shape == (6,)

def test_format_descriptors_for_const_types():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, could you please add corresponding non-const tests, even if redundant (I didn't look if that's covered elsewhere already). It's usually good to exercise closely related contrasting functionality together, especially if it's super easy, as in this case.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@@ -437,4 +437,10 @@ TEST_SUBMODULE(numpy_array, sm) {
sm.def("accept_double_f_style_forcecast_noconvert",
[](py::array_t<double, py::array::forcecast | py::array::f_style>) {},
"a"_a.noconvert());

// Check that types returns correct npy format descriptor
sm.def("float", [](py::array_t<float>) {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight worry about clash with built-in float. Could you please prepend array_ (or similar) to all functions to make the names more unique?

Copy link
Collaborator

@rwgk rwgk Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured you're in a European time zone, so I went ahead and started working on the prefix. When I looked more closely I decided test_fmt_desc_ is better as a prefix, and while I was at it I also condensed the test and made it less platform-specific.

I also double-checked that the new test fails without your change to the include:

test_numpy_array.py .....................................FF.............                                                                                                               [100%]

========================================================================================== FAILURES ==========================================================================================
________________________________________________________ test_format_descriptors_for_floating_point_types[test_fmt_desc_const_float] _________________________________________________________

test_func = <built-in method test_fmt_desc_const_float of PyCapsule object at 0x7fba1ce05c60>

    @pytest.mark.parametrize(
        "test_func",
        [
            m.test_fmt_desc_float,
            m.test_fmt_desc_double,
            m.test_fmt_desc_const_float,
            m.test_fmt_desc_const_double,
        ],
    )
    def test_format_descriptors_for_floating_point_types(test_func):
>       assert "numpy.ndarray[numpy.float" in test_func.__doc__
E       AssertionError: assert 'numpy.ndarray[numpy.float' in 'test_fmt_desc_const_float(arg0: numpy.ndarray[numpy.longdouble]) -> None\n'
E        +  where 'test_fmt_desc_const_float(arg0: numpy.ndarray[numpy.longdouble]) -> None\n' = <built-in method test_fmt_desc_const_float of PyCapsule object at 0x7fba1ce05c60>.__doc__

test_numpy_array.py:495: AssertionError
________________________________________________________ test_format_descriptors_for_floating_point_types[test_fmt_desc_const_double] ________________________________________________________

test_func = <built-in method test_fmt_desc_const_double of PyCapsule object at 0x7fba1ce05c90>

    @pytest.mark.parametrize(
        "test_func",
        [
            m.test_fmt_desc_float,
            m.test_fmt_desc_double,
            m.test_fmt_desc_const_float,
            m.test_fmt_desc_const_double,
        ],
    )
    def test_format_descriptors_for_floating_point_types(test_func):
>       assert "numpy.ndarray[numpy.float" in test_func.__doc__
E       AssertionError: assert 'numpy.ndarray[numpy.float' in 'test_fmt_desc_const_double(arg0: numpy.ndarray[numpy.longdouble]) -> None\n'
E        +  where 'test_fmt_desc_const_double(arg0: numpy.ndarray[numpy.longdouble]) -> None\n' = <built-in method test_fmt_desc_const_double of PyCapsule object at 0x7fba1ce05c90>.__doc__

test_numpy_array.py:495: AssertionError
================================================================================ 2 failed, 50 passed in 0.40s ================================================================================

Ralf W. Grosse-Kunstleve added 2 commits June 8, 2021 10:22
…nctions even if one fails; 3. be less platform-specific (e.g. C++ float is not necessarily float32).
@rwgk
Copy link
Collaborator

rwgk commented Jun 8, 2021

CI looks good, except for the Centos 8 build with is known to be broken for unrelated reasons. I'll merge this PR now. Thanks @jhale for the fix!

@rwgk rwgk merged commit 4c7697d into pybind:master Jun 8, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jun 8, 2021
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jul 13, 2021
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

Successfully merging this pull request may close these issues.

3 participants