records.pyi 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. # ruff: noqa: ANN401
  2. # pyright: reportSelfClsParameterName=false
  3. from collections.abc import Iterable, Sequence
  4. from typing import Any, ClassVar, Literal, Protocol, SupportsIndex, TypeAlias, overload, type_check_only
  5. from _typeshed import StrOrBytesPath
  6. from typing_extensions import TypeVar
  7. import numpy as np
  8. from numpy import _ByteOrder, _OrderKACF, _SupportsBuffer
  9. from numpy._typing import ArrayLike, DTypeLike, NDArray, _ArrayLikeVoid_co, _NestedSequence, _ShapeLike
  10. __all__ = [
  11. "array",
  12. "find_duplicate",
  13. "format_parser",
  14. "fromarrays",
  15. "fromfile",
  16. "fromrecords",
  17. "fromstring",
  18. "recarray",
  19. "record",
  20. ]
  21. _T = TypeVar("_T")
  22. _SCT = TypeVar("_SCT", bound=np.generic)
  23. _DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], covariant=True)
  24. _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
  25. _RecArray: TypeAlias = recarray[Any, np.dtype[_SCT]]
  26. @type_check_only
  27. class _SupportsReadInto(Protocol):
  28. def seek(self, offset: int, whence: int, /) -> object: ...
  29. def tell(self, /) -> int: ...
  30. def readinto(self, buffer: memoryview, /) -> int: ...
  31. ###
  32. # exported in `numpy.rec`
  33. class record(np.void):
  34. def __getattribute__(self, attr: str) -> Any: ...
  35. def __setattr__(self, attr: str, val: ArrayLike) -> None: ...
  36. def pprint(self) -> str: ...
  37. @overload
  38. def __getitem__(self, key: str | SupportsIndex) -> Any: ...
  39. @overload
  40. def __getitem__(self, key: list[str]) -> record: ...
  41. # exported in `numpy.rec`
  42. class recarray(np.ndarray[_ShapeT_co, _DTypeT_co]):
  43. __name__: ClassVar[Literal["record"]] = "record"
  44. __module__: Literal["numpy"] = "numpy"
  45. @overload
  46. def __new__(
  47. subtype,
  48. shape: _ShapeLike,
  49. dtype: None = None,
  50. buf: _SupportsBuffer | None = None,
  51. offset: SupportsIndex = 0,
  52. strides: _ShapeLike | None = None,
  53. *,
  54. formats: DTypeLike,
  55. names: str | Sequence[str] | None = None,
  56. titles: str | Sequence[str] | None = None,
  57. byteorder: _ByteOrder | None = None,
  58. aligned: bool = False,
  59. order: _OrderKACF = "C",
  60. ) -> _RecArray[record]: ...
  61. @overload
  62. def __new__(
  63. subtype,
  64. shape: _ShapeLike,
  65. dtype: DTypeLike,
  66. buf: _SupportsBuffer | None = None,
  67. offset: SupportsIndex = 0,
  68. strides: _ShapeLike | None = None,
  69. formats: None = None,
  70. names: None = None,
  71. titles: None = None,
  72. byteorder: None = None,
  73. aligned: Literal[False] = False,
  74. order: _OrderKACF = "C",
  75. ) -> _RecArray[Any]: ...
  76. def __array_finalize__(self, /, obj: object) -> None: ...
  77. def __getattribute__(self, attr: str, /) -> Any: ...
  78. def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ...
  79. #
  80. @overload
  81. def field(self, /, attr: int | str, val: ArrayLike) -> None: ...
  82. @overload
  83. def field(self, /, attr: int | str, val: None = None) -> Any: ...
  84. # exported in `numpy.rec`
  85. class format_parser:
  86. dtype: np.dtype[np.void]
  87. def __init__(
  88. self,
  89. /,
  90. formats: DTypeLike,
  91. names: str | Sequence[str] | None,
  92. titles: str | Sequence[str] | None,
  93. aligned: bool = False,
  94. byteorder: _ByteOrder | None = None,
  95. ) -> None: ...
  96. # exported in `numpy.rec`
  97. @overload
  98. def fromarrays(
  99. arrayList: Iterable[ArrayLike],
  100. dtype: DTypeLike | None = None,
  101. shape: _ShapeLike | None = None,
  102. formats: None = None,
  103. names: None = None,
  104. titles: None = None,
  105. aligned: bool = False,
  106. byteorder: None = None,
  107. ) -> _RecArray[Any]: ...
  108. @overload
  109. def fromarrays(
  110. arrayList: Iterable[ArrayLike],
  111. dtype: None = None,
  112. shape: _ShapeLike | None = None,
  113. *,
  114. formats: DTypeLike,
  115. names: str | Sequence[str] | None = None,
  116. titles: str | Sequence[str] | None = None,
  117. aligned: bool = False,
  118. byteorder: _ByteOrder | None = None,
  119. ) -> _RecArray[record]: ...
  120. @overload
  121. def fromrecords(
  122. recList: _ArrayLikeVoid_co | tuple[object, ...] | _NestedSequence[tuple[object, ...]],
  123. dtype: DTypeLike | None = None,
  124. shape: _ShapeLike | None = None,
  125. formats: None = None,
  126. names: None = None,
  127. titles: None = None,
  128. aligned: bool = False,
  129. byteorder: None = None,
  130. ) -> _RecArray[record]: ...
  131. @overload
  132. def fromrecords(
  133. recList: _ArrayLikeVoid_co | tuple[object, ...] | _NestedSequence[tuple[object, ...]],
  134. dtype: None = None,
  135. shape: _ShapeLike | None = None,
  136. *,
  137. formats: DTypeLike,
  138. names: str | Sequence[str] | None = None,
  139. titles: str | Sequence[str] | None = None,
  140. aligned: bool = False,
  141. byteorder: _ByteOrder | None = None,
  142. ) -> _RecArray[record]: ...
  143. # exported in `numpy.rec`
  144. @overload
  145. def fromstring(
  146. datastring: _SupportsBuffer,
  147. dtype: DTypeLike,
  148. shape: _ShapeLike | None = None,
  149. offset: int = 0,
  150. formats: None = None,
  151. names: None = None,
  152. titles: None = None,
  153. aligned: bool = False,
  154. byteorder: None = None,
  155. ) -> _RecArray[record]: ...
  156. @overload
  157. def fromstring(
  158. datastring: _SupportsBuffer,
  159. dtype: None = None,
  160. shape: _ShapeLike | None = None,
  161. offset: int = 0,
  162. *,
  163. formats: DTypeLike,
  164. names: str | Sequence[str] | None = None,
  165. titles: str | Sequence[str] | None = None,
  166. aligned: bool = False,
  167. byteorder: _ByteOrder | None = None,
  168. ) -> _RecArray[record]: ...
  169. # exported in `numpy.rec`
  170. @overload
  171. def fromfile(
  172. fd: StrOrBytesPath | _SupportsReadInto,
  173. dtype: DTypeLike,
  174. shape: _ShapeLike | None = None,
  175. offset: int = 0,
  176. formats: None = None,
  177. names: None = None,
  178. titles: None = None,
  179. aligned: bool = False,
  180. byteorder: None = None,
  181. ) -> _RecArray[Any]: ...
  182. @overload
  183. def fromfile(
  184. fd: StrOrBytesPath | _SupportsReadInto,
  185. dtype: None = None,
  186. shape: _ShapeLike | None = None,
  187. offset: int = 0,
  188. *,
  189. formats: DTypeLike,
  190. names: str | Sequence[str] | None = None,
  191. titles: str | Sequence[str] | None = None,
  192. aligned: bool = False,
  193. byteorder: _ByteOrder | None = None,
  194. ) -> _RecArray[record]: ...
  195. # exported in `numpy.rec`
  196. @overload
  197. def array(
  198. obj: _SCT | NDArray[_SCT],
  199. dtype: None = None,
  200. shape: _ShapeLike | None = None,
  201. offset: int = 0,
  202. strides: tuple[int, ...] | None = None,
  203. formats: None = None,
  204. names: None = None,
  205. titles: None = None,
  206. aligned: bool = False,
  207. byteorder: None = None,
  208. copy: bool = True,
  209. ) -> _RecArray[_SCT]: ...
  210. @overload
  211. def array(
  212. obj: ArrayLike,
  213. dtype: DTypeLike,
  214. shape: _ShapeLike | None = None,
  215. offset: int = 0,
  216. strides: tuple[int, ...] | None = None,
  217. formats: None = None,
  218. names: None = None,
  219. titles: None = None,
  220. aligned: bool = False,
  221. byteorder: None = None,
  222. copy: bool = True,
  223. ) -> _RecArray[Any]: ...
  224. @overload
  225. def array(
  226. obj: ArrayLike,
  227. dtype: None = None,
  228. shape: _ShapeLike | None = None,
  229. offset: int = 0,
  230. strides: tuple[int, ...] | None = None,
  231. *,
  232. formats: DTypeLike,
  233. names: str | Sequence[str] | None = None,
  234. titles: str | Sequence[str] | None = None,
  235. aligned: bool = False,
  236. byteorder: _ByteOrder | None = None,
  237. copy: bool = True,
  238. ) -> _RecArray[record]: ...
  239. @overload
  240. def array(
  241. obj: None,
  242. dtype: DTypeLike,
  243. shape: _ShapeLike,
  244. offset: int = 0,
  245. strides: tuple[int, ...] | None = None,
  246. formats: None = None,
  247. names: None = None,
  248. titles: None = None,
  249. aligned: bool = False,
  250. byteorder: None = None,
  251. copy: bool = True,
  252. ) -> _RecArray[Any]: ...
  253. @overload
  254. def array(
  255. obj: None,
  256. dtype: None = None,
  257. *,
  258. shape: _ShapeLike,
  259. offset: int = 0,
  260. strides: tuple[int, ...] | None = None,
  261. formats: DTypeLike,
  262. names: str | Sequence[str] | None = None,
  263. titles: str | Sequence[str] | None = None,
  264. aligned: bool = False,
  265. byteorder: _ByteOrder | None = None,
  266. copy: bool = True,
  267. ) -> _RecArray[record]: ...
  268. @overload
  269. def array(
  270. obj: _SupportsReadInto,
  271. dtype: DTypeLike,
  272. shape: _ShapeLike | None = None,
  273. offset: int = 0,
  274. strides: tuple[int, ...] | None = None,
  275. formats: None = None,
  276. names: None = None,
  277. titles: None = None,
  278. aligned: bool = False,
  279. byteorder: None = None,
  280. copy: bool = True,
  281. ) -> _RecArray[Any]: ...
  282. @overload
  283. def array(
  284. obj: _SupportsReadInto,
  285. dtype: None = None,
  286. shape: _ShapeLike | None = None,
  287. offset: int = 0,
  288. strides: tuple[int, ...] | None = None,
  289. *,
  290. formats: DTypeLike,
  291. names: str | Sequence[str] | None = None,
  292. titles: str | Sequence[str] | None = None,
  293. aligned: bool = False,
  294. byteorder: _ByteOrder | None = None,
  295. copy: bool = True,
  296. ) -> _RecArray[record]: ...
  297. # exported in `numpy.rec`
  298. def find_duplicate(list: Iterable[_T]) -> list[_T]: ...