conftest.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. from datetime import datetime
  2. import numpy as np
  3. import pytest
  4. from pandas import (
  5. DataFrame,
  6. Series,
  7. )
  8. # The various methods we support
  9. downsample_methods = [
  10. "min",
  11. "max",
  12. "first",
  13. "last",
  14. "sum",
  15. "mean",
  16. "sem",
  17. "median",
  18. "prod",
  19. "var",
  20. "std",
  21. "ohlc",
  22. "quantile",
  23. ]
  24. upsample_methods = ["count", "size"]
  25. series_methods = ["nunique"]
  26. resample_methods = downsample_methods + upsample_methods + series_methods
  27. @pytest.fixture(params=downsample_methods)
  28. def downsample_method(request):
  29. """Fixture for parametrization of Grouper downsample methods."""
  30. return request.param
  31. @pytest.fixture(params=resample_methods)
  32. def resample_method(request):
  33. """Fixture for parametrization of Grouper resample methods."""
  34. return request.param
  35. @pytest.fixture
  36. def _index_start():
  37. """Fixture for parametrization of index, series and frame."""
  38. return datetime(2005, 1, 1)
  39. @pytest.fixture
  40. def _index_end():
  41. """Fixture for parametrization of index, series and frame."""
  42. return datetime(2005, 1, 10)
  43. @pytest.fixture
  44. def _index_freq():
  45. """Fixture for parametrization of index, series and frame."""
  46. return "D"
  47. @pytest.fixture
  48. def _index_name():
  49. """Fixture for parametrization of index, series and frame."""
  50. return None
  51. @pytest.fixture
  52. def index(_index_factory, _index_start, _index_end, _index_freq, _index_name):
  53. """
  54. Fixture for parametrization of date_range, period_range and
  55. timedelta_range indexes
  56. """
  57. return _index_factory(_index_start, _index_end, freq=_index_freq, name=_index_name)
  58. @pytest.fixture
  59. def _static_values(index):
  60. """
  61. Fixture for parametrization of values used in parametrization of
  62. Series and DataFrames with date_range, period_range and
  63. timedelta_range indexes
  64. """
  65. return np.arange(len(index))
  66. @pytest.fixture
  67. def _series_name():
  68. """
  69. Fixture for parametrization of Series name for Series used with
  70. date_range, period_range and timedelta_range indexes
  71. """
  72. return None
  73. @pytest.fixture
  74. def series(index, _series_name, _static_values):
  75. """
  76. Fixture for parametrization of Series with date_range, period_range and
  77. timedelta_range indexes
  78. """
  79. return Series(_static_values, index=index, name=_series_name)
  80. @pytest.fixture
  81. def empty_series_dti(series):
  82. """
  83. Fixture for parametrization of empty Series with date_range,
  84. period_range and timedelta_range indexes
  85. """
  86. return series[:0]
  87. @pytest.fixture
  88. def frame(index, _series_name, _static_values):
  89. """
  90. Fixture for parametrization of DataFrame with date_range, period_range
  91. and timedelta_range indexes
  92. """
  93. # _series_name is intentionally unused
  94. return DataFrame({"value": _static_values}, index=index)
  95. @pytest.fixture
  96. def empty_frame_dti(series):
  97. """
  98. Fixture for parametrization of empty DataFrame with date_range,
  99. period_range and timedelta_range indexes
  100. """
  101. index = series.index[:0]
  102. return DataFrame(index=index)
  103. @pytest.fixture
  104. def series_and_frame(frame_or_series, series, frame):
  105. """
  106. Fixture for parametrization of Series and DataFrame with date_range,
  107. period_range and timedelta_range indexes
  108. """
  109. if frame_or_series == Series:
  110. return series
  111. if frame_or_series == DataFrame:
  112. return frame