conftest.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import numpy as np
  2. import pytest
  3. from pandas import (
  4. DataFrame,
  5. MultiIndex,
  6. )
  7. import pandas._testing as tm
  8. from pandas.core.groupby.base import (
  9. reduction_kernels,
  10. transformation_kernels,
  11. )
  12. @pytest.fixture(params=[True, False])
  13. def as_index(request):
  14. return request.param
  15. @pytest.fixture
  16. def mframe():
  17. index = MultiIndex(
  18. levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
  19. codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
  20. names=["first", "second"],
  21. )
  22. return DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"])
  23. @pytest.fixture
  24. def df():
  25. return DataFrame(
  26. {
  27. "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
  28. "B": ["one", "one", "two", "three", "two", "two", "one", "three"],
  29. "C": np.random.randn(8),
  30. "D": np.random.randn(8),
  31. }
  32. )
  33. @pytest.fixture
  34. def ts():
  35. return tm.makeTimeSeries()
  36. @pytest.fixture
  37. def tsd():
  38. return tm.getTimeSeriesData()
  39. @pytest.fixture
  40. def tsframe(tsd):
  41. return DataFrame(tsd)
  42. @pytest.fixture
  43. def df_mixed_floats():
  44. return DataFrame(
  45. {
  46. "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
  47. "B": ["one", "one", "two", "three", "two", "two", "one", "three"],
  48. "C": np.random.randn(8),
  49. "D": np.array(np.random.randn(8), dtype="float32"),
  50. }
  51. )
  52. @pytest.fixture
  53. def three_group():
  54. return DataFrame(
  55. {
  56. "A": [
  57. "foo",
  58. "foo",
  59. "foo",
  60. "foo",
  61. "bar",
  62. "bar",
  63. "bar",
  64. "bar",
  65. "foo",
  66. "foo",
  67. "foo",
  68. ],
  69. "B": [
  70. "one",
  71. "one",
  72. "one",
  73. "two",
  74. "one",
  75. "one",
  76. "one",
  77. "two",
  78. "two",
  79. "two",
  80. "one",
  81. ],
  82. "C": [
  83. "dull",
  84. "dull",
  85. "shiny",
  86. "dull",
  87. "dull",
  88. "shiny",
  89. "shiny",
  90. "dull",
  91. "shiny",
  92. "shiny",
  93. "shiny",
  94. ],
  95. "D": np.random.randn(11),
  96. "E": np.random.randn(11),
  97. "F": np.random.randn(11),
  98. }
  99. )
  100. @pytest.fixture(params=sorted(reduction_kernels))
  101. def reduction_func(request):
  102. """
  103. yields the string names of all groupby reduction functions, one at a time.
  104. """
  105. return request.param
  106. @pytest.fixture(params=sorted(transformation_kernels))
  107. def transformation_func(request):
  108. """yields the string names of all groupby transformation functions."""
  109. return request.param
  110. @pytest.fixture(params=sorted(reduction_kernels) + sorted(transformation_kernels))
  111. def groupby_func(request):
  112. """yields both aggregation and transformation functions."""
  113. return request.param
  114. @pytest.fixture(params=[True, False])
  115. def parallel(request):
  116. """parallel keyword argument for numba.jit"""
  117. return request.param
  118. # Can parameterize nogil & nopython over True | False, but limiting per
  119. # https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472
  120. @pytest.fixture(params=[False])
  121. def nogil(request):
  122. """nogil keyword argument for numba.jit"""
  123. return request.param
  124. @pytest.fixture(params=[True])
  125. def nopython(request):
  126. """nopython keyword argument for numba.jit"""
  127. return request.param