lib.pyi 7.6 KB

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