lib.pyi 7.0 KB

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