GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TST: migrate from pytz to zoneinfo + tzdata (where needed) · Issue #29064 · numpy/numpy

TST: migrate from pytz to zoneinfo + tzdata (where needed) #29064

New issue
Copy link
New issue
Copy link
Closed
Task
Closed
TST: migrate from pytz to zoneinfo + tzdata (where needed)#29064
Task
Copy link
Labels
sprintableIssue fits the time-frame and setting of a sprint

Description

@mattip
mattip
opened on May 27, 2025
Issue body actions

We use pytz in testing, notably in numpy/_core/tests/test_datetime.py and numpy/_core/tests/test_deprecations.py. Since Python3.9, the recommended way to access timezone information is to use the standard library zoneinfo, and install tzdata where needed (like windows). We should refactor our tests to use zoneinfo.

Reacted by Joren Hammudoglu

Activity

  1. mattip
    added the
    Task
    issue type on May 27, 2025
  2. mattip
    added
    sprintableIssue fits the time-frame and setting of a sprint
    on May 27, 2025
  3. V-R-S commented on Jun 7, 2025

    @V-R-S
    V-R-S
    on Jun 7, 2025
    Contributor
    More actions

    Here I see the task would not be just to replace the pytz with ZoneInfo
    As ZoneInfo is not compatible with datetime as pytz is compatible with it.

    from datetime import datetime
    from pytz import timezone as tz
    
    a = datetime(2025, 6, 7, 10, 0, 0)
    zonePytz = pytz("US/Central")
    c = zonePytz.fromutc(a)
    

    This particular snippet will work but

    from datetime import datetime
    from zoneinfo import ZoneInfo
    
    a = datetime(2025, 6, 7, 10, 0, 0)
    zoneInfo = ZoneInfo("US/Central")
    b = zoneInfo.fromutc(a)
    

    This won't as it will result in an exception
    ValueError: fromutc: dt.tzinfo is not self

    It seems that function get_tzoffset_from_pytzinfo in numpy/_core/src/multiarray/datetime.c might need to be modified to handle the new behaviour of a different object type.

    But I also see that this particular function will impact other places as well.
    Please guide me if there are gaps in my understanding.

  4. mattip commented on Jun 7, 2025

    @mattip
    mattip
    on Jun 7, 2025
    MemberAuthor
    More actions

    What other places would be impacted?

  5. V-R-S commented on Jun 7, 2025

    @V-R-S
    V-R-S
    on Jun 7, 2025
    Contributor
    More actions

    Well not in this codebase. As I first thought it would, but definitely it might affect the codebases that use this function datetime_as_string

    That would depend if it is required to support pytz along with ZoneInfo.

    diff --git a/numpy/_core/src/multiarray/datetime.c b/numpy/_core/src/multiarray/datetime.c
    index 9c024dbcd9..88e7ec6cc7 100644
    --- a/numpy/_core/src/multiarray/datetime.c
    +++ b/numpy/_core/src/multiarray/datetime.c
    @@ -2262,7 +2262,7 @@ get_tzoffset_from_pytzinfo(PyObject *timezone_obj, npy_datetimestruct *dts)
         }
    
         /* Convert the datetime from UTC to local time */
    -    loc_dt = PyObject_CallMethod(timezone_obj, "fromutc", "O", dt);
    +    loc_dt = PyObject_CallMethod(dt, "astimezone", "O", timezone_obj);
         Py_DECREF(dt);
         if (loc_dt == NULL) {
             return -1;
    

    I think a quick change like this would make ZoneInfo object work.
    it can work with pytz but the result might be inconsistent.

    with the above change at least the tests doesn't fail.(I have modified the tests to use ZoneInfo)
    ================================= 47140 passed, 1738 skipped, 2818 deselected, 33 xfailed, 5 xpassed in 313.85s (0:05:13) ==================================

  6. mattip commented on Jun 8, 2025

    @mattip
    mattip
    on Jun 8, 2025
    MemberAuthor
    More actions

    It can work with pytz but the result might be inconsistent.

    Why?

  7. V-R-S
    added a commit that references this issue on Jun 8, 2025

    TST: migrating from pytz to zoneinfo + tzdata (where needed)

    21c2e70
  8. V-R-S commented on Jun 8, 2025

    @V-R-S
    V-R-S
    on Jun 8, 2025
    Contributor
    More actions

    The problem would be the naive datetime object which is not aware of the timezone.
    solution create a datetime object with timezone.
    which is not provided in the
    PyObject *PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)

    But I have taken an approach inmy PR please have a look.

  9. mattip commented on Jun 11, 2025

    @mattip
    mattip
    on Jun 11, 2025
    MemberAuthor
    More actions

    Closed by #29148

  10. mattip
    closed this as completedon Jun 11, 2025
  11. joy2myself
    added a commit that references this issue on Jul 21, 2025

    ENH: Convert unary from C universal intrinsics to C++ using Highway (#19

    3f5dccf
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

    sprintableIssue fits the time-frame and setting of a sprint

    Type

    Task

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.