hashtable.pyi 7.2 KB

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