Skip to content

Commit

Permalink
Merge pull request #31 from sot/cxotimelike-type
Browse files Browse the repository at this point in the history
Add CxoTimeLike type alias
  • Loading branch information
taldcroft authored Dec 13, 2022
2 parents 2d7ba0e + 5047ced commit 17fd07c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 4 additions & 3 deletions cxotime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from .cxotime import CxoTime, date2secs, secs2date # noqa
from astropy.time import TimeDelta # noqa
from astropy import units # noqa
import ska_helpers
from astropy import units # noqa
from astropy.time import TimeDelta # noqa

from .cxotime import CxoTime, CxoTimeLike, date2secs, secs2date # noqa

__version__ = ska_helpers.get_version(__package__)

Expand Down
21 changes: 13 additions & 8 deletions cxotime/cxotime.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import datetime
import sys
import numpy as np
import warnings
from copy import copy
from ctypes import c_int
from pathlib import Path
import warnings
import datetime
from typing import Union

import numpy as np
import numpy.ctypeslib as npct
from ctypes import c_int

from astropy.time import Time, TimeCxcSec, TimeYearDayTime, TimeDecimalYear
import numpy.typing as npt
from astropy.time import Time, TimeCxcSec, TimeDecimalYear, TimeYearDayTime
from astropy.time.utils import day_frac
from astropy.utils import iers

# in astropy versions < 4.2, erfa was an astropy private package:
try:
import erfa
except ModuleNotFoundError:
from astropy import _erfa as erfa

# TODO: use npt.NDArray with numpy 1.21
CxoTimeLike = Union["CxoTime", str, float, int, np.ndarray, npt.ArrayLike, None]

# Globally ignore the ERFA dubious year warning that gets emitted for UTC dates
# either before around 1950 or well after the last known leap second. This
# warning is conservatively indicating that UTC is not well-defined in those
Expand Down Expand Up @@ -85,8 +90,8 @@ def date2secs(date):
"""
# This code is adapted from the underlying code in astropy time, with some
# of the general-purpose handling and validation removed.
from astropy.time.formats import TimeYearDayTime
from astropy.time import _parse_times
from astropy.time.formats import TimeYearDayTime

# Handle bytes or str input and convert to uint8. We need to the
# dtype _parse_times.dt_u1 instead of uint8, since otherwise it is
Expand Down Expand Up @@ -351,8 +356,8 @@ def print_conversions(self):
iso 2010-01-01 00:00:00.000
unix 1262304000.000
"""
from dateutil import tz
from astropy.table import Table
from dateutil import tz

formats = {
"date": "s",
Expand Down

0 comments on commit 17fd07c

Please sign in to comment.