Skip to content

Commit b112975

Browse files
committed
fix enum typing from _lib
1 parent 3940df8 commit b112975

File tree

4 files changed

+47
-41
lines changed

4 files changed

+47
-41
lines changed

pandas/_libs/tslibs/dtypes.pyi

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,35 @@ class PeriodDtypeBase:
2828
def _td64_unit(self) -> str: ...
2929

3030
class FreqGroup(Enum):
31-
FR_ANN: int
32-
FR_QTR: int
33-
FR_MTH: int
34-
FR_WK: int
35-
FR_BUS: int
36-
FR_DAY: int
37-
FR_HR: int
38-
FR_MIN: int
39-
FR_SEC: int
40-
FR_MS: int
41-
FR_US: int
42-
FR_NS: int
43-
FR_UND: int
31+
_value_: int
32+
FR_ANN = ...
33+
FR_QTR = ...
34+
FR_MTH = ...
35+
FR_WK = ...
36+
FR_BUS = ...
37+
FR_DAY = ...
38+
FR_HR = ...
39+
FR_MIN = ...
40+
FR_SEC = ...
41+
FR_MS = ...
42+
FR_US = ...
43+
FR_NS = ...
44+
FR_UND = ...
4445
@staticmethod
4546
def from_period_dtype_code(code: int) -> FreqGroup: ...
4647

4748
class Resolution(Enum):
48-
RESO_NS: int
49-
RESO_US: int
50-
RESO_MS: int
51-
RESO_SEC: int
52-
RESO_MIN: int
53-
RESO_HR: int
54-
RESO_DAY: int
55-
RESO_MTH: int
56-
RESO_QTR: int
57-
RESO_YR: int
49+
_value_: int
50+
RESO_NS = ...
51+
RESO_US = ...
52+
RESO_MS = ...
53+
RESO_SEC = ...
54+
RESO_MIN = ...
55+
RESO_HR = ...
56+
RESO_DAY = ...
57+
RESO_MTH = ...
58+
RESO_QTR = ...
59+
RESO_YR = ...
5860
def __lt__(self, other: Resolution) -> bool: ...
5961
def __ge__(self, other: Resolution) -> bool: ...
6062
@property
@@ -67,17 +69,18 @@ class Resolution(Enum):
6769
def attr_abbrev(self) -> str: ...
6870

6971
class NpyDatetimeUnit(Enum):
70-
NPY_FR_Y: int
71-
NPY_FR_M: int
72-
NPY_FR_W: int
73-
NPY_FR_D: int
74-
NPY_FR_h: int
75-
NPY_FR_m: int
76-
NPY_FR_s: int
77-
NPY_FR_ms: int
78-
NPY_FR_us: int
79-
NPY_FR_ns: int
80-
NPY_FR_ps: int
81-
NPY_FR_fs: int
82-
NPY_FR_as: int
83-
NPY_FR_GENERIC: int
72+
_value_: int
73+
NPY_FR_Y = ...
74+
NPY_FR_M = ...
75+
NPY_FR_W = ...
76+
NPY_FR_D = ...
77+
NPY_FR_h = ...
78+
NPY_FR_m = ...
79+
NPY_FR_s = ...
80+
NPY_FR_ms = ...
81+
NPY_FR_us = ...
82+
NPY_FR_ns = ...
83+
NPY_FR_ps = ...
84+
NPY_FR_fs = ...
85+
NPY_FR_as = ...
86+
NPY_FR_GENERIC = ...

pandas/core/arrays/period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,11 +1435,11 @@ def _range_from_fields(
14351435
if quarter is not None:
14361436
if freq is None:
14371437
freq = to_offset("Q", is_period=True)
1438-
base = FreqGroup.FR_QTR.value
1438+
base = cast(int, FreqGroup.FR_QTR.value)
14391439
else:
14401440
freq = to_offset(freq, is_period=True)
14411441
base = libperiod.freq_to_dtype_code(freq)
1442-
if base != FreqGroup.FR_QTR.value:
1442+
if base != cast(int, FreqGroup.FR_QTR.value):
14431443
raise AssertionError("base must equal FR_QTR")
14441444

14451445
freqstr = freq.freqstr

pandas/core/dtypes/dtypes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,10 @@ class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
10301030
# "Dict[int, PandasExtensionDtype]", base class "PandasExtensionDtype"
10311031
# defined the type as "Dict[str, PandasExtensionDtype]") [assignment]
10321032
_cache_dtypes: dict[BaseOffset, int] = {} # type: ignore[assignment]
1033-
__hash__ = PeriodDtypeBase.__hash__
1033+
# error: Incompatible types in assignment (expression has type
1034+
# "Callable[[PeriodDtypeBase], int]", base class "PandasExtensionDtype"
1035+
# defined the type as "Callable[[PandasExtensionDtype], int]")
1036+
__hash__ = PeriodDtypeBase.__hash__ # type: ignore[assignment]
10341037
_freq: BaseOffset
10351038
_supports_2d = True
10361039
_can_fast_transpose = True

pandas/core/tools/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def _to_datetime_with_unit(arg, unit, name, utc: bool, errors: str) -> Index:
528528
utc=utc,
529529
errors=errors,
530530
unit_for_numerics=unit,
531-
creso=NpyDatetimeUnit.NPY_FR_ns.value,
531+
creso=cast(int, NpyDatetimeUnit.NPY_FR_ns.value),
532532
)
533533

534534
result = DatetimeIndex(arr, name=name)

0 commit comments

Comments
 (0)