Skip to content

Fix bug in Wcs.wcs.print_contents() related to stdout buffer not bein… - #18350

Merged
mcara merged 4 commits into
astropy:mainfrom
astrofrog:wcs-flush-stdout
Jul 12, 2025
Merged

mcara merged 4 commits into
astropy:mainfrom
astrofrog:wcs-flush-stdout

Conversation

@astrofrog

Copy link
Copy Markdown
Member

Description

I ran into this when working on #18338 but it is a bug that exists in main - the short version is that WCS.wcs.print_contents() was not flushing stdout, which was causing the output of print_contents() to be truncated and to then pollute subsequent tests using print_contents. When I added the print_contents() test here, it caused another test to fail:

_______________________________________________________________________________ test_wtbarr_print ________________________________________________________________________________

tab_wcs_2di = WCS Keywords

Number of WCS axes: 2
CTYPE : 'RA---TAB' 'DEC--TAB' 
CRVAL : 1.0 1.0 
CRPIX : 1.0 1.0 
PC1_1 PC1_2  : 1.0 0.0 
PC2_1 PC2_2  : 0.0 1.0 
CDELT : 1.0 1.0 
NAXIS : 150  200
capfd = <_pytest.capture.CaptureFixture object at 0x7fa127e7b690>

    def test_wtbarr_print(tab_wcs_2di, capfd):
        tab_wcs_2di.wcs.wtb[0].print_contents()
        captured = capfd.readouterr()
        s = str(tab_wcs_2di.wcs.wtb[0])
        lines = s.split("\n")
>       assert captured.out == s
E       assert 'g: 0\n       code: "   "\n         r0:  0.000000\n         pv: (not used)\n       phi0: UNDEFINED\n     theta0: UNDEFINED\n     bounds: 7\n\n       name: "undefined"\n   category: 0 (undefined)\n    pvrange: 0\n  simplezen: 0\n  equiareal: 0\n  conformal: 0\n     global: 0\n  divergent: 0\n         x0: 0.000000\n         y0: 0.000000\n        err: 0x0\n        w[]:   0.0000       0.0000       0.0000       0.0000       0.0000    \n               0.0000       0.0000       0.0000       0.0000       0.0000    \n          m: 0\n          n: 0\n     prjx2s: 0x0\n     prjs2x: 0x0\n\n   spc.*\n       flag: 0\n       type: "    "\n       code: "   "\n      crval: UNDEFINED\n    restfrq: 0.000000\n    restwav: 0.000000\n         pv: (not used)\n          w:   0.0000       0.0000       0.0000      (remainder unused)\n    isGrism: 0\n        err: 0x0\n     spxX2P: 0x0\n     spxP2S: 0x0\n     spxS2P: 0x0\n     spxP2X: 0x0\n     i: 1\n     m: 1\n  kind: c\nextnam: WCS-TABLE\nextver: 1\nextlev: 1\n ttype: wavelength\n   row: 1\n  ndim: 3\ndimlen: 0x2d7057c0\n        0:   4\n        1:   2\narrayp: 0x2dc8a8c8\n' == '     i: 1\n     m: 1\n  kind: c\nextnam: WCS-TABLE\nextver: 1\nextlev: 1\n ttype: wavelength\n   row: 1\n  ndim: 3\ndimlen: 0x2d7057c0\n        0:   4\n        1:   2\narrayp: 0x2dc8a8c8\n'
E         
E         + g: 0
E         +        code: "   "
E         +          r0:  0.000000
E         +          pv: (not used)
E         +        phi0: UNDEFINED
E         +      theta0: UNDEFINED
E         +      bounds: 7
E         + 
E         +        name: "undefined"
E         +    category: 0 (undefined)
E         +     pvrange: 0
E         +   simplezen: 0
E         +   equiareal: 0
E         +   conformal: 0
E         +      global: 0
E         +   divergent: 0
E         +          x0: 0.000000
E         +          y0: 0.000000
E         +         err: 0x0
E         +         w[]:   0.0000       0.0000       0.0000       0.0000       0.0000    
E         +                0.0000       0.0000       0.0000       0.0000       0.0000    
E         +           m: 0
E         +           n: 0
E         +      prjx2s: 0x0
E         +      prjs2x: 0x0
E         + 
E         +    spc.*
E         +        flag: 0
E         +        type: "    "
E         +        code: "   "
E         +       crval: UNDEFINED
E         +     restfrq: 0.000000
E         +     restwav: 0.000000
E         +          pv: (not used)
E         +           w:   0.0000       0.0000       0.0000      (remainder unused)
E         +     isGrism: 0
E         +         err: 0x0
E         +      spxX2P: 0x0
E         +      spxP2S: 0x0
E         +      spxS2P: 0x0
E         +      spxP2X: 0x0
E                i: 1
E                m: 1
E             kind: c
E           extnam: WCS-TABLE
E           extver: 1
E           extlev: 1
E            ttype: wavelength
E              row: 1
E             ndim: 3
E           dimlen: 0x2d7057c0
E                   0:   4
E                   1:   2
E           arrayp: 0x2dc8a8c8

astropy/wcs/tests/test_wtbarr.py:45: AssertionError

because the print_contents() output of wtb[0] contained leftover output from the top-level print_contents.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@astrofrog astrofrog added the Bug label Jun 26, 2025
@github-actions github-actions Bot added the wcs label Jun 26, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@astrofrog astrofrog added this to the v7.1.1 milestone Jun 26, 2025
@astrofrog
astrofrog marked this pull request as ready for review June 26, 2025 08:33
@astrofrog
astrofrog requested a review from mcara as a code owner June 26, 2025 08:33

@mcara mcara left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mcara
mcara merged commit 530f3b4 into astropy:main Jul 12, 2025
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Jul 12, 2025
pllim added a commit that referenced this pull request Jul 12, 2025
…350-on-v7.1.x

Backport PR #18350 on branch v7.1.x (Fix bug in Wcs.wcs.print_contents() related to stdout buffer not bein…)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants