conftest.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import numpy as np
  2. import pytest
  3. import pandas as pd
  4. from pandas import Index
  5. @pytest.fixture(params=[1, np.array(1, dtype=np.int64)])
  6. def one(request):
  7. """
  8. Several variants of integer value 1. The zero-dim integer array
  9. behaves like an integer.
  10. This fixture can be used to check that datetimelike indexes handle
  11. addition and subtraction of integers and zero-dimensional arrays
  12. of integers.
  13. Examples
  14. --------
  15. dti = pd.date_range('2016-01-01', periods=2, freq='h')
  16. dti
  17. DatetimeIndex(['2016-01-01 00:00:00', '2016-01-01 01:00:00'],
  18. dtype='datetime64[ns]', freq='h')
  19. dti + one
  20. DatetimeIndex(['2016-01-01 01:00:00', '2016-01-01 02:00:00'],
  21. dtype='datetime64[ns]', freq='h')
  22. """
  23. return request.param
  24. zeros = [
  25. box_cls([0] * 5, dtype=dtype)
  26. for box_cls in [Index, np.array, pd.array]
  27. for dtype in [np.int64, np.uint64, np.float64]
  28. ]
  29. zeros.extend([box_cls([-0.0] * 5, dtype=np.float64) for box_cls in [Index, np.array]])
  30. zeros.extend([np.array(0, dtype=dtype) for dtype in [np.int64, np.uint64, np.float64]])
  31. zeros.extend([np.array(-0.0, dtype=np.float64)])
  32. zeros.extend([0, 0.0, -0.0])
  33. @pytest.fixture(params=zeros)
  34. def zero(request):
  35. """
  36. Several types of scalar zeros and length 5 vectors of zeros.
  37. This fixture can be used to check that numeric-dtype indexes handle
  38. division by any zero numeric-dtype.
  39. Uses vector of length 5 for broadcasting with `numeric_idx` fixture,
  40. which creates numeric-dtype vectors also of length 5.
  41. Examples
  42. --------
  43. arr = RangeIndex(5)
  44. arr / zeros
  45. Index([nan, inf, inf, inf, inf], dtype='float64')
  46. """
  47. return request.param
  48. # ------------------------------------------------------------------
  49. # Scalar Fixtures
  50. @pytest.fixture(
  51. params=[
  52. pd.Timedelta("10m7s").to_pytimedelta(),
  53. pd.Timedelta("10m7s"),
  54. pd.Timedelta("10m7s").to_timedelta64(),
  55. ],
  56. ids=lambda x: type(x).__name__,
  57. )
  58. def scalar_td(request):
  59. """
  60. Several variants of Timedelta scalars representing 10 minutes and 7 seconds.
  61. """
  62. return request.param
  63. @pytest.fixture(
  64. params=[
  65. pd.offsets.Day(3),
  66. pd.offsets.Hour(72),
  67. pd.Timedelta(days=3).to_pytimedelta(),
  68. pd.Timedelta("72:00:00"),
  69. np.timedelta64(3, "D"),
  70. np.timedelta64(72, "h"),
  71. ],
  72. ids=lambda x: type(x).__name__,
  73. )
  74. def three_days(request):
  75. """
  76. Several timedelta-like and DateOffset objects that each represent
  77. a 3-day timedelta
  78. """
  79. return request.param
  80. @pytest.fixture(
  81. params=[
  82. pd.offsets.Hour(2),
  83. pd.offsets.Minute(120),
  84. pd.Timedelta(hours=2).to_pytimedelta(),
  85. pd.Timedelta(seconds=2 * 3600),
  86. np.timedelta64(2, "h"),
  87. np.timedelta64(120, "m"),
  88. ],
  89. ids=lambda x: type(x).__name__,
  90. )
  91. def two_hours(request):
  92. """
  93. Several timedelta-like and DateOffset objects that each represent
  94. a 2-hour timedelta
  95. """
  96. return request.param
  97. _common_mismatch = [
  98. pd.offsets.YearBegin(2),
  99. pd.offsets.MonthBegin(1),
  100. pd.offsets.Minute(),
  101. ]
  102. @pytest.fixture(
  103. params=[
  104. np.timedelta64(4, "h"),
  105. pd.Timedelta(hours=23).to_pytimedelta(),
  106. pd.Timedelta("23:00:00"),
  107. ]
  108. + _common_mismatch
  109. )
  110. def not_daily(request):
  111. """
  112. Several timedelta-like and DateOffset instances that are _not_
  113. compatible with Daily frequencies.
  114. """
  115. return request.param