Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
77 changes: 40 additions & 37 deletions pandas/_libs/tslibs/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,35 @@ class PeriodDtypeBase:
def _td64_unit(self) -> str: ...

class FreqGroup(Enum):
FR_ANN: int
FR_QTR: int
FR_MTH: int
FR_WK: int
FR_BUS: int
FR_DAY: int
FR_HR: int
FR_MIN: int
FR_SEC: int
FR_MS: int
FR_US: int
FR_NS: int
FR_UND: int
_value_: int
FR_ANN = ...
FR_QTR = ...
FR_MTH = ...
FR_WK = ...
FR_BUS = ...
FR_DAY = ...
FR_HR = ...
FR_MIN = ...
FR_SEC = ...
FR_MS = ...
FR_US = ...
FR_NS = ...
FR_UND = ...
@staticmethod
def from_period_dtype_code(code: int) -> FreqGroup: ...

class Resolution(Enum):
RESO_NS: int
RESO_US: int
RESO_MS: int
RESO_SEC: int
RESO_MIN: int
RESO_HR: int
RESO_DAY: int
RESO_MTH: int
RESO_QTR: int
RESO_YR: int
_value_: int
RESO_NS = ...
RESO_US = ...
RESO_MS = ...
RESO_SEC = ...
RESO_MIN = ...
RESO_HR = ...
RESO_DAY = ...
RESO_MTH = ...
RESO_QTR = ...
RESO_YR = ...
def __lt__(self, other: Resolution) -> bool: ...
def __ge__(self, other: Resolution) -> bool: ...
@property
Expand All @@ -67,17 +69,18 @@ class Resolution(Enum):
def attr_abbrev(self) -> str: ...

class NpyDatetimeUnit(Enum):
NPY_FR_Y: int
NPY_FR_M: int
NPY_FR_W: int
NPY_FR_D: int
NPY_FR_h: int
NPY_FR_m: int
NPY_FR_s: int
NPY_FR_ms: int
NPY_FR_us: int
NPY_FR_ns: int
NPY_FR_ps: int
NPY_FR_fs: int
NPY_FR_as: int
NPY_FR_GENERIC: int
_value_: int
NPY_FR_Y = ...
NPY_FR_M = ...
NPY_FR_W = ...
NPY_FR_D = ...
NPY_FR_h = ...
NPY_FR_m = ...
NPY_FR_s = ...
NPY_FR_ms = ...
NPY_FR_us = ...
NPY_FR_ns = ...
NPY_FR_ps = ...
NPY_FR_fs = ...
NPY_FR_as = ...
NPY_FR_GENERIC = ...
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,11 +1435,11 @@ def _range_from_fields(
if quarter is not None:
if freq is None:
freq = to_offset("Q", is_period=True)
base = FreqGroup.FR_QTR.value
base = cast(int, FreqGroup.FR_QTR.value)
else:
freq = to_offset(freq, is_period=True)
base = libperiod.freq_to_dtype_code(freq)
if base != FreqGroup.FR_QTR.value:
if base != cast(int, FreqGroup.FR_QTR.value):
raise AssertionError("base must equal FR_QTR")

freqstr = freq.freqstr
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,10 @@ class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
# "Dict[int, PandasExtensionDtype]", base class "PandasExtensionDtype"
# defined the type as "Dict[str, PandasExtensionDtype]") [assignment]
_cache_dtypes: dict[BaseOffset, int] = {} # type: ignore[assignment]
__hash__ = PeriodDtypeBase.__hash__
# error: Incompatible types in assignment (expression has type
# "Callable[[PeriodDtypeBase], int]", base class "PandasExtensionDtype"
# defined the type as "Callable[[PandasExtensionDtype], int]")
__hash__ = PeriodDtypeBase.__hash__ # type: ignore[assignment]
_freq: BaseOffset
_supports_2d = True
_can_fast_transpose = True
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _to_datetime_with_unit(arg, unit, name, utc: bool, errors: str) -> Index:
utc=utc,
errors=errors,
unit_for_numerics=unit,
creso=NpyDatetimeUnit.NPY_FR_ns.value,
creso=cast(int, NpyDatetimeUnit.NPY_FR_ns.value),
)

result = DatetimeIndex(arr, name=name)
Expand Down
Loading