File tree 3 files changed +15
-0
lines changed
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)
8
8
cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil
9
9
cpdef int64_t periods_per_day(NPY_DATETIMEUNIT reso = * ) except ? - 1
10
10
cpdef int64_t periods_per_second(NPY_DATETIMEUNIT reso) except ? - 1
11
+ cpdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso)
11
12
12
13
cdef dict attrname_to_abbrevs
13
14
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ def periods_per_day(reso: int) -> int: ...
9
9
def periods_per_second (reso : int ) -> int : ...
10
10
def is_supported_unit (reso : int ) -> bool : ...
11
11
def npy_unit_to_abbrev (reso : int ) -> str : ...
12
+ def get_supported_reso (reso : int ) -> int : ...
12
13
13
14
class PeriodDtypeBase :
14
15
_dtype_code : int # PeriodDtypeCode
Original file line number Diff line number Diff line change @@ -278,6 +278,19 @@ class NpyDatetimeUnit(Enum):
278
278
NPY_FR_GENERIC = NPY_DATETIMEUNIT.NPY_FR_GENERIC
279
279
280
280
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
+
281
294
def is_supported_unit (NPY_DATETIMEUNIT reso ):
282
295
return (
283
296
reso == NPY_DATETIMEUNIT.NPY_FR_ns
You can’t perform that action at this time.
0 commit comments