conftest.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import numpy as np
  2. import pytest
  3. from pandas import DataFrame
  4. import pandas._testing as tm
  5. from pandas.core.groupby.base import (
  6. reduction_kernels,
  7. transformation_kernels,
  8. )
  9. @pytest.fixture(params=[True, False])
  10. def sort(request):
  11. return request.param
  12. @pytest.fixture(params=[True, False])
  13. def as_index(request):
  14. return request.param
  15. @pytest.fixture(params=[True, False])
  16. def dropna(request):
  17. return request.param
  18. @pytest.fixture(params=[True, False])
  19. def observed(request):
  20. return request.param
  21. @pytest.fixture
  22. def mframe(multiindex_dataframe_random_data):
  23. return multiindex_dataframe_random_data
  24. @pytest.fixture
  25. def df():
  26. return DataFrame(
  27. {
  28. "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
  29. "B": ["one", "one", "two", "three", "two", "two", "one", "three"],
  30. "C": np.random.randn(8),
  31. "D": np.random.randn(8),
  32. }
  33. )
  34. @pytest.fixture
  35. def ts():
  36. return tm.makeTimeSeries()
  37. @pytest.fixture
  38. def tsd():
  39. return tm.getTimeSeriesData()
  40. @pytest.fixture
  41. def tsframe(tsd):
  42. return DataFrame(tsd)
  43. @pytest.fixture
  44. def df_mixed_floats():
  45. return DataFrame(
  46. {
  47. "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
  48. "B": ["one", "one", "two", "three", "two", "two", "one", "three"],
  49. "C": np.random.randn(8),
  50. "D": np.array(np.random.randn(8), dtype="float32"),
  51. }
  52. )
  53. @pytest.fixture
  54. def three_group():
  55. return DataFrame(
  56. {
  57. "A": [
  58. "foo",
  59. "foo",
  60. "foo",
  61. "foo",
  62. "bar",
  63. "bar",
  64. "bar",
  65. "bar",
  66. "foo",
  67. "foo",
  68. "foo",
  69. ],
  70. "B": [
  71. "one",
  72. "one",
  73. "one",
  74. "two",
  75. "one",
  76. "one",
  77. "one",
  78. "two",
  79. "two",
  80. "two",
  81. "one",
  82. ],
  83. "C": [
  84. "dull",
  85. "dull",
  86. "shiny",
  87. "dull",
  88. "dull",
  89. "shiny",
  90. "shiny",
  91. "dull",
  92. "shiny",
  93. "shiny",
  94. "shiny",
  95. ],
  96. "D": np.random.randn(11),
  97. "E": np.random.randn(11),
  98. "F": np.random.randn(11),
  99. }
  100. )
  101. @pytest.fixture()
  102. def slice_test_df():
  103. data = [
  104. [0, "a", "a0_at_0"],
  105. [1, "b", "b0_at_1"],
  106. [2, "a", "a1_at_2"],
  107. [3, "b", "b1_at_3"],
  108. [4, "c", "c0_at_4"],
  109. [5, "a", "a2_at_5"],
  110. [6, "a", "a3_at_6"],
  111. [7, "a", "a4_at_7"],
  112. ]
  113. df = DataFrame(data, columns=["Index", "Group", "Value"])
  114. return df.set_index("Index")
  115. @pytest.fixture()
  116. def slice_test_grouped(slice_test_df):
  117. return slice_test_df.groupby("Group", as_index=False)
  118. @pytest.fixture(params=sorted(reduction_kernels))
  119. def reduction_func(request):
  120. """
  121. yields the string names of all groupby reduction functions, one at a time.
  122. """
  123. return request.param
  124. @pytest.fixture(params=sorted(transformation_kernels))
  125. def transformation_func(request):
  126. """yields the string names of all groupby transformation functions."""
  127. return request.param
  128. @pytest.fixture(params=sorted(reduction_kernels) + sorted(transformation_kernels))
  129. def groupby_func(request):
  130. """yields both aggregation and transformation functions."""
  131. return request.param
  132. @pytest.fixture(params=[True, False])
  133. def parallel(request):
  134. """parallel keyword argument for numba.jit"""
  135. return request.param
  136. # Can parameterize nogil & nopython over True | False, but limiting per
  137. # https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472
  138. @pytest.fixture(params=[False])
  139. def nogil(request):
  140. """nogil keyword argument for numba.jit"""
  141. return request.param
  142. @pytest.fixture(params=[True])
  143. def nopython(request):
  144. """nopython keyword argument for numba.jit"""
  145. return request.param
  146. @pytest.fixture(
  147. params=[
  148. ("mean", {}),
  149. ("var", {"ddof": 1}),
  150. ("var", {"ddof": 0}),
  151. ("std", {"ddof": 1}),
  152. ("std", {"ddof": 0}),
  153. ("sum", {}),
  154. ("min", {}),
  155. ("max", {}),
  156. ],
  157. ids=["mean", "var_1", "var_0", "std_1", "std_0", "sum", "min", "max"],
  158. )
  159. def numba_supported_reductions(request):
  160. """reductions supported with engine='numba'"""
  161. return request.param