hashtable.pyi 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. from typing import (
  2. Any,
  3. Hashable,
  4. Literal,
  5. )
  6. import numpy as np
  7. from pandas._typing import npt
  8. def unique_label_indices(
  9. labels: np.ndarray, # const int64_t[:]
  10. ) -> np.ndarray: ...
  11. class Factorizer:
  12. count: int
  13. uniques: Any
  14. def __init__(self, size_hint: int) -> None: ...
  15. def get_count(self) -> int: ...
  16. def factorize(
  17. self,
  18. values: np.ndarray,
  19. na_sentinel=...,
  20. na_value=...,
  21. mask=...,
  22. ) -> npt.NDArray[np.intp]: ...
  23. class ObjectFactorizer(Factorizer):
  24. table: PyObjectHashTable
  25. uniques: ObjectVector
  26. class Int64Factorizer(Factorizer):
  27. table: Int64HashTable
  28. uniques: Int64Vector
  29. class UInt64Factorizer(Factorizer):
  30. table: UInt64HashTable
  31. uniques: UInt64Vector
  32. class Int32Factorizer(Factorizer):
  33. table: Int32HashTable
  34. uniques: Int32Vector
  35. class UInt32Factorizer(Factorizer):
  36. table: UInt32HashTable
  37. uniques: UInt32Vector
  38. class Int16Factorizer(Factorizer):
  39. table: Int16HashTable
  40. uniques: Int16Vector
  41. class UInt16Factorizer(Factorizer):
  42. table: UInt16HashTable
  43. uniques: UInt16Vector
  44. class Int8Factorizer(Factorizer):
  45. table: Int8HashTable
  46. uniques: Int8Vector
  47. class UInt8Factorizer(Factorizer):
  48. table: UInt8HashTable
  49. uniques: UInt8Vector
  50. class Float64Factorizer(Factorizer):
  51. table: Float64HashTable
  52. uniques: Float64Vector
  53. class Float32Factorizer(Factorizer):
  54. table: Float32HashTable
  55. uniques: Float32Vector
  56. class Complex64Factorizer(Factorizer):
  57. table: Complex64HashTable
  58. uniques: Complex64Vector
  59. class Complex128Factorizer(Factorizer):
  60. table: Complex128HashTable
  61. uniques: Complex128Vector
  62. class Int64Vector:
  63. def __init__(self, *args) -> None: ...
  64. def __len__(self) -> int: ...
  65. def to_array(self) -> npt.NDArray[np.int64]: ...
  66. class Int32Vector:
  67. def __init__(self, *args) -> None: ...
  68. def __len__(self) -> int: ...
  69. def to_array(self) -> npt.NDArray[np.int32]: ...
  70. class Int16Vector:
  71. def __init__(self, *args) -> None: ...
  72. def __len__(self) -> int: ...
  73. def to_array(self) -> npt.NDArray[np.int16]: ...
  74. class Int8Vector:
  75. def __init__(self, *args) -> None: ...
  76. def __len__(self) -> int: ...
  77. def to_array(self) -> npt.NDArray[np.int8]: ...
  78. class UInt64Vector:
  79. def __init__(self, *args) -> None: ...
  80. def __len__(self) -> int: ...
  81. def to_array(self) -> npt.NDArray[np.uint64]: ...
  82. class UInt32Vector:
  83. def __init__(self, *args) -> None: ...
  84. def __len__(self) -> int: ...
  85. def to_array(self) -> npt.NDArray[np.uint32]: ...
  86. class UInt16Vector:
  87. def __init__(self, *args) -> None: ...
  88. def __len__(self) -> int: ...
  89. def to_array(self) -> npt.NDArray[np.uint16]: ...
  90. class UInt8Vector:
  91. def __init__(self, *args) -> None: ...
  92. def __len__(self) -> int: ...
  93. def to_array(self) -> npt.NDArray[np.uint8]: ...
  94. class Float64Vector:
  95. def __init__(self, *args) -> None: ...
  96. def __len__(self) -> int: ...
  97. def to_array(self) -> npt.NDArray[np.float64]: ...
  98. class Float32Vector:
  99. def __init__(self, *args) -> None: ...
  100. def __len__(self) -> int: ...
  101. def to_array(self) -> npt.NDArray[np.float32]: ...
  102. class Complex128Vector:
  103. def __init__(self, *args) -> None: ...
  104. def __len__(self) -> int: ...
  105. def to_array(self) -> npt.NDArray[np.complex128]: ...
  106. class Complex64Vector:
  107. def __init__(self, *args) -> None: ...
  108. def __len__(self) -> int: ...
  109. def to_array(self) -> npt.NDArray[np.complex64]: ...
  110. class StringVector:
  111. def __init__(self, *args) -> None: ...
  112. def __len__(self) -> int: ...
  113. def to_array(self) -> npt.NDArray[np.object_]: ...
  114. class ObjectVector:
  115. def __init__(self, *args) -> None: ...
  116. def __len__(self) -> int: ...
  117. def to_array(self) -> npt.NDArray[np.object_]: ...
  118. class HashTable:
  119. # NB: The base HashTable class does _not_ actually have these methods;
  120. # we are putting them here for the sake of mypy to avoid
  121. # reproducing them in each subclass below.
  122. def __init__(self, size_hint: int = ..., uses_mask: bool = ...) -> None: ...
  123. def __len__(self) -> int: ...
  124. def __contains__(self, key: Hashable) -> bool: ...
  125. def sizeof(self, deep: bool = ...) -> int: ...
  126. def get_state(self) -> dict[str, int]: ...
  127. # TODO: `val/key` type is subclass-specific
  128. def get_item(self, val): ... # TODO: return type?
  129. def set_item(self, key, val) -> None: ...
  130. def get_na(self): ... # TODO: return type?
  131. def set_na(self, val) -> None: ...
  132. def map_locations(
  133. self,
  134. values: np.ndarray, # np.ndarray[subclass-specific]
  135. mask: npt.NDArray[np.bool_] | None = ...,
  136. ) -> None: ...
  137. def lookup(
  138. self,
  139. values: np.ndarray, # np.ndarray[subclass-specific]
  140. mask: npt.NDArray[np.bool_] | None = ...,
  141. ) -> npt.NDArray[np.intp]: ...
  142. def get_labels(
  143. self,
  144. values: np.ndarray, # np.ndarray[subclass-specific]
  145. uniques, # SubclassTypeVector
  146. count_prior: int = ...,
  147. na_sentinel: int = ...,
  148. na_value: object = ...,
  149. mask=...,
  150. ) -> npt.NDArray[np.intp]: ...
  151. def unique(
  152. self,
  153. values: np.ndarray, # np.ndarray[subclass-specific]
  154. return_inverse: bool = ...,
  155. mask=...,
  156. ) -> (
  157. tuple[
  158. np.ndarray, # np.ndarray[subclass-specific]
  159. npt.NDArray[np.intp],
  160. ]
  161. | np.ndarray
  162. ): ... # np.ndarray[subclass-specific]
  163. def factorize(
  164. self,
  165. values: np.ndarray, # np.ndarray[subclass-specific]
  166. na_sentinel: int = ...,
  167. na_value: object = ...,
  168. mask=...,
  169. ignore_na: bool = True,
  170. ) -> tuple[np.ndarray, npt.NDArray[np.intp]]: ... # np.ndarray[subclass-specific]
  171. class Complex128HashTable(HashTable): ...
  172. class Complex64HashTable(HashTable): ...
  173. class Float64HashTable(HashTable): ...
  174. class Float32HashTable(HashTable): ...
  175. class Int64HashTable(HashTable):
  176. # Only Int64HashTable has get_labels_groupby, map_keys_to_values
  177. def get_labels_groupby(
  178. self,
  179. values: npt.NDArray[np.int64], # const int64_t[:]
  180. ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.int64]]: ...
  181. def map_keys_to_values(
  182. self,
  183. keys: npt.NDArray[np.int64],
  184. values: npt.NDArray[np.int64], # const int64_t[:]
  185. ) -> None: ...
  186. class Int32HashTable(HashTable): ...
  187. class Int16HashTable(HashTable): ...
  188. class Int8HashTable(HashTable): ...
  189. class UInt64HashTable(HashTable): ...
  190. class UInt32HashTable(HashTable): ...
  191. class UInt16HashTable(HashTable): ...
  192. class UInt8HashTable(HashTable): ...
  193. class StringHashTable(HashTable): ...
  194. class PyObjectHashTable(HashTable): ...
  195. class IntpHashTable(HashTable): ...
  196. def duplicated(
  197. values: np.ndarray,
  198. keep: Literal["last", "first", False] = ...,
  199. mask: npt.NDArray[np.bool_] | None = ...,
  200. ) -> npt.NDArray[np.bool_]: ...
  201. def mode(
  202. values: np.ndarray, dropna: bool, mask: npt.NDArray[np.bool_] | None = ...
  203. ) -> np.ndarray: ...
  204. def value_count(
  205. values: np.ndarray,
  206. dropna: bool,
  207. mask: npt.NDArray[np.bool_] | None = ...,
  208. ) -> tuple[np.ndarray, npt.NDArray[np.int64], int]: ... # np.ndarray[same-as-values]
  209. # arr and values should have same dtype
  210. def ismember(
  211. arr: np.ndarray,
  212. values: np.ndarray,
  213. ) -> npt.NDArray[np.bool_]: ...
  214. def object_hash(obj) -> int: ...
  215. def objects_are_equal(a, b) -> bool: ...