Skip to content

REF: de-duplicate hard-coded unit code #46338

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

Merged
merged 4 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def array_with_unit_to_datetime(
)
return result, tz

m, p = precision_from_unit(unit)
m, _ = precision_from_unit(unit)

if is_raise:
# try a quick conversion to i8/f8
Expand Down
22 changes: 21 additions & 1 deletion pandas/_libs/tslibs/dtypes.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from pandas._libs.tslibs.np_datetime cimport NPY_DATETIMEUNIT


cdef str npy_unit_to_abbrev(NPY_DATETIMEUNIT unit)
cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil

cdef dict attrname_to_abbrevs

cdef enum c_FreqGroup:
# Mirrors FreqGroup in the .pxy file
# Mirrors FreqGroup in the .pyx file
FR_ANN = 1000
FR_QTR = 2000
FR_MTH = 3000
Expand All @@ -17,6 +23,20 @@ cdef enum c_FreqGroup:
FR_UND = -10000 # undefined


cdef enum c_Resolution:
# Mirrors Resolution in the .pyx file
RESO_NS = 0
RESO_US = 1
RESO_MS = 2
RESO_SEC = 3
RESO_MIN = 4
RESO_HR = 5
RESO_DAY = 6
RESO_MTH = 7
RESO_QTR = 8
RESO_YR = 9


cdef enum PeriodDtypeCode:
# Annual freqs with various fiscal year ends.
# eg, 2005 for A_FEB runs Mar 1, 2004 to Feb 28, 2005
Expand Down
18 changes: 9 additions & 9 deletions pandas/_libs/tslibs/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ from enum import Enum

from pandas._libs.tslibs.offsets import BaseOffset

# These are not public API, but are exposed in the .pyi file because they
# are imported in tests.
_attrname_to_abbrevs: dict[str, str]
_period_code_map: dict[str, int]

Expand All @@ -10,13 +12,11 @@ class PeriodDtypeBase:

# actually __cinit__
def __new__(cls, code: int): ...
def freq_group_code(self) -> int: ...
def date_offset(self) -> BaseOffset: ...
@classmethod
def from_date_offset(cls, offset: BaseOffset) -> PeriodDtypeBase: ...
def _freq_group_code(self) -> int: ...
@property
def resolution(self) -> Resolution: ...
def _resolution_obj(self) -> Resolution: ...
def _get_to_timestamp_base(self) -> int: ...
def _freqstr(self) -> str: ...

class FreqGroup(Enum):
FR_ANN: int
Expand All @@ -33,7 +33,7 @@ class FreqGroup(Enum):
FR_NS: int
FR_UND: int
@staticmethod
def get_freq_group(code: int) -> FreqGroup: ...
def from_period_dtype_code(code: int) -> FreqGroup: ...

class Resolution(Enum):
RESO_NS: int
Expand All @@ -49,10 +49,10 @@ class Resolution(Enum):
def __lt__(self, other: Resolution) -> bool: ...
def __ge__(self, other: Resolution) -> bool: ...
@property
def freq_group(self) -> FreqGroup: ...
@property
def attrname(self) -> str: ...
@classmethod
def from_attrname(cls, attrname: str) -> Resolution: ...
@classmethod
def get_reso_from_freq(cls, freq: str) -> Resolution: ...
def get_reso_from_freqstr(cls, freq: str) -> Resolution: ...
@property
def attr_abbrev(self) -> str: ...
Loading