arrayprint.pyi 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. from collections.abc import Callable
  2. # Using a private class is by no means ideal, but it is simply a consequence
  3. # of a `contextlib.context` returning an instance of aforementioned class
  4. from contextlib import _GeneratorContextManager
  5. from typing import Any, Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only
  6. from typing_extensions import deprecated
  7. import numpy as np
  8. from numpy._globals import _NoValueType
  9. from numpy._typing import NDArray, _CharLike_co, _FloatLike_co
  10. __all__ = [
  11. "array2string",
  12. "array_repr",
  13. "array_str",
  14. "format_float_positional",
  15. "format_float_scientific",
  16. "get_printoptions",
  17. "printoptions",
  18. "set_printoptions",
  19. ]
  20. ###
  21. _FloatMode: TypeAlias = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
  22. _LegacyNoStyle: TypeAlias = Literal["1.21", "1.25", "2.1", False]
  23. _Legacy: TypeAlias = Literal["1.13", _LegacyNoStyle]
  24. _Sign: TypeAlias = Literal["-", "+", " "]
  25. _Trim: TypeAlias = Literal["k", ".", "0", "-"]
  26. _ReprFunc: TypeAlias = Callable[[NDArray[Any]], str]
  27. @type_check_only
  28. class _FormatDict(TypedDict, total=False):
  29. bool: Callable[[np.bool], str]
  30. int: Callable[[np.integer], str]
  31. timedelta: Callable[[np.timedelta64], str]
  32. datetime: Callable[[np.datetime64], str]
  33. float: Callable[[np.floating], str]
  34. longfloat: Callable[[np.longdouble], str]
  35. complexfloat: Callable[[np.complexfloating], str]
  36. longcomplexfloat: Callable[[np.clongdouble], str]
  37. void: Callable[[np.void], str]
  38. numpystr: Callable[[_CharLike_co], str]
  39. object: Callable[[object], str]
  40. all: Callable[[object], str]
  41. int_kind: Callable[[np.integer], str]
  42. float_kind: Callable[[np.floating], str]
  43. complex_kind: Callable[[np.complexfloating], str]
  44. str_kind: Callable[[_CharLike_co], str]
  45. @type_check_only
  46. class _FormatOptions(TypedDict):
  47. precision: int
  48. threshold: int
  49. edgeitems: int
  50. linewidth: int
  51. suppress: bool
  52. nanstr: str
  53. infstr: str
  54. formatter: _FormatDict | None
  55. sign: _Sign
  56. floatmode: _FloatMode
  57. legacy: _Legacy
  58. ###
  59. __docformat__: Final = "restructuredtext" # undocumented
  60. def set_printoptions(
  61. precision: None | SupportsIndex = ...,
  62. threshold: None | int = ...,
  63. edgeitems: None | int = ...,
  64. linewidth: None | int = ...,
  65. suppress: None | bool = ...,
  66. nanstr: None | str = ...,
  67. infstr: None | str = ...,
  68. formatter: None | _FormatDict = ...,
  69. sign: _Sign | None = None,
  70. floatmode: _FloatMode | None = None,
  71. *,
  72. legacy: _Legacy | None = None,
  73. override_repr: _ReprFunc | None = None,
  74. ) -> None: ...
  75. def get_printoptions() -> _FormatOptions: ...
  76. # public numpy export
  77. @overload # no style
  78. def array2string(
  79. a: NDArray[Any],
  80. max_line_width: int | None = None,
  81. precision: SupportsIndex | None = None,
  82. suppress_small: bool | None = None,
  83. separator: str = " ",
  84. prefix: str = "",
  85. style: _NoValueType = ...,
  86. formatter: _FormatDict | None = None,
  87. threshold: int | None = None,
  88. edgeitems: int | None = None,
  89. sign: _Sign | None = None,
  90. floatmode: _FloatMode | None = None,
  91. suffix: str = "",
  92. *,
  93. legacy: _Legacy | None = None,
  94. ) -> str: ...
  95. @overload # style=<given> (positional), legacy="1.13"
  96. def array2string(
  97. a: NDArray[Any],
  98. max_line_width: int | None,
  99. precision: SupportsIndex | None,
  100. suppress_small: bool | None,
  101. separator: str,
  102. prefix: str,
  103. style: _ReprFunc,
  104. formatter: _FormatDict | None = None,
  105. threshold: int | None = None,
  106. edgeitems: int | None = None,
  107. sign: _Sign | None = None,
  108. floatmode: _FloatMode | None = None,
  109. suffix: str = "",
  110. *,
  111. legacy: Literal["1.13"],
  112. ) -> str: ...
  113. @overload # style=<given> (keyword), legacy="1.13"
  114. def array2string(
  115. a: NDArray[Any],
  116. max_line_width: int | None = None,
  117. precision: SupportsIndex | None = None,
  118. suppress_small: bool | None = None,
  119. separator: str = " ",
  120. prefix: str = "",
  121. *,
  122. style: _ReprFunc,
  123. formatter: _FormatDict | None = None,
  124. threshold: int | None = None,
  125. edgeitems: int | None = None,
  126. sign: _Sign | None = None,
  127. floatmode: _FloatMode | None = None,
  128. suffix: str = "",
  129. legacy: Literal["1.13"],
  130. ) -> str: ...
  131. @overload # style=<given> (positional), legacy!="1.13"
  132. @deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
  133. def array2string(
  134. a: NDArray[Any],
  135. max_line_width: int | None,
  136. precision: SupportsIndex | None,
  137. suppress_small: bool | None,
  138. separator: str,
  139. prefix: str,
  140. style: _ReprFunc,
  141. formatter: _FormatDict | None = None,
  142. threshold: int | None = None,
  143. edgeitems: int | None = None,
  144. sign: _Sign | None = None,
  145. floatmode: _FloatMode | None = None,
  146. suffix: str = "",
  147. *,
  148. legacy: _LegacyNoStyle | None = None,
  149. ) -> str: ...
  150. @overload # style=<given> (keyword), legacy="1.13"
  151. @deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
  152. def array2string(
  153. a: NDArray[Any],
  154. max_line_width: int | None = None,
  155. precision: SupportsIndex | None = None,
  156. suppress_small: bool | None = None,
  157. separator: str = " ",
  158. prefix: str = "",
  159. *,
  160. style: _ReprFunc,
  161. formatter: _FormatDict | None = None,
  162. threshold: int | None = None,
  163. edgeitems: int | None = None,
  164. sign: _Sign | None = None,
  165. floatmode: _FloatMode | None = None,
  166. suffix: str = "",
  167. legacy: _LegacyNoStyle | None = None,
  168. ) -> str: ...
  169. def format_float_scientific(
  170. x: _FloatLike_co,
  171. precision: None | int = ...,
  172. unique: bool = ...,
  173. trim: _Trim = "k",
  174. sign: bool = ...,
  175. pad_left: None | int = ...,
  176. exp_digits: None | int = ...,
  177. min_digits: None | int = ...,
  178. ) -> str: ...
  179. def format_float_positional(
  180. x: _FloatLike_co,
  181. precision: None | int = ...,
  182. unique: bool = ...,
  183. fractional: bool = ...,
  184. trim: _Trim = "k",
  185. sign: bool = ...,
  186. pad_left: None | int = ...,
  187. pad_right: None | int = ...,
  188. min_digits: None | int = ...,
  189. ) -> str: ...
  190. def array_repr(
  191. arr: NDArray[Any],
  192. max_line_width: None | int = ...,
  193. precision: None | SupportsIndex = ...,
  194. suppress_small: None | bool = ...,
  195. ) -> str: ...
  196. def array_str(
  197. a: NDArray[Any],
  198. max_line_width: None | int = ...,
  199. precision: None | SupportsIndex = ...,
  200. suppress_small: None | bool = ...,
  201. ) -> str: ...
  202. def printoptions(
  203. precision: None | SupportsIndex = ...,
  204. threshold: None | int = ...,
  205. edgeitems: None | int = ...,
  206. linewidth: None | int = ...,
  207. suppress: None | bool = ...,
  208. nanstr: None | str = ...,
  209. infstr: None | str = ...,
  210. formatter: None | _FormatDict = ...,
  211. sign: None | _Sign = None,
  212. floatmode: _FloatMode | None = None,
  213. *,
  214. legacy: _Legacy | None = None,
  215. override_repr: _ReprFunc | None = None,
  216. ) -> _GeneratorContextManager[_FormatOptions]: ...