Skip to content

TYP: tslibs.conversion, dtypes, fields #40693

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 1 commit into from
Mar 31, 2021
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
41 changes: 41 additions & 0 deletions pandas/_libs/tslibs/conversion.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from datetime import (
datetime,
tzinfo,
)

import numpy as np

DT64NS_DTYPE: np.dtype
TD64NS_DTYPE: np.dtype

class OutOfBoundsTimedelta(ValueError): ...

def precision_from_unit(
unit: str,
) -> tuple[
int, # int64_t
int,
]: ...


def ensure_datetime64ns(
arr: np.ndarray, # np.ndarray[datetime64[ANY]]
copy: bool = ...,
) -> np.ndarray: ... # np.ndarray[datetime64ns]


def ensure_timedelta64ns(
arr: np.ndarray, # np.ndarray[timedelta64[ANY]]
copy: bool = ...,
) -> np.ndarray: ... # np.ndarray[timedelta64ns]


def datetime_to_datetime64(
values: np.ndarray, # np.ndarray[object]
) -> tuple[
np.ndarray, # np.ndarray[dt64ns]
tzinfo | None,
]: ...


def localize_pydatetime(dt: datetime, tz: tzinfo | None) -> datetime: ...
65 changes: 65 additions & 0 deletions pandas/_libs/tslibs/dtypes.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from enum import Enum

from pandas._libs.tslibs.offsets import BaseOffset

_attrname_to_abbrevs: dict[str, str]
_period_code_map: dict[str, int]


class PeriodDtypeBase:
# actually __cinit__
def __new__(self, code: int): ...

def freq_group_code(self) -> int: ...
def date_offset(self) -> BaseOffset: ...

@classmethod
def from_date_offset(cls, offset: BaseOffset) -> PeriodDtypeBase: ...


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 = ...

@staticmethod
def get_freq_group(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 = ...

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: ...
69 changes: 69 additions & 0 deletions pandas/_libs/tslibs/fields.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import numpy as np

def build_field_sarray(
dtindex: np.ndarray, # const int64_t[:]
) -> np.ndarray: ...

def month_position_check(fields, weekdays) -> str | None: ...

def get_date_name_field(
dtindex: np.ndarray, # const int64_t[:]
field: str,
locale=...,
) -> np.ndarray: ... # np.ndarray[object]

def get_start_end_field(
dtindex: np.ndarray, # const int64_t[:]
field: str,
freqstr: str | None = ...,
month_kw: int = ...
) -> np.ndarray: ... # np.ndarray[bool]


def get_date_field(
dtindex: np.ndarray, # const int64_t[:]

field: str,
) -> np.ndarray: ... # np.ndarray[in32]


def get_timedelta_field(
tdindex: np.ndarray, # const int64_t[:]
field: str,
) -> np.ndarray: ... # np.ndarray[int32]


def isleapyear_arr(
years: np.ndarray,
) -> np.ndarray: ... # np.ndarray[bool]

def build_isocalendar_sarray(
dtindex: np.ndarray, # const int64_t[:]
) -> np.ndarray: ...


def get_locale_names(name_type: str, locale: object = None): ...


class RoundTo:
@property
def MINUS_INFTY(self) -> int: ...

@property
def PLUS_INFTY(self) -> int: ...

@property
def NEAREST_HALF_EVEN(self) -> int: ...

@property
def NEAREST_HALF_PLUS_INFTY(self) -> int: ...

@property
def NEAREST_HALF_MINUS_INFTY(self) -> int: ...


def round_nsint64(
values: np.ndarray, # np.ndarray[np.int64]
mode: RoundTo,
nanos: int,
) -> np.ndarray: ... # np.ndarray[np.int64]
1 change: 1 addition & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ def _round(self, freq, mode, ambiguous, nonexistent):
)

values = self.view("i8")
values = cast(np.ndarray, values)
nanos = to_offset(freq).nanos
result = round_nsint64(values, mode, nanos)
result = self._maybe_mask_results(result, fill_value=iNaT)
Expand Down