Skip to content

Commit 607ecff

Browse files
jbrockmendelvladu
authored andcommitted
TYP: tslibs (pandas-dev#40693)
1 parent 5e7f7d8 commit 607ecff

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

pandas/_libs/tslibs/conversion.pyi

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from datetime import (
2+
datetime,
3+
tzinfo,
4+
)
5+
6+
import numpy as np
7+
8+
DT64NS_DTYPE: np.dtype
9+
TD64NS_DTYPE: np.dtype
10+
11+
class OutOfBoundsTimedelta(ValueError): ...
12+
13+
def precision_from_unit(
14+
unit: str,
15+
) -> tuple[
16+
int, # int64_t
17+
int,
18+
]: ...
19+
20+
21+
def ensure_datetime64ns(
22+
arr: np.ndarray, # np.ndarray[datetime64[ANY]]
23+
copy: bool = ...,
24+
) -> np.ndarray: ... # np.ndarray[datetime64ns]
25+
26+
27+
def ensure_timedelta64ns(
28+
arr: np.ndarray, # np.ndarray[timedelta64[ANY]]
29+
copy: bool = ...,
30+
) -> np.ndarray: ... # np.ndarray[timedelta64ns]
31+
32+
33+
def datetime_to_datetime64(
34+
values: np.ndarray, # np.ndarray[object]
35+
) -> tuple[
36+
np.ndarray, # np.ndarray[dt64ns]
37+
tzinfo | None,
38+
]: ...
39+
40+
41+
def localize_pydatetime(dt: datetime, tz: tzinfo | None) -> datetime: ...

pandas/_libs/tslibs/dtypes.pyi

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from enum import Enum
2+
3+
from pandas._libs.tslibs.offsets import BaseOffset
4+
5+
_attrname_to_abbrevs: dict[str, str]
6+
_period_code_map: dict[str, int]
7+
8+
9+
class PeriodDtypeBase:
10+
# actually __cinit__
11+
def __new__(self, code: int): ...
12+
13+
def freq_group_code(self) -> int: ...
14+
def date_offset(self) -> BaseOffset: ...
15+
16+
@classmethod
17+
def from_date_offset(cls, offset: BaseOffset) -> PeriodDtypeBase: ...
18+
19+
20+
class FreqGroup(Enum):
21+
FR_ANN: int = ...
22+
FR_QTR: int = ...
23+
FR_MTH: int = ...
24+
FR_WK: int = ...
25+
FR_BUS: int = ...
26+
FR_DAY: int = ...
27+
FR_HR: int = ...
28+
FR_MIN: int = ...
29+
FR_SEC: int = ...
30+
FR_MS: int = ...
31+
FR_US: int = ...
32+
FR_NS: int = ...
33+
FR_UND: int = ...
34+
35+
@staticmethod
36+
def get_freq_group(code: int) -> FreqGroup: ...
37+
38+
39+
class Resolution(Enum):
40+
RESO_NS: int = ...
41+
RESO_US: int = ...
42+
RESO_MS: int = ...
43+
RESO_SEC: int = ...
44+
RESO_MIN: int = ...
45+
RESO_HR: int = ...
46+
RESO_DAY: int = ...
47+
RESO_MTH: int = ...
48+
RESO_QTR: int = ...
49+
RESO_YR: int = ...
50+
51+
def __lt__(self, other: Resolution) -> bool: ...
52+
53+
def __ge__(self, other: Resolution) -> bool: ...
54+
55+
@property
56+
def freq_group(self) -> FreqGroup: ...
57+
58+
@property
59+
def attrname(self) -> str: ...
60+
61+
@classmethod
62+
def from_attrname(cls, attrname: str) -> Resolution: ...
63+
64+
@classmethod
65+
def get_reso_from_freq(cls, freq: str) -> Resolution: ...

pandas/_libs/tslibs/fields.pyi

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import numpy as np
2+
3+
def build_field_sarray(
4+
dtindex: np.ndarray, # const int64_t[:]
5+
) -> np.ndarray: ...
6+
7+
def month_position_check(fields, weekdays) -> str | None: ...
8+
9+
def get_date_name_field(
10+
dtindex: np.ndarray, # const int64_t[:]
11+
field: str,
12+
locale=...,
13+
) -> np.ndarray: ... # np.ndarray[object]
14+
15+
def get_start_end_field(
16+
dtindex: np.ndarray, # const int64_t[:]
17+
field: str,
18+
freqstr: str | None = ...,
19+
month_kw: int = ...
20+
) -> np.ndarray: ... # np.ndarray[bool]
21+
22+
23+
def get_date_field(
24+
dtindex: np.ndarray, # const int64_t[:]
25+
26+
field: str,
27+
) -> np.ndarray: ... # np.ndarray[in32]
28+
29+
30+
def get_timedelta_field(
31+
tdindex: np.ndarray, # const int64_t[:]
32+
field: str,
33+
) -> np.ndarray: ... # np.ndarray[int32]
34+
35+
36+
def isleapyear_arr(
37+
years: np.ndarray,
38+
) -> np.ndarray: ... # np.ndarray[bool]
39+
40+
def build_isocalendar_sarray(
41+
dtindex: np.ndarray, # const int64_t[:]
42+
) -> np.ndarray: ...
43+
44+
45+
def get_locale_names(name_type: str, locale: object = None): ...
46+
47+
48+
class RoundTo:
49+
@property
50+
def MINUS_INFTY(self) -> int: ...
51+
52+
@property
53+
def PLUS_INFTY(self) -> int: ...
54+
55+
@property
56+
def NEAREST_HALF_EVEN(self) -> int: ...
57+
58+
@property
59+
def NEAREST_HALF_PLUS_INFTY(self) -> int: ...
60+
61+
@property
62+
def NEAREST_HALF_MINUS_INFTY(self) -> int: ...
63+
64+
65+
def round_nsint64(
66+
values: np.ndarray, # np.ndarray[np.int64]
67+
mode: RoundTo,
68+
nanos: int,
69+
) -> np.ndarray: ... # np.ndarray[np.int64]

pandas/core/arrays/datetimelike.py

+1
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ def _round(self, freq, mode, ambiguous, nonexistent):
17271727
)
17281728

17291729
values = self.view("i8")
1730+
values = cast(np.ndarray, values)
17301731
nanos = to_offset(freq).nanos
17311732
result = round_nsint64(values, mode, nanos)
17321733
result = self._maybe_mask_results(result, fill_value=iNaT)

0 commit comments

Comments
 (0)