forked from pandas-dev/pandas-stubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.pyi
465 lines (458 loc) · 13.8 KB
/
base.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
from collections.abc import (
Callable,
Hashable,
Iterable,
Iterator,
Sequence,
)
from datetime import (
datetime,
timedelta,
)
from typing import (
Any,
ClassVar,
Literal,
TypeAlias,
final,
overload,
)
import numpy as np
from pandas import (
DataFrame,
DatetimeIndex,
Interval,
IntervalIndex,
MultiIndex,
Period,
PeriodDtype,
PeriodIndex,
Series,
TimedeltaIndex,
)
from pandas.core.arrays import ExtensionArray
from pandas.core.base import IndexOpsMixin
from pandas.core.strings import StringMethods
from typing_extensions import (
Never,
Self,
)
from pandas._libs.interval import _OrderableT
from pandas._typing import (
S1,
Dtype,
DtypeArg,
DtypeObj,
FillnaOptions,
HashableT,
Label,
Level,
MaskType,
NaPosition,
TimedeltaDtypeArg,
TimestampDtypeArg,
np_ndarray_anyint,
np_ndarray_bool,
np_ndarray_complex,
np_ndarray_float,
type_t,
)
class InvalidIndexError(Exception): ...
_str = str
class Index(IndexOpsMixin[S1]):
__hash__: ClassVar[None] # type: ignore[assignment]
# overloads with additional dtypes
@overload
def __new__( # pyright: ignore[reportOverlappingOverload]
cls,
data: Sequence[int | np.integer] | IndexOpsMixin[int] | np_ndarray_anyint,
*,
dtype: Literal["int"] | type_t[int | np.integer] = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Index[int]: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: Literal["int"] | type_t[int | np.integer],
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Index[int]: ...
@overload
def __new__(
cls,
data: Sequence[float | np.floating] | IndexOpsMixin[float] | np_ndarray_float,
*,
dtype: Literal["float"] | type_t[float | np.floating] = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Index[float]: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: Literal["float"] | type_t[float | np.floating],
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Index[float]: ...
@overload
def __new__(
cls,
data: (
Sequence[complex | np.complexfloating]
| IndexOpsMixin[complex]
| np_ndarray_complex
),
*,
dtype: Literal["complex"] | type_t[complex | np.complexfloating] = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Index[complex]: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: Literal["complex"] | type_t[complex | np.complexfloating],
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Index[complex]: ...
# special overloads with dedicated Index-subclasses
@overload
def __new__(
cls,
data: Sequence[np.datetime64 | datetime] | IndexOpsMixin[datetime],
*,
dtype: TimestampDtypeArg = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> DatetimeIndex: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: TimestampDtypeArg,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> DatetimeIndex: ...
@overload
def __new__(
cls,
data: Sequence[Period] | IndexOpsMixin[Period],
*,
dtype: PeriodDtype = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> PeriodIndex: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: PeriodDtype,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> PeriodIndex: ...
@overload
def __new__(
cls,
data: Sequence[np.timedelta64 | timedelta] | IndexOpsMixin[timedelta],
*,
dtype: TimedeltaDtypeArg = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> TimedeltaIndex: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: TimedeltaDtypeArg,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> TimedeltaIndex: ...
@overload
def __new__(
cls,
data: Sequence[Interval[_OrderableT]] | IndexOpsMixin[Interval[_OrderableT]],
*,
dtype: Literal["Interval"] = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> IntervalIndex[Interval[_OrderableT]]: ...
@overload
def __new__(
cls,
data: Iterable,
*,
dtype: Literal["Interval"],
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> IntervalIndex[Interval[Any]]: ...
# generic overloads
@overload
def __new__(
cls,
data: Iterable[S1] | IndexOpsMixin[S1],
*,
dtype: type[S1] = ...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Self: ...
@overload
def __new__(
cls,
data: Iterable = ...,
*,
dtype: type[S1],
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Self: ...
# fallback overload
@overload
def __new__(
cls,
data: Iterable,
*,
dtype=...,
copy: bool = ...,
name: Hashable = ...,
tupleize_cols: bool = ...,
**kwargs,
) -> Self: ...
@property
def str(
self,
) -> StringMethods[Self, MultiIndex, np_ndarray_bool, Index[list[str]]]: ...
def is_(self, other) -> bool: ...
def __len__(self) -> int: ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __array_wrap__(self, result, context=...): ...
@property
def dtype(self) -> DtypeObj: ...
def ravel(self, order: _str = ...): ...
def view(self, cls=...): ...
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Index: ...
def take(
self, indices, axis: int = ..., allow_fill: bool = ..., fill_value=..., **kwargs
): ...
def repeat(self, repeats, axis=...): ...
def copy(self, name: Hashable = ..., deep: bool = ...) -> Self: ...
def __copy__(self, **kwargs): ...
def __deepcopy__(self, memo=...): ...
def format(
self, name: bool = ..., formatter: Callable | None = ..., na_rep: _str = ...
) -> list[_str]: ...
def to_flat_index(self): ...
def to_series(self, index=..., name: Hashable = ...) -> Series: ...
def to_frame(self, index: bool = ..., name=...) -> DataFrame: ...
@property
def name(self): ...
@name.setter
def name(self, value) -> None: ...
@property
def names(self) -> list[_str]: ...
@names.setter
def names(self, names: list[_str]): ...
def set_names(self, names, *, level=..., inplace: bool = ...): ...
@overload
def rename(self, name, inplace: Literal[False] = False) -> Self: ...
@overload
def rename(self, name, inplace: Literal[True]) -> None: ...
@property
def nlevels(self) -> int: ...
def sortlevel(self, level=..., ascending: bool = ..., sort_remaining=...): ...
def get_level_values(self, level: int | _str) -> Index: ...
def droplevel(self, level: Level | list[Level] = ...): ...
@property
def is_monotonic_increasing(self) -> bool: ...
@property
def is_monotonic_decreasing(self) -> bool: ...
@property
def is_unique(self) -> bool: ...
@property
def has_duplicates(self) -> bool: ...
@property
def inferred_type(self) -> _str: ...
def __reduce__(self): ...
@property
def hasnans(self) -> bool: ...
def isna(self): ...
isnull = ...
def notna(self): ...
notnull = ...
def fillna(self, value=...): ...
def dropna(self, how: Literal["any", "all"] = ...) -> Self: ...
def unique(self, level=...) -> Self: ...
def drop_duplicates(self, *, keep: NaPosition | Literal[False] = ...) -> Self: ...
def duplicated(
self, keep: Literal["first", "last", False] = ...
) -> np_ndarray_bool: ...
def __and__(self, other: Never) -> Never: ...
def __rand__(self, other: Never) -> Never: ...
def __or__(self, other: Never) -> Never: ...
def __ror__(self, other: Never) -> Never: ...
def __xor__(self, other: Never) -> Never: ...
def __rxor__(self, other: Never) -> Never: ...
def __neg__(self) -> Self: ...
def __nonzero__(self) -> None: ...
__bool__ = ...
def union(self, other: list[HashableT] | Index, sort=...) -> Index: ...
def intersection(self, other: list[S1] | Self, sort: bool = ...) -> Self: ...
def difference(self, other: list | Index, sort: bool | None = None) -> Self: ...
def symmetric_difference(
self, other: list[S1] | Self, result_name: Hashable = ..., sort=...
) -> Self: ...
def get_loc(
self,
key: Label,
method: FillnaOptions | Literal["nearest"] | None = ...,
tolerance=...,
) -> int | slice | np_ndarray_bool: ...
def get_indexer(self, target, method=..., limit=..., tolerance=...): ...
def reindex(self, target, method=..., level=..., limit=..., tolerance=...): ...
def join(
self,
other,
*,
how: _str = ...,
level=...,
return_indexers: bool = ...,
sort: bool = ...,
): ...
@property
def values(self) -> np.ndarray: ...
@property
def array(self) -> ExtensionArray: ...
def memory_usage(self, deep: bool = ...): ...
def where(self, cond, other=...): ...
def __contains__(self, key) -> bool: ...
def __setitem__(self, key, value) -> None: ...
@overload
def __getitem__(
self,
idx: slice | np_ndarray_anyint | Sequence[int] | Index | MaskType,
) -> Self: ...
@overload
def __getitem__(self, idx: int | tuple[np_ndarray_anyint, ...]) -> S1: ...
def append(self, other): ...
def putmask(self, mask, value): ...
def equals(self, other) -> bool: ...
def identical(self, other) -> bool: ...
def asof(self, label): ...
def asof_locs(self, where, mask): ...
def sort_values(self, return_indexer: bool = ..., ascending: bool = ...): ...
def sort(self, *args, **kwargs) -> None: ...
def shift(self, periods: int = ..., freq=...) -> None: ...
def argsort(self, *args, **kwargs): ...
def get_indexer_non_unique(self, target): ...
def get_indexer_for(self, target, **kwargs): ...
@final
def groupby(self, values) -> dict[Hashable, np.ndarray]: ...
def map(self, mapper, na_action=...) -> Index: ...
def isin(self, values, level=...) -> np_ndarray_bool: ...
def slice_indexer(self, start=..., end=..., step=...): ...
def get_slice_bound(self, label, side): ...
def slice_locs(self, start=..., end=..., step=...): ...
def delete(self, loc): ...
def insert(self, loc, item): ...
def drop(self, labels, errors: _str = ...) -> Self: ...
@property
def shape(self) -> tuple[int, ...]: ...
# Extra methods from old stubs
def __eq__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __iter__(self) -> Iterator[S1]: ...
def __ne__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __le__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __ge__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __lt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __gt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
# overwrite inherited methods from OpsMixin
@overload
def __mul__(
self: Index[int] | Index[float], other: timedelta
) -> TimedeltaIndex: ...
@overload
def __mul__(self, other: Any) -> Self: ...
def __floordiv__(
self,
other: (
float
| IndexOpsMixin[int]
| IndexOpsMixin[float]
| Sequence[int]
| Sequence[float]
),
) -> Self: ...
def __rfloordiv__(
self,
other: (
float
| IndexOpsMixin[int]
| IndexOpsMixin[float]
| Sequence[int]
| Sequence[float]
),
) -> Self: ...
def __truediv__(
self,
other: (
float
| IndexOpsMixin[int]
| IndexOpsMixin[float]
| Sequence[int]
| Sequence[float]
),
) -> Self: ...
def __rtruediv__(
self,
other: (
float
| IndexOpsMixin[int]
| IndexOpsMixin[float]
| Sequence[int]
| Sequence[float]
),
) -> Self: ...
UnknownIndex: TypeAlias = Index[Any]
def ensure_index_from_sequences(
sequences: Sequence[Sequence[Dtype]], names: list[str] = ...
) -> Index: ...
def ensure_index(index_like: Sequence | Index, copy: bool = ...) -> Index: ...
def maybe_extract_name(name, obj, cls) -> Label: ...