conftest.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. from datetime import timedelta
  2. import pytest
  3. import pandas.util._test_decorators as td
  4. from pandas import (
  5. DataFrame,
  6. to_datetime,
  7. )
  8. @pytest.fixture(params=[True, False])
  9. def raw(request):
  10. """raw keyword argument for rolling.apply"""
  11. return request.param
  12. @pytest.fixture(
  13. params=[
  14. "triang",
  15. "blackman",
  16. "hamming",
  17. "bartlett",
  18. "bohman",
  19. "blackmanharris",
  20. "nuttall",
  21. "barthann",
  22. ]
  23. )
  24. def win_types(request):
  25. return request.param
  26. @pytest.fixture(params=["kaiser", "gaussian", "general_gaussian", "exponential"])
  27. def win_types_special(request):
  28. return request.param
  29. @pytest.fixture(
  30. params=[
  31. "sum",
  32. "mean",
  33. "median",
  34. "max",
  35. "min",
  36. "var",
  37. "std",
  38. "kurt",
  39. "skew",
  40. "count",
  41. "sem",
  42. ]
  43. )
  44. def arithmetic_win_operators(request):
  45. return request.param
  46. @pytest.fixture(
  47. params=[
  48. "sum",
  49. "mean",
  50. "median",
  51. "max",
  52. "min",
  53. ]
  54. )
  55. def arithmetic_numba_supported_operators(request):
  56. return request.param
  57. @pytest.fixture(params=["right", "left", "both", "neither"])
  58. def closed(request):
  59. return request.param
  60. @pytest.fixture(params=[True, False])
  61. def center(request):
  62. return request.param
  63. @pytest.fixture(params=[None, 1])
  64. def min_periods(request):
  65. return request.param
  66. @pytest.fixture(params=[True, False])
  67. def parallel(request):
  68. """parallel keyword argument for numba.jit"""
  69. return request.param
  70. # Can parameterize nogil & nopython over True | False, but limiting per
  71. # https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472
  72. @pytest.fixture(params=[False])
  73. def nogil(request):
  74. """nogil keyword argument for numba.jit"""
  75. return request.param
  76. @pytest.fixture(params=[True])
  77. def nopython(request):
  78. """nopython keyword argument for numba.jit"""
  79. return request.param
  80. @pytest.fixture(params=[True, False])
  81. def adjust(request):
  82. """adjust keyword argument for ewm"""
  83. return request.param
  84. @pytest.fixture(params=[True, False])
  85. def ignore_na(request):
  86. """ignore_na keyword argument for ewm"""
  87. return request.param
  88. @pytest.fixture(
  89. params=[pytest.param("numba", marks=td.skip_if_no("numba", "0.46.0")), "cython"]
  90. )
  91. def engine(request):
  92. """engine keyword argument for rolling.apply"""
  93. return request.param
  94. @pytest.fixture(
  95. params=[
  96. pytest.param(("numba", True), marks=td.skip_if_no("numba", "0.46.0")),
  97. ("cython", True),
  98. ("cython", False),
  99. ]
  100. )
  101. def engine_and_raw(request):
  102. """engine and raw keyword arguments for rolling.apply"""
  103. return request.param
  104. @pytest.fixture
  105. def times_frame():
  106. """Frame for testing times argument in EWM groupby."""
  107. return DataFrame(
  108. {
  109. "A": ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"],
  110. "B": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3],
  111. "C": to_datetime(
  112. [
  113. "2020-01-01",
  114. "2020-01-01",
  115. "2020-01-01",
  116. "2020-01-02",
  117. "2020-01-10",
  118. "2020-01-22",
  119. "2020-01-03",
  120. "2020-01-23",
  121. "2020-01-23",
  122. "2020-01-04",
  123. ]
  124. ),
  125. }
  126. )
  127. @pytest.fixture(params=["1 day", timedelta(days=1)])
  128. def halflife_with_times(request):
  129. """Halflife argument for EWM when times is specified."""
  130. return request.param
  131. @pytest.fixture(
  132. params=[
  133. "object",
  134. "category",
  135. "int8",
  136. "int16",
  137. "int32",
  138. "int64",
  139. "uint8",
  140. "uint16",
  141. "uint32",
  142. "uint64",
  143. "float16",
  144. "float32",
  145. "float64",
  146. "m8[ns]",
  147. "M8[ns]",
  148. pytest.param(
  149. "datetime64[ns, UTC]",
  150. marks=pytest.mark.skip(
  151. "direct creation of extension dtype datetime64[ns, UTC] "
  152. "is not supported ATM"
  153. ),
  154. ),
  155. ]
  156. )
  157. def dtypes(request):
  158. """Dtypes for window tests"""
  159. return request.param
  160. @pytest.fixture(
  161. params=[
  162. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 0]),
  163. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 1]),
  164. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", "C"]),
  165. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1.0, 0]),
  166. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0.0, 1]),
  167. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", 1]),
  168. DataFrame([[2.0, 4.0], [1.0, 2.0], [5.0, 2.0], [8.0, 1.0]], columns=[1, 0.0]),
  169. DataFrame([[2, 4.0], [1, 2.0], [5, 2.0], [8, 1.0]], columns=[0, 1.0]),
  170. DataFrame([[2, 4], [1, 2], [5, 2], [8, 1.0]], columns=[1.0, "X"]),
  171. ]
  172. )
  173. def pairwise_frames(request):
  174. """Pairwise frames test_pairwise"""
  175. return request.param
  176. @pytest.fixture
  177. def pairwise_target_frame():
  178. """Pairwise target frame for test_pairwise"""
  179. return DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0, 1])
  180. @pytest.fixture
  181. def pairwise_other_frame():
  182. """Pairwise other frame for test_pairwise"""
  183. return DataFrame(
  184. [[None, 1, 1], [None, 1, 2], [None, 3, 2], [None, 8, 1]],
  185. columns=["Y", "Z", "X"],
  186. )