Skip to content

datetime -> Time accuracy problems #9579

Description

@aarchiba

Description

Although python's datetime objects support microsecond resolution, and Time objects support sub-nanosecond resolution, conversion and arithmetic between the two can be off by tens of microseconds. (By design datetime objects do not support leap seconds, so UTC cannot be expected to work. The problems described here are for non-UTC timescales like TAI.)

Expected behavior

Computing the difference between two datetime objects then converting to a TimeDelta should give the same result as converting the datetime objects to Time objects and subtracting, to within a couple of microseconds.

Actual behavior

In fact PR #9532 demonstrates several examples where the difference exceeds 20 microseconds.

Steps to Reproduce

def test_datetime_difference_agrees_with_timedelta_no_hypothesis():
    scale = "tai"
    dt1 = datetime(1235, 1, 1, 0, 0)
    dt2 = datetime(9950, 1, 1, 0, 0, 0, 890773)
    t1 = Time(dt1, scale=scale)
    t2 = Time(dt2, scale=scale)
    assert(abs((t2-t1) - TimeDelta(dt2-dt1, scale=scale)) < 25*u.us)

System Details

Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; print(platform.platform())
Linux-5.0.0-32-generic-x86_64-with-Ubuntu-19.04-disco
>>> import sys; print("Python", sys.version)
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0]
>>> import numpy; print("Numpy", numpy.__version__)
Numpy 1.17.1
>>> import scipy; print("Scipy", scipy.__version__)
Scipy 1.3.1
>>> import astropy; print("astropy", astropy.__version__)
astropy 4.0.dev26780

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions