1
- from typing import Hashable
1
+ import datetime as dt
2
+ from typing import (
3
+ Any ,
4
+ Hashable ,
5
+ Literal ,
6
+ Sequence ,
7
+ Union ,
8
+ overload ,
9
+ )
2
10
3
11
import numpy as np
12
+ import pandas as pd
13
+ from pandas import Index
4
14
from pandas .core .indexes .extension import ExtensionIndex
15
+ from typing_extensions import TypeAlias
5
16
6
17
from pandas ._libs .interval import (
7
18
Interval as Interval ,
8
19
IntervalMixin as IntervalMixin ,
9
20
)
21
+ from pandas ._libs .tslibs .offsets import DateOffset
10
22
from pandas ._typing import (
23
+ DatetimeLike ,
11
24
DtypeArg ,
25
+ FillnaOptions ,
12
26
IntervalClosedType ,
27
+ Label ,
28
+ npt ,
13
29
)
14
30
15
31
from pandas .core .dtypes .dtypes import IntervalDtype as IntervalDtype
16
32
from pandas .core .dtypes .generic import ABCSeries
17
33
34
+ _Edges : TypeAlias = Union [
35
+ Sequence [int ],
36
+ Sequence [float ],
37
+ Sequence [DatetimeLike ],
38
+ npt .NDArray [np .int_ ],
39
+ npt .NDArray [np .float_ ],
40
+ npt .NDArray [np .datetime64 ],
41
+ pd .Series [int ],
42
+ pd .Series [float ],
43
+ pd .Series [pd .Timestamp ],
44
+ pd .Int64Index ,
45
+ pd .DatetimeIndex ,
46
+ ]
47
+
18
48
class IntervalIndex (IntervalMixin , ExtensionIndex ):
19
49
def __new__ (
20
50
cls ,
@@ -28,7 +58,7 @@ class IntervalIndex(IntervalMixin, ExtensionIndex):
28
58
@classmethod
29
59
def from_breaks (
30
60
cls ,
31
- breaks ,
61
+ breaks : _Edges ,
32
62
closed : IntervalClosedType = ...,
33
63
name : Hashable = ...,
34
64
copy : bool = ...,
@@ -37,8 +67,8 @@ class IntervalIndex(IntervalMixin, ExtensionIndex):
37
67
@classmethod
38
68
def from_arrays (
39
69
cls ,
40
- left ,
41
- right ,
70
+ left : _Edges ,
71
+ right : _Edges ,
42
72
closed : IntervalClosedType = ...,
43
73
name : Hashable = ...,
44
74
copy : bool = ...,
@@ -47,37 +77,67 @@ class IntervalIndex(IntervalMixin, ExtensionIndex):
47
77
@classmethod
48
78
def from_tuples (
49
79
cls ,
50
- data ,
80
+ data : Sequence [tuple [int , int ]]
81
+ | Sequence [tuple [float , float ]]
82
+ | Sequence [tuple [DatetimeLike , DatetimeLike ]]
83
+ | npt .NDArray ,
51
84
closed : IntervalClosedType = ...,
52
85
name : Hashable = ...,
53
86
copy : bool = ...,
54
87
dtype : IntervalDtype | None = ...,
55
88
) -> IntervalIndex : ...
89
+ def __contains__ (self , key : Any ) -> bool : ...
56
90
def astype (self , dtype : DtypeArg , copy : bool = ...) -> IntervalIndex : ...
57
91
@property
58
92
def inferred_type (self ) -> str : ...
59
93
def memory_usage (self , deep : bool = ...) -> int : ...
60
94
@property
61
95
def is_overlapping (self ) -> bool : ...
62
- def get_loc (self , key , tolerance = ...) -> int | slice | np .ndarray : ...
96
+ # Note: tolerance no effect. It is included in all get_loc so
97
+ # that signatures are consistent with base even though it is usually not used
98
+ def get_loc (
99
+ self ,
100
+ key : Label ,
101
+ method : FillnaOptions | Literal ["nearest" ] | None = ...,
102
+ tolerance = ...,
103
+ ) -> int | slice | npt .NDArray [np .bool_ ]: ...
63
104
def get_indexer (
64
105
self ,
65
- targetArrayLike ,
66
- method : str | None = ...,
106
+ target : Index ,
107
+ method : FillnaOptions | Literal [ "nearest" ] | None = ...,
67
108
limit : int | None = ...,
68
109
tolerance = ...,
69
- ) -> np .ndarray : ...
110
+ ) -> npt . NDArray [ np .intp ] : ...
70
111
def get_indexer_non_unique (
71
- self , targetArrayLike
72
- ) -> tuple [np .ndarray , np .ndarray ]: ...
112
+ self , target : Index
113
+ ) -> tuple [npt .NDArray [np .intp ], npt .NDArray [np .intp ]]: ...
114
+ @property
115
+ def left (self ) -> Index : ...
116
+ @property
117
+ def right (self ) -> Index : ...
118
+ @property
119
+ def mid (self ) -> Index : ...
120
+ @property
121
+ def length (self ) -> Index : ...
73
122
def get_value (self , series : ABCSeries , key ): ...
74
123
@property
75
124
def is_all_dates (self ) -> bool : ...
76
- def __lt__ (self , other ): ...
77
- def __le__ (self , other ): ...
78
- def __gt__ (self , other ): ...
79
- def __ge__ (self , other ): ...
80
125
126
+ @overload
127
+ def interval_range (
128
+ start : int | float | None = ...,
129
+ end : int | float | None = ...,
130
+ periods : int | None = ...,
131
+ freq : int | None = ...,
132
+ name : Hashable = ...,
133
+ closed : IntervalClosedType = ...,
134
+ ) -> IntervalIndex : ...
135
+ @overload
81
136
def interval_range (
82
- start = ..., end = ..., periods = ..., freq = ..., name = ..., closed : str = ...
83
- ): ...
137
+ start : DatetimeLike | None = ...,
138
+ end : DatetimeLike | None = ...,
139
+ periods : int | None = ...,
140
+ freq : str | DateOffset | None = ...,
141
+ name : Hashable = ...,
142
+ closed : IntervalClosedType = ...,
143
+ ) -> IntervalIndex : ...
0 commit comments