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

BUG: changed np.round(mean_diff,2) -> mean_diff:.2g to avoid trailing … #9125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jeswcollins
Copy link

…digits bug that appears in matplotlib figure output

  • closes #xxxx
  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

…digits bug that appears in matplotlib figure output
@jeswcollins jeswcollins changed the title fix: changed np.round(mean_dff,2) -> mean_diff:.2g to avoid trailing … BUG: changed np.round(mean_diff,2) -> mean_diff:.2g to avoid trailing … Jan 17, 2024
Copy link
Member

@bashtage bashtage left a comment

Choose a reason for hiding this comment

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

Need to ensure that the format doesn't change the value returned, but only prevents things like 1.23000000000001 from appearing.

@@ -114,7 +114,7 @@ def mean_diff_plot(m1, m2, sd_limit=1.96, ax=None, scatter_kwds=None,
ax.axhline(mean_diff, **mean_line_kwds) # draw mean line.

# Annotate mean line with mean difference.
ax.annotate(f'mean diff:\n{np.round(mean_diff, 2)}',
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to round first and then apply the format string, since I'm not sure the format string actually rounds - I think it might truncate,

 f"{4.229:0.2g}"
Out[2]: '4.2'

In [3]: f"{4.229:0.2g}"
Out[3]: '4.2'

In [5]: import numpy as np

In [6]: f"{np.round(4.229,2)}"
Out[6]: '4.23'

See how these are different. You should ensure that they are the same. I think the format should also be .3g ,

In [12]: f"{np.round(4.209,2)}"
Out[12]: '4.21'

In [13]: f"{np.round(4.209,2):.2g}"
Out[13]: '4.2'

In [14]: f"{np.round(4.209,2):.3g}"
Out[14]: '4.21'

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.

None yet

2 participants