|
| 1 | +# TODO(npdtypes): Many types specified here can be made more specific/accurate; |
| 2 | +# the more specific versions are specified in comments |
| 3 | + |
| 4 | +from typing import ( |
| 5 | + Any, |
| 6 | + Callable, |
| 7 | +) |
| 8 | + |
| 9 | +import numpy as np |
| 10 | + |
| 11 | +from pandas._typing import ArrayLike |
| 12 | + |
| 13 | +# placeholder until we can specify np.ndarray[object, ndim=2] |
| 14 | +ndarray_obj_2d = np.ndarray |
| 15 | + |
| 16 | +from enum import Enum |
| 17 | + |
| 18 | +class NoDefault(Enum): |
| 19 | + ... |
| 20 | + |
| 21 | +no_default: NoDefault |
| 22 | + |
| 23 | + |
| 24 | +def item_from_zerodim(val: object) -> object: ... |
| 25 | +def infer_dtype(value: object, skipna: bool = True) -> str: ... |
| 26 | + |
| 27 | +def is_iterator(obj: object) -> bool: ... |
| 28 | +def is_scalar(val: object) -> bool: ... |
| 29 | +def is_list_like(obj: object, allow_sets: bool = True) -> bool: ... |
| 30 | + |
| 31 | +def is_period(val: object) -> bool: ... |
| 32 | +def is_interval(val: object) -> bool: ... |
| 33 | +def is_decimal(val: object) -> bool: ... |
| 34 | +def is_complex(val: object) -> bool: ... |
| 35 | +def is_bool(val: object) -> bool: ... |
| 36 | +def is_integer(val: object) -> bool: ... |
| 37 | +def is_float(val: object) -> bool: ... |
| 38 | + |
| 39 | +def is_interval_array(values: np.ndarray) -> bool: ... |
| 40 | +def is_period_array(values: np.ndarray) -> bool: ... |
| 41 | +def is_datetime64_array(values: np.ndarray) -> bool: ... |
| 42 | +def is_timedelta_or_timedelta64_array(values: np.ndarray) -> bool: ... |
| 43 | +def is_datetime_with_singletz_array(values: np.ndarray) -> bool: ... |
| 44 | + |
| 45 | +def is_time_array(values: np.ndarray, skipna: bool = False): ... |
| 46 | +def is_date_array(values: np.ndarray, skipna: bool = False): ... |
| 47 | +def is_datetime_array(values: np.ndarray, skipna: bool = False): ... |
| 48 | +def is_string_array(values: np.ndarray, skipna: bool = False): ... |
| 49 | +def is_float_array(values: np.ndarray, skipna: bool = False): ... |
| 50 | +def is_integer_array(values: np.ndarray, skipna: bool = False): ... |
| 51 | +def is_bool_array(values: np.ndarray, skipna: bool = False): ... |
| 52 | + |
| 53 | +def fast_multiget(mapping: dict, keys: np.ndarray, default=np.nan) -> ArrayLike: ... |
| 54 | + |
| 55 | +# TODO: gen: Generator? |
| 56 | +def fast_unique_multiple_list_gen(gen: object, sort: bool = True) -> list: ... |
| 57 | +def fast_unique_multiple_list(lists: list, sort: bool = True) -> list: ... |
| 58 | +def fast_unique_multiple(arrays: list, sort: bool = True) -> list: ... |
| 59 | + |
| 60 | +def map_infer( |
| 61 | + arr: np.ndarray, f: Callable[[Any], Any], convert: bool = True, ignore_na: bool = False |
| 62 | +) -> ArrayLike: ... |
| 63 | + |
| 64 | +def maybe_convert_objects( |
| 65 | + objects: np.ndarray, # np.ndarray[object] |
| 66 | + try_float: bool = False, |
| 67 | + safe: bool = False, |
| 68 | + convert_datetime: bool = False, |
| 69 | + convert_timedelta: bool = False, |
| 70 | + convert_to_nullable_integer: bool = False, |
| 71 | +) -> ArrayLike: ... |
| 72 | + |
| 73 | +def maybe_convert_numeric( |
| 74 | + values: np.ndarray, # np.ndarray[object] |
| 75 | + na_values: set, |
| 76 | + convert_empty: bool = True, |
| 77 | + coerce_numeric: bool = False, |
| 78 | +) -> np.ndarray: ... |
| 79 | + |
| 80 | +# TODO: restrict `arr`? |
| 81 | +def ensure_string_array( |
| 82 | + arr, |
| 83 | + na_value: object = np.nan, |
| 84 | + convert_na_value: bool = True, |
| 85 | + copy: bool = True, |
| 86 | + skipna: bool = True, |
| 87 | +) -> np.ndarray: ... # np.ndarray[object] |
| 88 | + |
| 89 | +def infer_datetimelike_array( |
| 90 | + arr: np.ndarray # np.ndarray[object] |
| 91 | +) -> str: ... |
| 92 | + |
| 93 | +# TODO: new_dtype -> np.dtype? |
| 94 | +def astype_intsafe( |
| 95 | + arr: np.ndarray, # np.ndarray[object] |
| 96 | + new_dtype, |
| 97 | +) -> np.ndarray: ... |
| 98 | + |
| 99 | +def fast_zip(ndarrays: list) -> np.ndarray: ... # np.ndarray[object] |
| 100 | + |
| 101 | +# TODO: can we be more specific about rows? |
| 102 | +def to_object_array_tuples(rows: object) -> ndarray_obj_2d: ... |
| 103 | + |
| 104 | +def tuples_to_object_array( |
| 105 | + tuples: np.ndarray # np.ndarray[object] |
| 106 | +) -> ndarray_obj_2d: ... |
| 107 | + |
| 108 | +# TODO: can we be more specific about rows? |
| 109 | +def to_object_array(rows: object, min_width: int = 0) -> ndarray_obj_2d: ... |
| 110 | + |
| 111 | +def dicts_to_array(dicts: list, columns: list) -> ndarray_obj_2d: ... |
| 112 | + |
| 113 | + |
| 114 | +def maybe_booleans_to_slice( |
| 115 | + mask: np.ndarray # ndarray[uint8_t] |
| 116 | +) -> slice | np.ndarray: ... # np.ndarray[np.uint8] |
| 117 | + |
| 118 | +def maybe_indices_to_slice( |
| 119 | + indices: np.ndarray, # np.ndarray[np.intp] |
| 120 | + max_len: int, |
| 121 | +) -> slice | np.ndarray: ... # np.ndarray[np.uint8] |
| 122 | + |
| 123 | +def clean_index_list(obj: list) -> tuple[ |
| 124 | + list | np.ndarray, # np.ndarray[object] | np.ndarray[np.int64] |
| 125 | + bool, |
| 126 | +]: ... |
| 127 | + |
| 128 | + |
| 129 | +# ----------------------------------------------------------------- |
| 130 | +# Functions which in reality take memoryviews |
| 131 | + |
| 132 | +def memory_usage_of_objects( |
| 133 | + arr: np.ndarray # object[:] |
| 134 | +) -> int: ... # np.int64 |
| 135 | + |
| 136 | + |
| 137 | +# TODO: f: Callable? |
| 138 | +# TODO: dtype -> DtypeObj? |
| 139 | +def map_infer_mask( |
| 140 | + arr: np.ndarray, |
| 141 | + f: Callable[[Any], Any], |
| 142 | + mask: np.ndarray, # const uint8_t[:] |
| 143 | + convert: bool = ..., |
| 144 | + na_value: Any = ..., |
| 145 | + dtype: Any = ..., |
| 146 | +) -> ArrayLike: ... |
| 147 | + |
| 148 | +def indices_fast( |
| 149 | + index: np.ndarray, # ndarray[intp_t] |
| 150 | + labels: np.ndarray, # const int64_t[:] |
| 151 | + keys: list, |
| 152 | + sorted_labels: list[np.ndarray], # list[ndarray[np.int64]] |
| 153 | +) -> dict: ... |
| 154 | + |
| 155 | +def generate_slices( |
| 156 | + labels: np.ndarray, # const intp_t[:] |
| 157 | + ngroups: int |
| 158 | +) -> tuple[ |
| 159 | + np.ndarray, # np.ndarray[np.int64] |
| 160 | + np.ndarray, # np.ndarray[np.int64] |
| 161 | +]: ... |
| 162 | + |
| 163 | +def count_level_2d( |
| 164 | + mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True], |
| 165 | + labels: np.ndarray, # const intp_t[:] |
| 166 | + max_bin: int, |
| 167 | + axis: int |
| 168 | +) -> np.ndarray: ... # np.ndarray[np.int64, ndim=2] |
| 169 | + |
| 170 | +def get_level_sorter( |
| 171 | + label: np.ndarray, # const int64_t[:] |
| 172 | + starts: np.ndarray, # const intp_t[:] |
| 173 | +) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1] |
| 174 | + |
| 175 | + |
| 176 | +def generate_bins_dt64( |
| 177 | + values: np.ndarray, # np.ndarray[np.int64] |
| 178 | + binner: np.ndarray, # const int64_t[:] |
| 179 | + closed: object = "left", |
| 180 | + hasnans: bool = False, |
| 181 | +) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1] |
| 182 | + |
| 183 | + |
| 184 | +def array_equivalent_object( |
| 185 | + left: np.ndarray, # object[:] |
| 186 | + right: np.ndarray, # object[:] |
| 187 | +) -> bool: ... |
| 188 | + |
| 189 | +def has_infs_f8( |
| 190 | + arr: np.ndarray # const float64_t[:] |
| 191 | +) -> bool: ... |
| 192 | + |
| 193 | +def has_infs_f4( |
| 194 | + arr: np.ndarray # const float32_t[:] |
| 195 | +) -> bool: ... |
| 196 | + |
| 197 | +def get_reverse_indexer( |
| 198 | + indexer: np.ndarray, # const intp_t[:] |
| 199 | + length: int, |
| 200 | +) -> np.ndarray: ... # np.ndarray[np.intp] |
0 commit comments