arrayprint.pyi 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 (
  6. Any,
  7. Final,
  8. Literal,
  9. SupportsIndex,
  10. TypeAlias,
  11. TypedDict,
  12. type_check_only,
  13. )
  14. import numpy as np
  15. from numpy._typing import NDArray, _CharLike_co, _FloatLike_co
  16. __all__ = [
  17. "array2string",
  18. "array_repr",
  19. "array_str",
  20. "format_float_positional",
  21. "format_float_scientific",
  22. "get_printoptions",
  23. "printoptions",
  24. "set_printoptions",
  25. ]
  26. ###
  27. _FloatMode: TypeAlias = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
  28. _LegacyNoStyle: TypeAlias = Literal["1.21", "1.25", "2.1", False]
  29. _Legacy: TypeAlias = Literal["1.13", _LegacyNoStyle]
  30. _Sign: TypeAlias = Literal["-", "+", " "]
  31. _Trim: TypeAlias = Literal["k", ".", "0", "-"]
  32. _ReprFunc: TypeAlias = Callable[[NDArray[Any]], str]
  33. @type_check_only
  34. class _FormatDict(TypedDict, total=False):
  35. bool: Callable[[np.bool], str]
  36. int: Callable[[np.integer], str]
  37. timedelta: Callable[[np.timedelta64], str]
  38. datetime: Callable[[np.datetime64], str]
  39. float: Callable[[np.floating], str]
  40. longfloat: Callable[[np.longdouble], str]
  41. complexfloat: Callable[[np.complexfloating], str]
  42. longcomplexfloat: Callable[[np.clongdouble], str]
  43. void: Callable[[np.void], str]
  44. numpystr: Callable[[_CharLike_co], str]
  45. object: Callable[[object], str]
  46. all: Callable[[object], str]
  47. int_kind: Callable[[np.integer], str]
  48. float_kind: Callable[[np.floating], str]
  49. complex_kind: Callable[[np.complexfloating], str]
  50. str_kind: Callable[[_CharLike_co], str]
  51. @type_check_only
  52. class _FormatOptions(TypedDict):
  53. precision: int
  54. threshold: int
  55. edgeitems: int
  56. linewidth: int
  57. suppress: bool
  58. nanstr: str
  59. infstr: str
  60. formatter: _FormatDict | None
  61. sign: _Sign
  62. floatmode: _FloatMode
  63. legacy: _Legacy
  64. ###
  65. __docformat__: Final = "restructuredtext" # undocumented
  66. def set_printoptions(
  67. precision: SupportsIndex | None = None,
  68. threshold: int | None = None,
  69. edgeitems: int | None = None,
  70. linewidth: int | None = None,
  71. suppress: bool | None = None,
  72. nanstr: str | None = None,
  73. infstr: str | None = None,
  74. formatter: _FormatDict | None = None,
  75. sign: _Sign | None = None,
  76. floatmode: _FloatMode | None = None,
  77. *,
  78. legacy: _Legacy | None = None,
  79. override_repr: _ReprFunc | None = None,
  80. ) -> None: ...
  81. def get_printoptions() -> _FormatOptions: ...
  82. # public numpy export
  83. def array2string(
  84. a: NDArray[Any],
  85. max_line_width: int | None = None,
  86. precision: SupportsIndex | None = None,
  87. suppress_small: bool | None = None,
  88. separator: str = " ",
  89. prefix: str = "",
  90. *,
  91. formatter: _FormatDict | None = None,
  92. threshold: int | None = None,
  93. edgeitems: int | None = None,
  94. sign: _Sign | None = None,
  95. floatmode: _FloatMode | None = None,
  96. suffix: str = "",
  97. legacy: _Legacy | None = None,
  98. ) -> str: ...
  99. def format_float_scientific(
  100. x: _FloatLike_co,
  101. precision: int | None = None,
  102. unique: bool = True,
  103. trim: _Trim = "k",
  104. sign: bool = False,
  105. pad_left: int | None = None,
  106. exp_digits: int | None = None,
  107. min_digits: int | None = None,
  108. ) -> str: ...
  109. def format_float_positional(
  110. x: _FloatLike_co,
  111. precision: int | None = None,
  112. unique: bool = True,
  113. fractional: bool = True,
  114. trim: _Trim = "k",
  115. sign: bool = False,
  116. pad_left: int | None = None,
  117. pad_right: int | None = None,
  118. min_digits: int | None = None,
  119. ) -> str: ...
  120. def array_repr(
  121. arr: NDArray[Any],
  122. max_line_width: int | None = None,
  123. precision: SupportsIndex | None = None,
  124. suppress_small: bool | None = None,
  125. ) -> str: ...
  126. def array_str(
  127. a: NDArray[Any],
  128. max_line_width: int | None = None,
  129. precision: SupportsIndex | None = None,
  130. suppress_small: bool | None = None,
  131. ) -> str: ...
  132. def printoptions(
  133. precision: SupportsIndex | None = ...,
  134. threshold: int | None = ...,
  135. edgeitems: int | None = ...,
  136. linewidth: int | None = ...,
  137. suppress: bool | None = ...,
  138. nanstr: str | None = ...,
  139. infstr: str | None = ...,
  140. formatter: _FormatDict | None = ...,
  141. sign: _Sign | None = None,
  142. floatmode: _FloatMode | None = None,
  143. *,
  144. legacy: _Legacy | None = None,
  145. override_repr: _ReprFunc | None = None,
  146. ) -> _GeneratorContextManager[_FormatOptions]: ...