File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ cdef NPY_DATETIMEUNIT abbrev_to_npy_unit(str abbrev)
88cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil
99cpdef int64_t periods_per_day(NPY_DATETIMEUNIT reso = * ) except ? - 1
1010cpdef int64_t periods_per_second(NPY_DATETIMEUNIT reso) except ? - 1
11+ cpdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso)
1112
1213cdef dict attrname_to_abbrevs
1314
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ def periods_per_day(reso: int) -> int: ...
99def periods_per_second (reso : int ) -> int : ...
1010def is_supported_unit (reso : int ) -> bool : ...
1111def npy_unit_to_abbrev (reso : int ) -> str : ...
12+ def get_supported_reso (reso : int ) -> int : ...
1213
1314class PeriodDtypeBase :
1415 _dtype_code : int # PeriodDtypeCode
Original file line number Diff line number Diff line change @@ -278,6 +278,19 @@ class NpyDatetimeUnit(Enum):
278278 NPY_FR_GENERIC = NPY_DATETIMEUNIT.NPY_FR_GENERIC
279279
280280
281+ cpdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso):
282+ # If we have an unsupported reso, return the nearest supported reso.
283+ if reso == NPY_DATETIMEUNIT.NPY_FR_GENERIC:
284+ # TODO: or raise ValueError? trying this gives unraisable errors, but
285+ # "except? -1" breaks at compile-time for unknown reasons
286+ return NPY_DATETIMEUNIT.NPY_FR_ns
287+ if reso < NPY_DATETIMEUNIT.NPY_FR_s:
288+ return NPY_DATETIMEUNIT.NPY_FR_s
289+ elif reso > NPY_DATETIMEUNIT.NPY_FR_ns:
290+ return NPY_DATETIMEUNIT.NPY_FR_ns
291+ return reso
292+
293+
281294def is_supported_unit (NPY_DATETIMEUNIT reso ):
282295 return (
283296 reso == NPY_DATETIMEUNIT.NPY_FR_ns
You can’t perform that action at this time.
0 commit comments