comparisons.pyi 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import fractions
  2. import decimal
  3. from typing import Any
  4. import numpy as np
  5. import numpy.typing as npt
  6. from typing_extensions import assert_type
  7. c16 = np.complex128()
  8. f8 = np.float64()
  9. i8 = np.int64()
  10. u8 = np.uint64()
  11. c8 = np.complex64()
  12. f4 = np.float32()
  13. i4 = np.int32()
  14. u4 = np.uint32()
  15. dt = np.datetime64(0, "D")
  16. td = np.timedelta64(0, "D")
  17. b_ = np.bool()
  18. b = bool()
  19. c = complex()
  20. f = float()
  21. i = int()
  22. AR = np.array([0], dtype=np.int64)
  23. AR.setflags(write=False)
  24. SEQ = (0, 1, 2, 3, 4)
  25. # object-like comparisons
  26. assert_type(i8 > fractions.Fraction(1, 5), np.bool)
  27. assert_type(i8 > [fractions.Fraction(1, 5)], npt.NDArray[np.bool])
  28. assert_type(i8 > decimal.Decimal("1.5"), np.bool)
  29. assert_type(i8 > [decimal.Decimal("1.5")], npt.NDArray[np.bool])
  30. # Time structures
  31. assert_type(dt > dt, np.bool)
  32. assert_type(td > td, np.bool)
  33. assert_type(td > i, np.bool)
  34. assert_type(td > i4, np.bool)
  35. assert_type(td > i8, np.bool)
  36. assert_type(td > AR, npt.NDArray[np.bool])
  37. assert_type(td > SEQ, npt.NDArray[np.bool])
  38. assert_type(AR > SEQ, npt.NDArray[np.bool])
  39. assert_type(AR > td, npt.NDArray[np.bool])
  40. assert_type(SEQ > td, npt.NDArray[np.bool])
  41. assert_type(SEQ > AR, npt.NDArray[np.bool])
  42. # boolean
  43. assert_type(b_ > b, np.bool)
  44. assert_type(b_ > b_, np.bool)
  45. assert_type(b_ > i, np.bool)
  46. assert_type(b_ > i8, np.bool)
  47. assert_type(b_ > i4, np.bool)
  48. assert_type(b_ > u8, np.bool)
  49. assert_type(b_ > u4, np.bool)
  50. assert_type(b_ > f, np.bool)
  51. assert_type(b_ > f8, np.bool)
  52. assert_type(b_ > f4, np.bool)
  53. assert_type(b_ > c, np.bool)
  54. assert_type(b_ > c16, np.bool)
  55. assert_type(b_ > c8, np.bool)
  56. assert_type(b_ > AR, npt.NDArray[np.bool])
  57. assert_type(b_ > SEQ, npt.NDArray[np.bool])
  58. # Complex
  59. assert_type(c16 > c16, np.bool)
  60. assert_type(c16 > f8, np.bool)
  61. assert_type(c16 > i8, np.bool)
  62. assert_type(c16 > c8, np.bool)
  63. assert_type(c16 > f4, np.bool)
  64. assert_type(c16 > i4, np.bool)
  65. assert_type(c16 > b_, np.bool)
  66. assert_type(c16 > b, np.bool)
  67. assert_type(c16 > c, np.bool)
  68. assert_type(c16 > f, np.bool)
  69. assert_type(c16 > i, np.bool)
  70. assert_type(c16 > AR, npt.NDArray[np.bool])
  71. assert_type(c16 > SEQ, npt.NDArray[np.bool])
  72. assert_type(c16 > c16, np.bool)
  73. assert_type(f8 > c16, np.bool)
  74. assert_type(i8 > c16, np.bool)
  75. assert_type(c8 > c16, np.bool)
  76. assert_type(f4 > c16, np.bool)
  77. assert_type(i4 > c16, np.bool)
  78. assert_type(b_ > c16, np.bool)
  79. assert_type(b > c16, np.bool)
  80. assert_type(c > c16, np.bool)
  81. assert_type(f > c16, np.bool)
  82. assert_type(i > c16, np.bool)
  83. assert_type(AR > c16, npt.NDArray[np.bool])
  84. assert_type(SEQ > c16, npt.NDArray[np.bool])
  85. assert_type(c8 > c16, np.bool)
  86. assert_type(c8 > f8, np.bool)
  87. assert_type(c8 > i8, np.bool)
  88. assert_type(c8 > c8, np.bool)
  89. assert_type(c8 > f4, np.bool)
  90. assert_type(c8 > i4, np.bool)
  91. assert_type(c8 > b_, np.bool)
  92. assert_type(c8 > b, np.bool)
  93. assert_type(c8 > c, np.bool)
  94. assert_type(c8 > f, np.bool)
  95. assert_type(c8 > i, np.bool)
  96. assert_type(c8 > AR, npt.NDArray[np.bool])
  97. assert_type(c8 > SEQ, npt.NDArray[np.bool])
  98. assert_type(c16 > c8, np.bool)
  99. assert_type(f8 > c8, np.bool)
  100. assert_type(i8 > c8, np.bool)
  101. assert_type(c8 > c8, np.bool)
  102. assert_type(f4 > c8, np.bool)
  103. assert_type(i4 > c8, np.bool)
  104. assert_type(b_ > c8, np.bool)
  105. assert_type(b > c8, np.bool)
  106. assert_type(c > c8, np.bool)
  107. assert_type(f > c8, np.bool)
  108. assert_type(i > c8, np.bool)
  109. assert_type(AR > c8, npt.NDArray[np.bool])
  110. assert_type(SEQ > c8, npt.NDArray[np.bool])
  111. # Float
  112. assert_type(f8 > f8, np.bool)
  113. assert_type(f8 > i8, np.bool)
  114. assert_type(f8 > f4, np.bool)
  115. assert_type(f8 > i4, np.bool)
  116. assert_type(f8 > b_, np.bool)
  117. assert_type(f8 > b, np.bool)
  118. assert_type(f8 > c, np.bool)
  119. assert_type(f8 > f, np.bool)
  120. assert_type(f8 > i, np.bool)
  121. assert_type(f8 > AR, npt.NDArray[np.bool])
  122. assert_type(f8 > SEQ, npt.NDArray[np.bool])
  123. assert_type(f8 > f8, np.bool)
  124. assert_type(i8 > f8, np.bool)
  125. assert_type(f4 > f8, np.bool)
  126. assert_type(i4 > f8, np.bool)
  127. assert_type(b_ > f8, np.bool)
  128. assert_type(b > f8, np.bool)
  129. assert_type(c > f8, np.bool)
  130. assert_type(f > f8, np.bool)
  131. assert_type(i > f8, np.bool)
  132. assert_type(AR > f8, npt.NDArray[np.bool])
  133. assert_type(SEQ > f8, npt.NDArray[np.bool])
  134. assert_type(f4 > f8, np.bool)
  135. assert_type(f4 > i8, np.bool)
  136. assert_type(f4 > f4, np.bool)
  137. assert_type(f4 > i4, np.bool)
  138. assert_type(f4 > b_, np.bool)
  139. assert_type(f4 > b, np.bool)
  140. assert_type(f4 > c, np.bool)
  141. assert_type(f4 > f, np.bool)
  142. assert_type(f4 > i, np.bool)
  143. assert_type(f4 > AR, npt.NDArray[np.bool])
  144. assert_type(f4 > SEQ, npt.NDArray[np.bool])
  145. assert_type(f8 > f4, np.bool)
  146. assert_type(i8 > f4, np.bool)
  147. assert_type(f4 > f4, np.bool)
  148. assert_type(i4 > f4, np.bool)
  149. assert_type(b_ > f4, np.bool)
  150. assert_type(b > f4, np.bool)
  151. assert_type(c > f4, np.bool)
  152. assert_type(f > f4, np.bool)
  153. assert_type(i > f4, np.bool)
  154. assert_type(AR > f4, npt.NDArray[np.bool])
  155. assert_type(SEQ > f4, npt.NDArray[np.bool])
  156. # Int
  157. assert_type(i8 > i8, np.bool)
  158. assert_type(i8 > u8, np.bool)
  159. assert_type(i8 > i4, np.bool)
  160. assert_type(i8 > u4, np.bool)
  161. assert_type(i8 > b_, np.bool)
  162. assert_type(i8 > b, np.bool)
  163. assert_type(i8 > c, np.bool)
  164. assert_type(i8 > f, np.bool)
  165. assert_type(i8 > i, np.bool)
  166. assert_type(i8 > AR, npt.NDArray[np.bool])
  167. assert_type(i8 > SEQ, npt.NDArray[np.bool])
  168. assert_type(u8 > u8, np.bool)
  169. assert_type(u8 > i4, np.bool)
  170. assert_type(u8 > u4, np.bool)
  171. assert_type(u8 > b_, np.bool)
  172. assert_type(u8 > b, np.bool)
  173. assert_type(u8 > c, np.bool)
  174. assert_type(u8 > f, np.bool)
  175. assert_type(u8 > i, np.bool)
  176. assert_type(u8 > AR, npt.NDArray[np.bool])
  177. assert_type(u8 > SEQ, npt.NDArray[np.bool])
  178. assert_type(i8 > i8, np.bool)
  179. assert_type(u8 > i8, np.bool)
  180. assert_type(i4 > i8, np.bool)
  181. assert_type(u4 > i8, np.bool)
  182. assert_type(b_ > i8, np.bool)
  183. assert_type(b > i8, np.bool)
  184. assert_type(c > i8, np.bool)
  185. assert_type(f > i8, np.bool)
  186. assert_type(i > i8, np.bool)
  187. assert_type(AR > i8, npt.NDArray[np.bool])
  188. assert_type(SEQ > i8, npt.NDArray[np.bool])
  189. assert_type(u8 > u8, np.bool)
  190. assert_type(i4 > u8, np.bool)
  191. assert_type(u4 > u8, np.bool)
  192. assert_type(b_ > u8, np.bool)
  193. assert_type(b > u8, np.bool)
  194. assert_type(c > u8, np.bool)
  195. assert_type(f > u8, np.bool)
  196. assert_type(i > u8, np.bool)
  197. assert_type(AR > u8, npt.NDArray[np.bool])
  198. assert_type(SEQ > u8, npt.NDArray[np.bool])
  199. assert_type(i4 > i8, np.bool)
  200. assert_type(i4 > i4, np.bool)
  201. assert_type(i4 > i, np.bool)
  202. assert_type(i4 > b_, np.bool)
  203. assert_type(i4 > b, np.bool)
  204. assert_type(i4 > AR, npt.NDArray[np.bool])
  205. assert_type(i4 > SEQ, npt.NDArray[np.bool])
  206. assert_type(u4 > i8, np.bool)
  207. assert_type(u4 > i4, np.bool)
  208. assert_type(u4 > u8, np.bool)
  209. assert_type(u4 > u4, np.bool)
  210. assert_type(u4 > i, np.bool)
  211. assert_type(u4 > b_, np.bool)
  212. assert_type(u4 > b, np.bool)
  213. assert_type(u4 > AR, npt.NDArray[np.bool])
  214. assert_type(u4 > SEQ, npt.NDArray[np.bool])
  215. assert_type(i8 > i4, np.bool)
  216. assert_type(i4 > i4, np.bool)
  217. assert_type(i > i4, np.bool)
  218. assert_type(b_ > i4, np.bool)
  219. assert_type(b > i4, np.bool)
  220. assert_type(AR > i4, npt.NDArray[np.bool])
  221. assert_type(SEQ > i4, npt.NDArray[np.bool])
  222. assert_type(i8 > u4, np.bool)
  223. assert_type(i4 > u4, np.bool)
  224. assert_type(u8 > u4, np.bool)
  225. assert_type(u4 > u4, np.bool)
  226. assert_type(b_ > u4, np.bool)
  227. assert_type(b > u4, np.bool)
  228. assert_type(i > u4, np.bool)
  229. assert_type(AR > u4, npt.NDArray[np.bool])
  230. assert_type(SEQ > u4, npt.NDArray[np.bool])