lib.pyi 8.1 KB

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