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

datetime tests out of range macOS & python 3.12 #3922

Closed
davidhewitt opened this issue Mar 2, 2024 · 9 comments · Fixed by #4275
Closed

datetime tests out of range macOS & python 3.12 #3922

davidhewitt opened this issue Mar 2, 2024 · 9 comments · Fixed by #4275

Comments

@davidhewitt
Copy link
Member

https://github.com/PyO3/pyo3/actions/runs/8118596439/job/22193138483?pr=3917#step:22:268a

I haven't tried to reproduce yet, if it does reproduce locally then it should be reasonably straightforward to work out how to adjust the test to stay in bounds.

Fixing this would help reduce CI flakiness!

I've marked this good first issue as it might be a nice way for someone to familiarise with the codebase. (In particular our python based part of the test suite.)

@LilyFoote
Copy link
Contributor

I don't think CI jobs stay around forever, so here's the error:

  _________________________ test_datetime_from_timestamp _________________________
  
      @given(dt=st.datetimes(MIN_DATETIME, MAX_DATETIME))
  >   @example(dt=pdt.datetime(1971, 1, 2, 0, 0))
  
  tests/test_datetime.py:230: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  dt = datetime.datetime(9999, 12, 31, 0, 0, fold=1)
  
      @given(dt=st.datetimes(MIN_DATETIME, MAX_DATETIME))
      @example(dt=pdt.datetime(1971, 1, 2, 0, 0))
      def test_datetime_from_timestamp(dt):
          if PYPY and dt < pdt.datetime(1900, 1, 1):
              pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900")
      
  >       ts = pdt.datetime.timestamp(dt)
  E       ValueError: year 10000 is out of range
  E       Falsifying example: test_datetime_from_timestamp(
  E           dt=datetime.datetime(9999, 12, 31, 0, 0, fold=1),
  E       )
  E       
  E       You can reproduce this example by temporarily adding @reproduce_failure('6.98.15', b'AAAfPwseAAAAAAAAAQ==') as a decorator on your test case
  
  tests/test_datetime.py:235: ValueError
  =========================== short test summary info ============================
  FAILED tests/test_datetime.py::test_datetime_from_timestamp - ValueError: year 10000 is out of range
  Falsifying example: test_datetime_from_timestamp(
      dt=datetime.datetime(9999, 12, 31, 0, 0, fold=1),
  )
  
  You can reproduce this example by temporarily adding @reproduce_failure('6.98.15', b'AAAfPwseAAAAAAAAAQ==') as a decorator on your test case

@davidhewitt
Copy link
Member Author

davidhewitt commented Apr 11, 2024

Looks like windows 3.12 can fail too:

 ================================== FAILURES ===================================
  ________________________ test_datetime_from_timestamp _________________________
  
      @given(dt=st.datetimes(MIN_DATETIME, MAX_DATETIME))
  >   @example(dt=pdt.datetime(1971, 1, 2, 0, 0))
  
  tests\test_datetime.py:230: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  
  dt = datetime.datetime(3001, 1, 18, 8, 0, fold=1)
  
      @given(dt=st.datetimes(MIN_DATETIME, MAX_DATETIME))
      @example(dt=pdt.datetime(1971, 1, 2, 0, 0))
      def test_datetime_from_timestamp(dt):
          if PYPY and dt < pdt.datetime(1900, 1, 1):
              pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900")
      
  >       ts = pdt.datetime.timestamp(dt)
  E       OSError: [Errno 22] Invalid argument
  E       Falsifying example: test_datetime_from_timestamp(
  E           dt=datetime.datetime(3001, 1, 18, 8, 0, fold=1),
  E       )
  E       
  E       You can reproduce this example by temporarily adding @reproduce_failure('6.100.1', b'AAAD6QARCAAAAAAAAQ==') as a decorator on your test case
  
  tests\test_datetime.py:235: OSError
  =========================== short test summary info ===========================
  FAILED tests/test_datetime.py::test_datetime_from_timestamp - OSError: [Errno 22] Invalid argument
  Falsifying example: test_datetime_from_timestamp(
      dt=datetime.datetime(3001, 1, 18, 8, 0, fold=1),
  )
  
  You can reproduce this example by temporarily adding @reproduce_failure('6.100.1', b'AAAD6QARCAAAAAAAAQ==') as a decorator on your test case
  ======================== 1 failed, 147 passed in 3.87s ========================

@Cheukting
Copy link
Contributor

Cheukting commented May 24, 2024

From here.), on 32 bit Windows actual range for C datetime is midnight, January 1, 1970, to January 18, 19:14:07, 2038, I wonder how is the MIN and MAX range in the code:

if IS_WINDOWS:
    MIN_DATETIME = pdt.datetime(1971, 1, 2, 0, 0)
    if IS_32_BIT:
        MAX_DATETIME = pdt.datetime(3001, 1, 19, 4, 59, 59)
    else:
        MAX_DATETIME = pdt.datetime(3001, 1, 19, 7, 59, 59)
else:
    if IS_32_BIT:
        # TS ±2147483648 (2**31)
        MIN_DATETIME = pdt.datetime(1901, 12, 13, 20, 45, 52)
        MAX_DATETIME = pdt.datetime(2038, 1, 18, 3, 14, 8)
    else:
        MIN_DATETIME = pdt.datetime(1, 1, 2, 0, 0)
        MAX_DATETIME = pdt.datetime(9999, 12, 31, 18, 59, 59)

determined?

@davidhewitt
Copy link
Member Author

Off the top of my head I don't recall why we made those choices, the commit history or GitHub discussion on PRs might reveal more. There is also datetime.min and datetime.max, which might be useful here?

@Cheukting
Copy link
Contributor

According to this datetime itself does not limit the range in C level, you will get an OverflowError or OSError (which is exactly what we have above). So I doubt datetime.min and datetime.max will be helpful here

@Cheukting
Copy link
Contributor

Cheukting commented May 24, 2024

I think I will poke around a bit more to check why the range is chosen and if should we adjust them. Or we can write some code to determine the range with seconds (which is more straightforward as we know the max in, for example, 32 bit machine).

@Cheukting
Copy link
Contributor

It was added 5 years ago by @Alexander-N : 7aaef51

I am wondering if this will be a better information source of what the range should be.
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/mktime-mktime32-mktime64?view=msvc-170

If there's something that I missed maybe @Alexander-N can shine some light on it.

@Alexander-N
Copy link
Member

@pganssle is the expert on this who wrote these tests, see #635

@Cheukting
Copy link
Contributor

Thanks @Alexander-N and @pganssle I did some research this weekend and may have found the problem, have created a PR and welcome for reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants