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

Adding examples into function documentation #50

Open
2 of 5 tasks
matteobecchi opened this issue Dec 3, 2024 · 5 comments
Open
2 of 5 tasks

Adding examples into function documentation #50

matteobecchi opened this issue Dec 3, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@matteobecchi
Copy link
Contributor

matteobecchi commented Dec 3, 2024

It would be very nice to have an example of how to use each function, within the doc string of the function. The same way numpy does it.

It is already done for the LENS module, spatial_average() and the Shannon entropy functions. So it should be added in:

  • radial_distribution_function
  • onion (from the tropea-clustering package)
  • time_soap
  • soapify
  • hdf5er
@andrewtarzia
Copy link
Contributor

andrewtarzia commented Dec 3, 2024

One comment I have for this is to use the testcode functionality in sphinx to make them small unit tests, ensuring their accuracy, for example, you can place the code below into the doc string:

    Examples:
        .. testcode:: dynsight-test

            import dynsight

            x = dynsight.calculate_something()

        .. testcode:: dynsight-test
            :hide:
        
            assert x == 'something you know'

@matteobecchi matteobecchi added the documentation Improvements or additions to documentation label Dec 3, 2024
@matteobecchi matteobecchi mentioned this issue Dec 3, 2024
@matteobecchi
Copy link
Contributor Author

I modified, within tropea_clsutering, the doc strings of the functions imported by dynsight.onion, adding the examples.

When I run "just check" in tropea_clsutering, they are tested and work fine.

When I run "just check" in dynsight, some of the tests randomly fail, as if for some reason the random data used as input were changing. But the random seed is set, and there is no such issue in tropea_clustering.

@andrewtarzia
Copy link
Contributor

When I run "just check" in dynsight, some of the tests randomly fail, as if for some reason the random data used as input were changing. But the random seed is set, and there is no such issue in tropea_clustering.

  • Is it the same tests that fail? or is it actually random?
  • are the environments (all numpy versions and such) the same?

@matteobecchi
Copy link
Contributor Author

  • Is it the same tests that fail? or is it actually random?

It's actually random. Sometimes one of the four functions fails the test. Sometimes none of them.

  • are the environments (all numpy versions and such) the same?

There are many differences, among which numpy, Sphinx, ruff, scipy and scikit.learn. This could be the issue.

@matteobecchi
Copy link
Contributor Author

Equating the packages used in tropea and dynsight, the issue is solved.

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

No branches or pull requests

2 participants