TYP: timedeltas.pyi (#40766) · pandas-dev/pandas@84d9c5e (original) (raw)

``

1

`+

from datetime import timedelta

`

``

2

`+

from typing import (

`

``

3

`+

ClassVar,

`

``

4

`+

Type,

`

``

5

`+

TypeVar,

`

``

6

`+

overload,

`

``

7

`+

)

`

``

8

+

``

9

`+

import numpy as np

`

``

10

+

``

11

`+

from pandas._libs.tslibs import (

`

``

12

`+

NaTType,

`

``

13

`+

Tick,

`

``

14

`+

)

`

``

15

+

``

16

`+

_S = TypeVar("_S")

`

``

17

+

``

18

+

``

19

`+

def ints_to_pytimedelta(

`

``

20

`+

arr: np.ndarray, # const int64_t[:]

`

``

21

`+

box: bool = ...,

`

``

22

`+

) -> np.ndarray: ... # np.ndarray[object]

`

``

23

+

``

24

+

``

25

`+

def array_to_timedelta64(

`

``

26

`+

values: np.ndarray, # ndarray[object]

`

``

27

`+

unit: str | None = ...,

`

``

28

`+

errors: str = ...,

`

``

29

`+

) -> np.ndarray: ... # np.ndarray[m8ns]

`

``

30

+

``

31

+

``

32

`+

def parse_timedelta_unit(unit: str | None) -> str: ...

`

``

33

+

``

34

+

``

35

`+

def delta_to_nanoseconds(delta: Tick | np.timedelta64 | timedelta | int) -> int: ...

`

``

36

+

``

37

+

``

38

`+

class Timedelta(timedelta):

`

``

39

`+

min: ClassVar[Timedelta]

`

``

40

`+

max: ClassVar[Timedelta]

`

``

41

`+

resolution: ClassVar[Timedelta]

`

``

42

`+

value: int # np.int64

`

``

43

+

``

44

`+

error: "new" must return a class instance (got "Union[Timedelta, NaTType]")

`

``

45

`+

def new( # type: ignore[misc]

`

``

46

`+

cls: Type[_S],

`

``

47

`+

value=...,

`

``

48

`+

unit=...,

`

``

49

`+

**kwargs

`

``

50

`+

) -> _S | NaTType: ...

`

``

51

+

``

52

`+

@property

`

``

53

`+

def days(self) -> int: ...

`

``

54

`+

@property

`

``

55

`+

def seconds(self) -> int: ...

`

``

56

`+

@property

`

``

57

`+

def microseconds(self) -> int: ...

`

``

58

`+

def total_seconds(self) -> float: ...

`

``

59

+

``

60

`+

def to_pytimedelta(self) -> timedelta: ...

`

``

61

`+

def to_timedelta64(self) -> np.timedelta64: ...

`

``

62

+

``

63

`+

@property

`

``

64

`+

def asm8(self) -> np.timedelta64: ...

`

``

65

+

``

66

`+

TODO: round/floor/ceil could return NaT?

`

``

67

`+

def round(self: _S, freq) -> _S: ...

`

``

68

`+

def floor(self: _S, freq) -> _S: ...

`

``

69

`+

def ceil(self: _S, freq) -> _S: ...

`

``

70

+

``

71

`+

@property

`

``

72

`+

def resolution_string(self) -> str: ...

`

``

73

+

``

74

`+

def add(self, other: timedelta) -> timedelta: ...

`

``

75

`+

def radd(self, other: timedelta) -> timedelta: ...

`

``

76

`+

def sub(self, other: timedelta) -> timedelta: ...

`

``

77

`+

def rsub(self, other: timedelta) -> timedelta: ...

`

``

78

`+

def neg(self) -> timedelta: ...

`

``

79

`+

def pos(self) -> timedelta: ...

`

``

80

`+

def abs(self) -> timedelta: ...

`

``

81

`+

def mul(self, other: float) -> timedelta: ...

`

``

82

`+

def rmul(self, other: float) -> timedelta: ...

`

``

83

+

``

84

`+

@overload

`

``

85

`+

def floordiv(self, other: timedelta) -> int: ...

`

``

86

`+

@overload

`

``

87

`+

def floordiv(self, other: int) -> timedelta: ...

`

``

88

+

``

89

`+

@overload

`

``

90

`+

def truediv(self, other: timedelta) -> float: ...

`

``

91

`+

@overload

`

``

92

`+

def truediv(self, other: float) -> timedelta: ...

`

``

93

`+

def mod(self, other: timedelta) -> timedelta: ...

`

``

94

`+

def divmod(self, other: timedelta) -> tuple[int, timedelta]: ...

`

``

95

+

``

96

`+

def le(self, other: timedelta) -> bool: ...

`

``

97

`+

def lt(self, other: timedelta) -> bool: ...

`

``

98

`+

def ge(self, other: timedelta) -> bool: ...

`

``

99

`+

def gt(self, other: timedelta) -> bool: ...

`

``

100

`+

def hash(self) -> int: ...

`