Skip to content

Commit b9cb593

Browse files
msfterictrauttwoertwein
authored andcommitted
Improved the type stubs in the _libs directory to help with type checking.
1 parent 9cc98a0 commit b9cb593

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

pandas/_libs/interval.pyi

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from typing import FrozenSet, Tuple
2+
3+
import numpy as np
4+
5+
class IntervalMixin:
6+
@property
7+
def _left(self) -> object: ...
8+
@property
9+
def _right(self) -> object: ...
10+
@property
11+
def closed_left(self) -> bool: ...
12+
@property
13+
def closed_right(self) -> bool: ...
14+
@property
15+
def open_left(self) -> bool: ...
16+
@property
17+
def open_right(self) -> bool: ...
18+
@property
19+
def mid(self) -> float: ...
20+
@property
21+
def length(self) -> float: ...
22+
@property
23+
def is_empty(self) -> bool: ...
24+
def _check_closed_matches(self, other: IntervalMixin, name: str=...) -> None: ...
25+
26+
class Interval(IntervalMixin):
27+
def __init__(self, left: object, right: object, closed: str=...) -> None: ...
28+
@property
29+
def closed(self) -> str: ...
30+
@property
31+
def left(self) -> object: ...
32+
@property
33+
def right(self) -> object: ...
34+
def __str__(self) -> str: ...
35+
def __add__(self, y: Interval) -> Interval: ...
36+
def __sub__(self, y: Interval) -> Interval: ...
37+
def __mul__(self, y: Interval) -> Interval: ...
38+
def __trudeiv__(self, y: Interval) -> Interval: ...
39+
def __floordiv__(self, y: Interval) -> Interval: ...
40+
def __overlaps__(self, other: Interval) -> bool: ...
41+
42+
VALID_CLOSED: FrozenSet[str]
43+
44+
def intervals_to_interval_bounds(
45+
intervals: np.ndarray,
46+
valdiate_closed: bool = ...
47+
) -> Tuple[object, object, str]: ...

pandas/_libs/tslibs/ccalendar.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ def get_firstbday(year: int, month: int) -> int: ...
88
def get_lastbday(year: int, month: int) -> int: ...
99
def get_day_of_year(year: int, month: int, day: int) -> int: ...
1010
def get_iso_calendar(year: int, month: int, day: int) -> tuple[int, int, int]: ...
11+
def is_leapyear(year: int) -> bool: ...
1112
def get_week_of_year(year: int, month: int, day: int) -> int: ...
1213
def get_days_in_month(year: int, month: int) -> int: ...
14+
def dayofweek(y: int, m: int, d: int) -> int: ...

pandas/_libs/tslibs/nattype.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ iNaT: int
1414
nat_strings: set[str]
1515

1616
def is_null_datetimelike(val: object, inat_is_null: bool = ...) -> bool: ...
17+
def checknull_with_nat(val: object) -> bool: ...
1718

1819
class NaTType(datetime):
1920
value: np.int64

pandas/_libs/tslibs/offsets.pyi

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from __future__ import annotations
2+
from datetime import datetime
3+
from typing import Any, Tuple, Union
4+
from datetime import timedelta
5+
6+
class BaseOffset:
7+
def __init__(self, n: int = ..., normalize: bool = ...) -> None: ...
8+
def __eq__(self, other) -> bool: ...
9+
def __ne__(self, other) -> bool: ...
10+
def __hash__(self) -> int: ...
11+
@property
12+
def kwds(self) -> dict: ...
13+
@property
14+
def base(self) -> BaseOffset: ...
15+
def __add__(self, other) -> BaseOffset: ...
16+
def __sub__(self, other) -> BaseOffset: ...
17+
def __call__(self, other): ...
18+
def __mul__(self, other): ...
19+
def __neg__(self) -> BaseOffset: ...
20+
def copy(self) -> BaseOffset: ...
21+
def __repr__(self) -> str: ...
22+
@property
23+
def name(self) -> str: ...
24+
@property
25+
def rule_code(self) -> str: ...
26+
def freqstr(self) -> str: ...
27+
# Next one is problematic due to circular imports
28+
#def apply_index(self, dtindex: DatetimeIndex) -> DatetimeIndex: ...
29+
def apply_index(self, dtindex): ...
30+
def _apply_array(self, dtarr) -> None: ...
31+
def rollback(self, dt: datetime) -> datetime: ...
32+
def rollforward(self, dt: datetime) -> datetime: ...
33+
def is_on_offset(self, dt: datetime) -> bool: ...
34+
def __setstate__(self, state) -> None: ...
35+
def __getstate__(self): ...
36+
@property
37+
def nanos(self) -> int: ...
38+
def onOffset(self, dt: datetime) -> bool: ...
39+
def isAnchored(self) -> bool: ...
40+
def is_anchored(self) -> bool: ...
41+
42+
class SingleConstructorOffset(BaseOffset):
43+
@classmethod
44+
def _from_name(cls, suffix=None): ...
45+
def __reduce__(self): ...
46+
47+
def to_offset(freq: Union[str, Tuple, timedelta, BaseOffset, None]) -> Union[BaseOffset, None]: ...
48+
49+
class Tick(SingleConstructorOffset):
50+
def __init__(self, n: int = ..., normalize: bool = ...) -> None: ...
51+
52+
class Day(Tick): ...
53+
class Hour(Tick): ...
54+
class Minute(Tick): ...
55+
class Second(Tick): ...
56+
class Milli(Tick): ...
57+
class Micro(Tick): ...
58+
class Nano(Tick): ...
59+
class RelativeDeltaOffset(BaseOffset):
60+
def __init__(self, n: int = ..., normalize: bool = ..., **kwds: Any) -> None: ...
61+
class BusinessMixin(SingleConstructorOffset): ...
62+
class BusinessDay(BusinessMixin): ...
63+
class BusinessHour(BusinessMixin): ...
64+
class WeekOfMonthMixin(SingleConstructorOffset): ...
65+
class YearOffset(SingleConstructorOffset): ...
66+
class BYearEnd(YearOffset): ...
67+
class BYearBegin(YearOffset): ...
68+
class YearEnd(YearOffset): ...
69+
class YearBegin(YearOffset): ...
70+
class QuarterOffset(SingleConstructorOffset): ...
71+
class BQuarterEnd(QuarterOffset): ...
72+
class BQuarterBegin(QuarterOffset): ...
73+
class QuarterEnd(QuarterOffset): ...
74+
class QuarterBegin(QuarterOffset): ...
75+
class MonthOffset(SingleConstructorOffset): ...
76+
class MonthEnd(MonthOffset): ...
77+
class MonthBegin(MonthOffset): ...
78+
class BusinessMonthEnd(MonthOffset): ...
79+
class BusinessMonthBegin(MonthOffset): ...
80+
class SemiMonthOffset(SingleConstructorOffset): ...
81+
class SemiMonthEnd(SemiMonthOffset): ...
82+
class SemiMonthBegin(SemiMonthOffset): ...
83+
class Week(SingleConstructorOffset): ...
84+
class WeekOfMonth(WeekOfMonthMixin): ...
85+
class LastWeekOfMonth(WeekOfMonthMixin): ...
86+
class FY5253Mixin(SingleConstructorOffset): ...
87+
class FY5253(FY5253Mixin): ...
88+
class FY5253Quarter(FY5253Mixin): ...
89+
class Easter(SingleConstructorOffset): ...
90+
class _CustomBusinessMonth(BusinessMixin): ...
91+
class CustomBusinessDay(BusinessDay): ...
92+
class CustomBusinessHour(BusinessHour): ...
93+
class CustomBusinessMonthEnd(_CustomBusinessMonth): ...
94+
class CustomBusinessMonthBegin(_CustomBusinessMonth): ...
95+
class DateOffset(RelativeDeltaOffset): ...
96+
97+
BDay = BusinessDay
98+
BMonthEnd = BusinessMonthEnd
99+
BMonthBegin = BusinessMonthBegin
100+
CBMonthEnd = CustomBusinessMonthEnd
101+
CBMonthBegin = CustomBusinessMonthBegin
102+
CDay = CustomBusinessDay

pandas/_libs/tslibs/period.pyi

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from typing import Literal
23

34
import numpy as np
@@ -14,6 +15,9 @@ from pandas._typing import (
1415
INVALID_FREQ_ERR_MSG: str
1516
DIFFERENT_FREQ: str
1617

18+
def is_period_object(obj: object) -> bool: ...
19+
def get_period_ordinal(dts: datetime, freq: int) -> int: ...
20+
1721
class IncompatibleFrequency(ValueError): ...
1822

1923
def periodarr_to_dt64arr(

0 commit comments

Comments
 (0)