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

make doc_string examples order-independent by removing np.set_printoptions #7361

Merged
merged 1 commit into from Mar 20, 2024

Conversation

dschult
Copy link
Member

@dschult dschult commented Mar 20, 2024

Fix the pytest-randomly tests in networkx/linalg which started occasionally failing due to a new doc_string test that changed the print setting for numpy arrays. The printoptions were set to print 4 digits for array values. Luckily the example still fits in the code width using the standard 8 digits.

So this fix just removes the line that sets the numpy print options and expands the example to show 8 digits.

This should go in before v3.3

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

Ack, nice catch @dschult - the set_printoptions should've been a red flag that I missed during review!

This LGTM - alternatively if fewer digits is really desired then np.printoptions can be used as a context manager to prevent the issues with global option setting:

>>> with np.printoptions(precision=4):
...     print(nx.normalized_laplacian_matrix(DiG).toarray())

@dschult dschult merged commit 1b34ffe into networkx:main Mar 20, 2024
42 checks passed
@jarrodmillman jarrodmillman added this to the 3.3 milestone Mar 20, 2024
@dschult
Copy link
Member Author

dschult commented Mar 20, 2024

Thanks Ross and Matt for the 2 approvals -- I'm going to merge it myself just so the cron job can test it.

@dschult dschult deleted the printopts_in_examples branch March 20, 2024 20:40
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
…tions (networkx#7361)

remove np.set_printoptions from normalized_laplacian_matrix doc_string example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants