Skip to content

TST: Use legacy numpy 1.25 print - #15096

Merged
pllim merged 7 commits into
astropy:mainfrom
pllim:numpy-dev-legacy-print-hotfix
Aug 12, 2023
Merged

pllim merged 7 commits into
astropy:mainfrom
pllim:numpy-dev-legacy-print-hotfix

Conversation

@pllim

@pllim pllim commented Jul 26, 2023

Copy link
Copy Markdown
Member

Description

This pull request is to use legacy numpy 1.25 print so the new numpy 2.0 print will not break CI until we are ready to patch it properly over at #15065.

Temporary workaround for #15095

This patch is as suggested by seberg over at astropy/pyvo#464 (comment) and similar to bsipocz patch at astropy/pyvo#465 .

@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 "When to rebase and squash commits".
  • 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?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • 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?

@pllim pllim mentioned this pull request Jul 26, 2023
5 tasks done
@pllim

pllim commented Jul 26, 2023

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

Comment thread astropy/conftest.py Resolved
@pllim

pllim commented Jul 26, 2023 •

Copy link
Copy Markdown
Member Author

Hmm didn't fix everything; 10 of the remaining 13 failures are related.

@mhvk

mhvk commented Jul 26, 2023

Copy link
Copy Markdown
Contributor

I can push what I had but those remaining test failures should be fixed upstream -- clearly, we missed some legacy if statement here, so pinging @seberg.

@seberg

seberg commented Jul 27, 2023

Copy link
Copy Markdown
Contributor

I retriggered a build with the fix so you can iterate (in 30 minutes). I hope you are not using np.cast which is now removed unless complains come in :).

@pllim

pllim commented Jul 27, 2023 •

Copy link
Copy Markdown
Member Author

Well, since you brought up np.cast, looks like scipy is using it, @seberg . 😬

Both numpy and scipy are from dev wheels hosted by Scientific Python.

gwcs/wcs.py:18: in <module>
    from scipy import linalg, optimize
scipy/__init__.py:189: in __getattr__
    return _importlib.import_module(f'scipy.{name}')
scipy/linalg/__init__.py:208: in <module>
    from ._basic import *
scipy/linalg/_basic.py:13: in <module>
    from ._decomp import _asarray_validated
scipy/linalg/_decomp.py:22: in <module>
    from numpy import (array, isfinite, inexact, nonzero, iscomplexobj, cast,
E   ImportError: cannot import name 'cast' from 'numpy' (numpy/__init__.py)

Update: Looks like scipy removed it in scipy/scipy#18973 so I guess they have to push a new dev wheel out?

@seberg

seberg commented Jul 27, 2023

Copy link
Copy Markdown
Contributor

Yeah, scipy is working on that, sorry. (not sure if you use it, if you do chime in your opinion if you think it should stay; personally, I actually don't think np.cast is worth the trouble of skipping the deprecation, but would rather get one too many than a few too few.)

@pllim

pllim commented Jul 27, 2023

Copy link
Copy Markdown
Member Author

not sure if you use it

I do not use it personally, no. But I will wait to see what the CI here says until scipy dev wheel gets updated. Thanks for the heads up!

@pllim

pllim commented Jul 27, 2023

Copy link
Copy Markdown
Member Author

Only one related failure left!

____________________ TestStringFunctions.test_array2string _____________________

self = <Quantity 0. Jy>, unit = Unit(dimensionless), equivalencies = []

(a lot of stuff that leads to this...)

        # But not if the formatter is not relevant for us.
>       out4 = np.array2string(self.q, separator=", ", formatter={"int": str})

astropy/units/tests/test_quantity_non_ufuncs.py:1764: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy/units/quantity.py:1844: in __array_function__
    result = super().__array_function__(function, types, args, kwargs)
numpy/core/arrayprint.py:744: in array2string
    return _array2string(a, options, separator, prefix)
numpy/core/arrayprint.py:521: in wrapper
    return f(self, *args, **kwargs)
numpy/core/arrayprint.py:554: in _array2string
    lst = _formatArray(a, format_function, options['linewidth'],
numpy/core/arrayprint.py:897: in _formatArray
    return recurser(index=(),
numpy/core/arrayprint.py:853: in recurser
    word = recurser(index + (-i,), next_hanging_indent, next_width)
numpy/core/arrayprint.py:807: in recurser
    return format_function(a[index])
numpy/core/arrayprint.py:1047: in __call__
    return dragon4_positional(x,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Quantity 0. Jy>

    def __float__(self):
        try:
            return float(self.to_value(dimensionless_unscaled))
        except (UnitsError, TypeError):
>           raise TypeError(
                "only dimensionless scalar quantities can be "
                "converted to Python scalars"
            )
E           TypeError: only dimensionless scalar quantities can be converted to Python scalars

astropy/units/quantity.py:1351: TypeError

@pllim

This comment was marked as resolved.

@mhvk

mhvk commented Aug 11, 2023

Copy link
Copy Markdown
Contributor

@pllim - I pushed a fix to the units error, but am getting lots of errors due to inconsistencies between scipy and numpy (from modelling). I also updated #15065 (but that's best discussed there). It is all a bit of a mess...

@pllim

pllim commented Aug 11, 2023

Copy link
Copy Markdown
Member Author

@WilliamJamieson is aware of the modeling stuff but not sure when he has time to fix those...

@pllim

This comment was marked as resolved.

Comment thread setup.cfg Resolved
@mhvk

mhvk commented Aug 11, 2023

Copy link
Copy Markdown
Contributor

Agreed that we should wait out the scipy-dev being brought up to date; they did fix the exceptions being moved in scipy/scipy#19015

@pllim
pllim force-pushed the numpy-dev-legacy-print-hotfix branch from 12e5d13 to ea2f8e4 Compare August 11, 2023 18:34
@mhvk
mhvk force-pushed the numpy-dev-legacy-print-hotfix branch from ea2f8e4 to d3a463d Compare August 11, 2023 18:58
@pllim pllim added the Extra CI Run cron CI as part of PR label Aug 11, 2023
else:
# See whether it covers our dtype.
from numpy.core.arrayprint import _get_format_function
from numpy.core.arrayprint import _get_format_function, _make_options_dict

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mhvk , should we not use hidden functions from deep within numpy? I am afraid further refactoring upstream will come back to bite us here.

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.

In principle, yes, and clearly here my initial implementation was even wrong! (since without _make_options_dict, the legacy option does not get properly translated into an integer). But the alternative is duplication of the whole arrayprint module...

Anyway, I hope this will become moot: in the initial scalar work, a public version of _get_format_function was included, and I think this is still likely to happen. Once that is there, we can just switch to using it.

pllim and others added 3 commits August 11, 2023 17:57
so the new numpy 2.0 print will not break CI
until we are ready to patch it properly.
@pllim
pllim force-pushed the numpy-dev-legacy-print-hotfix branch from a957751 to 5433c6d Compare August 11, 2023 21:57
pllim added 3 commits August 11, 2023 18:13
because we moved it for pydata-sphinx-theme
tests for modeling when TRFLSQFitter is used

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@WilliamJamieson , I went ahead and kinda ignore the new modeling warnings from scipy dev. Will open a follow-up issue for you later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually I will just update #15087 when this is merged.

@pllim

pllim commented Aug 11, 2023

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@pllim

pllim commented Aug 11, 2023

Copy link
Copy Markdown
Member Author

argh devdeps finally green...

@pllim

pllim commented Aug 12, 2023

Copy link
Copy Markdown
Member Author

Wut? Why would cosmology doctest fail only on s390x? @nstarman , do you know what is going on here?

_____________________ [doctest] astropy.cosmology._io.yaml _____________________
  004 
  005 This module provides functions to transform a |Cosmology| object to and from a `yaml
  006 <https://yaml.org/>`_ representation. The functions are registered with
  007 ``convert_registry`` under the format name "yaml". This format is primarily intended for
  008 use by other I/O functions, e.g. |Table|'s metadata serialization, which themselves
  009 require YAML serialization.
  010 
  011     >>> from astropy.cosmology import Planck18
  012     >>> yml = Planck18.to_format("yaml")
  013     >>> yml
  Expected:
      "!astropy.cosmology.flrw.FlatLambdaCDM\nH0: !astropy.units.Quantity\n
      unit: !astropy.units.Unit {unit: km / (Mpc s)}\n  value: 67.66\nNeff: 3.046\nOb0:
      0.04897\nOm0: 0.30966\nTcmb0: !astropy.units.Quantity\n  unit: !astropy.units.Unit
      {unit: K}\n  value: 2.7255\nm_nu: !astropy.units.Quantity\n
      unit: !astropy.units.Unit {unit: eV}\n  value: !numpy.ndarray\n
      buffer: !!binary |\n      QUFBQUFBQUFBQUFBQUFBQUFBQUFBTGdlaGV0UnVLNC8=\n
      dtype: float64\n    order: C\n    shape: !!python/tuple [3]\nmeta:
      !!python/tuple\n- !!python/tuple [Oc0, 0.2607]\n- !!python/tuple [n, 0.9665]\n-
      !!python/tuple [sigma8, 0.8102]\n- !!python/tuple [tau, 0.0561]\n- !!python/tuple\n
      - z_reion\n  - !astropy.units.Quantity\n    unit: !astropy.units.Unit {unit:
      redshift}\n    value: 7.82\n- !!python/tuple\n  - t0\n  - !astropy.units.Quantity\n
      unit: !astropy.units.Unit {unit: Gyr}\n    value: 13.787\n- !!python/tuple [flat,
      true]\n- !!python/tuple [reference, 'Planck Collaboration 2018, 2020, A&A, 641, A6
      (Paper\n    VI), Table 2 (TT, TE, EE + lowE + lensing + BAO)']\nname: Planck18\n"
  Got:
      "!astropy.cosmology.flrw.FlatLambdaCDM\nH0: !astropy.units.Quantity\n  unit: !astropy.units.Unit {unit: km / (Mpc s)}\n  value: 67.66\nNeff: 3.046\nOb0: 0.04897\nOm0: 0.30966\nTcmb0: !astropy.units.Quantity\n  unit: !astropy.units.Unit {unit: K}\n  value: 2.7255\nm_nu: !astropy.units.Quantity\n  unit: !astropy.units.Unit {unit: eV}\n  value: !numpy.ndarray\n    buffer: !!binary |\n      QUFBQUFBQUFBQUFBQUFBQUFBQUFBRCt1dUZIcmhSNjQ=\n    dtype: float64\n    order: C\n    shape: !!python/tuple [3]\nmeta: !!python/tuple\n- !!python/tuple [Oc0, 0.2607]\n- !!python/tuple [n, 0.9665]\n- !!python/tuple [sigma8, 0.8102]\n- !!python/tuple [tau, 0.0561]\n- !!python/tuple\n  - z_reion\n  - !astropy.units.Quantity\n    unit: !astropy.units.Unit {unit: redshift}\n    value: 7.82\n- !!python/tuple\n  - t0\n  - !astropy.units.Quantity\n    unit: !astropy.units.Unit {unit: Gyr}\n    value: 13.787\n- !!python/tuple [flat, true]\n- !!python/tuple [reference, 'Planck Collaboration 2018, 2020, A&A, 641, A6  (Paper\n    VI), Table 2 (TT, TE, EE + lowE + lensing + BAO)']\nname: Planck18\n"
  
  /home/runner/work/astropy/astropy/astropy/cosmology/_io/yaml.py:13: DocTestFailure
  _________________ [doctest] astropy.cosmology._io.yaml.to_yaml _________________
  205 
  206     Returns
  207     -------
  208     str
  209         :mod:`yaml` representation of |Cosmology| object
  210 
  211     Examples
  212     --------
  213     >>> from astropy.cosmology import Planck18
  214     >>> Planck18.to_format("yaml")
  Expected:
      "!astropy.cosmology.flrw.FlatLambdaCDM\nH0: !astropy.units.Quantity\n
      unit: !astropy.units.Unit {unit: km / (Mpc s)}\n  value: 67.66\nNeff: 3.046\nOb0:
      0.04897\nOm0: 0.30966\nTcmb0: !astropy.units.Quantity\n  unit: !astropy.units.Unit
      {unit: K}\n  value: 2.7255\nm_nu: !astropy.units.Quantity\n
      unit: !astropy.units.Unit {unit: eV}\n  value: !numpy.ndarray\n
      buffer: !!binary |\n      QUFBQUFBQUFBQUFBQUFBQUFBQUFBTGdlaGV0UnVLNC8=\n
      dtype: float64\n    order: C\n    shape: !!python/tuple [3]\nmeta:
      !!python/tuple\n- !!python/tuple [Oc0, 0.2607]\n- !!python/tuple [n, 0.9665]\n-
      !!python/tuple [sigma8, 0.8102]\n- !!python/tuple [tau, 0.0561]\n- !!python/tuple\n
      - z_reion\n  - !astropy.units.Quantity\n    unit: !astropy.units.Unit {unit:
      redshift}\n    value: 7.82\n- !!python/tuple\n  - t0\n  - !astropy.units.Quantity\n
      unit: !astropy.units.Unit {unit: Gyr}\n    value: 13.787\n- !!python/tuple [flat,
      true]\n- !!python/tuple [reference, 'Planck Collaboration 2018, 2020, A&A, 641, A6
      (Paper\n    VI), Table 2 (TT, TE, EE + lowE + lensing + BAO)']\nname: Planck18\n"
  Got:
      "!astropy.cosmology.flrw.FlatLambdaCDM\nH0: !astropy.units.Quantity\n  unit: !astropy.units.Unit {unit: km / (Mpc s)}\n  value: 67.66\nNeff: 3.046\nOb0: 0.04897\nOm0: 0.30966\nTcmb0: !astropy.units.Quantity\n  unit: !astropy.units.Unit {unit: K}\n  value: 2.7255\nm_nu: !astropy.units.Quantity\n  unit: !astropy.units.Unit {unit: eV}\n  value: !numpy.ndarray\n    buffer: !!binary |\n      QUFBQUFBQUFBQUFBQUFBQUFBQUFBRCt1dUZIcmhSNjQ=\n    dtype: float64\n    order: C\n    shape: !!python/tuple [3]\nmeta: !!python/tuple\n- !!python/tuple [Oc0, 0.2607]\n- !!python/tuple [n, 0.9665]\n- !!python/tuple [sigma8, 0.8102]\n- !!python/tuple [tau, 0.0561]\n- !!python/tuple\n  - z_reion\n  - !astropy.units.Quantity\n    unit: !astropy.units.Unit {unit: redshift}\n    value: 7.82\n- !!python/tuple\n  - t0\n  - !astropy.units.Quantity\n    unit: !astropy.units.Unit {unit: Gyr}\n    value: 13.787\n- !!python/tuple [flat, true]\n- !!python/tuple [reference, 'Planck Collaboration 2018, 2020, A&A, 641, A6  (Paper\n    VI), Table 2 (TT, TE, EE + lowE + lensing + BAO)']\nname: Planck18\n"
  
  /home/runner/work/astropy/astropy/astropy/cosmology/_io/yaml.py:214: DocTestFailure

@nstarman

nstarman commented Aug 12, 2023 •

Copy link
Copy Markdown
Member

I noticed something similar to this in a recent PR (#15102) if you want to cherry-pick the fix.

@mhvk mhvk 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.

Thanks! I think these changes all look fine, and it may be best to just merge this, and work on other issues separately.

p.s. It would seem there is a case for keeping the different commits separate (for possible reversion later on).

@pllim
pllim marked this pull request as ready for review August 12, 2023 18:48
@pllim
pllim requested a review from a team as a code owner August 12, 2023 18:48
@pllim
pllim merged commit 4bf05d9 into astropy:main Aug 12, 2023
@pllim
pllim deleted the numpy-dev-legacy-print-hotfix branch August 12, 2023 18:48
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Aug 12, 2023
@pllim

pllim commented Aug 12, 2023 •

Copy link
Copy Markdown
Member Author

Thanks, all! I will open follow-up issues update existing issues.

@nstarman , I cherry-picked as you suggested over at #15165

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.

5 participants