Skip to content

TST: Handle new numpy 2.0.dev string representation #210

Open

Description

@pllim

Example log: https://github.com/scientific-python/pytest-doctestplus/actions/runs/5704149430/job/15457469475

____________________________ [doctest] module2.foo _____________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> foo(1, 2)
Expected:
    3.0
Got:
    np.float64(3.0)

module2.py:None: DocTestFailure

Activity

  1. bsipocz commented on Aug 1, 2023

    @bsipocz
    Member

    Shall we do the easy thing with the legacy printoption, or you rather suggest to make a new directive that does this flexibly? (I suppose we need to do the printoption either way to fix the CI, but for downstream, it maybe useful to have a directive? Or should they all just update the reprs?

    cc @seberg

  2. added this to the 1.0.0 milestone on Aug 1, 2023
  3. pllim commented on Aug 1, 2023

    @pllim
    ContributorAuthor

    I have mixed feeling about the new printout. This extra np.float64(...) really messes up the WCS print over at astropy.wcs. I wish there is a way to opt out permanently (not just temporarily).

  4. drammock commented on Aug 1, 2023

    @drammock
    Member

    @pllim IDK how astropy.wcs works, but would it work to redefine the __print__ and/or __repr__ definitions to cast to python numeric types before printing (leaving the underlying object(s) as a numpy dtype)?

  5. pllim commented on Aug 1, 2023

    @pllim
    ContributorAuthor

    Re: WCS -- Maybe but it is just a small portion of things that would be similarly affected. For us downstream that don't see the point of extra stuff in printouts, this seems like busywork that we don't have time for. I think one of the WCS printout code is at https://github.com/astropy/astropy/blob/8ab8208a4df5c636054f07c763006324d245ddbd/astropy/wcs/wcs.py#L3116

  6. pllim commented on Aug 1, 2023

    @pllim
    ContributorAuthor

    But that said, I'll check out what Marten has worked out at astropy/astropy#15065 though so far he didn't touch WCS.

  7. seberg commented on Aug 1, 2023

    @seberg
    Contributor

    There is a !r there, if you know you got a numerical value, using !s should be fine? I don't care about making it more permanent, although i would care a bit about making printoption saner (e.g. context safe).

  8. removed this from the 1.0.0 milestone on Aug 11, 2023
  9. pllim commented on Aug 20, 2023

    @pllim
    ContributorAuthor

    I thought we ignored it but it came back last night (https://github.com/scientific-python/pytest-doctestplus/actions/runs/5915248667/job/16041319959). So I took the liberty to relax the numpy-dev version check directly on main at 91104d8 since it is Sunday morning and I don't have much time. FYI.

  10. bsipocz commented on Aug 22, 2023

    @bsipocz
    Member

    @pllim - I don't think it's necessary to push hot fixes like this, as 1) the failing cron only an effect in our internal testing 2) we still don't provide a solution for downstream.

    Besides, leaving an explicit dev version would be helpful while one is in the middle of the dev cycle.

  11. bsipocz commented on Jan 25, 2025

    @bsipocz
    Member

    Do we still need this? I mean the numpy <2 support window is fast approaching, and it doesn't look like there is a huge interest in implementing the dual approach.

  12. pllim commented on Jan 27, 2025

    @pllim
    ContributorAuthor

    Did we ever revert #211 ? I think some action is still needed if not?

  13. pllim commented on Jan 27, 2025

    @pllim
    ContributorAuthor

    Still here:

    # Keep this until we require numpy to be >=2.0 or there is a directive in doctestplus
    # to support multiple ways of repr
    if Version(np.__version__) >= Version("2.0.dev"):
    np.set_printoptions(legacy="1.25")

  14. bsipocz commented on Jan 27, 2025

    @bsipocz
    Member

    Ahh, yes, sure we will need changes to support >2+, my understanding was that this issue was about supporting both types of representations.

  15. pllim commented on Jan 27, 2025

    @pllim
    ContributorAuthor

    Hmm I didn't explicitly request supporting both in the original post. As long as we revert that, I think by now, it is reasonable to only support numpy>=2. Thanks!

  16. flying-sheep commented on May 8, 2025

    @flying-sheep
    Contributor

    Aw, would have loved this to exist.

    But only 4 months until the last numpy 1 version’s support window is over so I get it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions