conftest.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import numpy as np
  2. import pytest
  3. from pandas import DataFrame, SparseArray, SparseDataFrame, bdate_range
  4. data = {'A': [np.nan, np.nan, np.nan, 0, 1, 2, 3, 4, 5, 6],
  5. 'B': [0, 1, 2, np.nan, np.nan, np.nan, 3, 4, 5, 6],
  6. 'C': np.arange(10, dtype=np.float64),
  7. 'D': [0, 1, 2, 3, 4, 5, np.nan, np.nan, np.nan, np.nan]}
  8. dates = bdate_range('1/1/2011', periods=10)
  9. # fixture names must be compatible with the tests in
  10. # tests/frame/test_api.SharedWithSparse
  11. @pytest.fixture
  12. def float_frame_dense():
  13. """
  14. Fixture for dense DataFrame of floats with DatetimeIndex
  15. Columns are ['A', 'B', 'C', 'D']; some entries are missing
  16. """
  17. return DataFrame(data, index=dates)
  18. @pytest.fixture
  19. def float_frame():
  20. """
  21. Fixture for sparse DataFrame of floats with DatetimeIndex
  22. Columns are ['A', 'B', 'C', 'D']; some entries are missing
  23. """
  24. # default_kind='block' is the default
  25. return SparseDataFrame(data, index=dates, default_kind='block')
  26. @pytest.fixture
  27. def float_frame_int_kind():
  28. """
  29. Fixture for sparse DataFrame of floats with DatetimeIndex
  30. Columns are ['A', 'B', 'C', 'D'] and default_kind='integer'.
  31. Some entries are missing.
  32. """
  33. return SparseDataFrame(data, index=dates, default_kind='integer')
  34. @pytest.fixture
  35. def float_string_frame():
  36. """
  37. Fixture for sparse DataFrame of floats and strings with DatetimeIndex
  38. Columns are ['A', 'B', 'C', 'D', 'foo']; some entries are missing
  39. """
  40. sdf = SparseDataFrame(data, index=dates)
  41. sdf['foo'] = SparseArray(['bar'] * len(dates))
  42. return sdf
  43. @pytest.fixture
  44. def float_frame_fill0_dense():
  45. """
  46. Fixture for dense DataFrame of floats with DatetimeIndex
  47. Columns are ['A', 'B', 'C', 'D']; missing entries have been filled with 0
  48. """
  49. values = SparseDataFrame(data).values
  50. values[np.isnan(values)] = 0
  51. return DataFrame(values, columns=['A', 'B', 'C', 'D'], index=dates)
  52. @pytest.fixture
  53. def float_frame_fill0():
  54. """
  55. Fixture for sparse DataFrame of floats with DatetimeIndex
  56. Columns are ['A', 'B', 'C', 'D']; missing entries have been filled with 0
  57. """
  58. values = SparseDataFrame(data).values
  59. values[np.isnan(values)] = 0
  60. return SparseDataFrame(values, columns=['A', 'B', 'C', 'D'],
  61. default_fill_value=0, index=dates)
  62. @pytest.fixture
  63. def float_frame_fill2_dense():
  64. """
  65. Fixture for dense DataFrame of floats with DatetimeIndex
  66. Columns are ['A', 'B', 'C', 'D']; missing entries have been filled with 2
  67. """
  68. values = SparseDataFrame(data).values
  69. values[np.isnan(values)] = 2
  70. return DataFrame(values, columns=['A', 'B', 'C', 'D'], index=dates)
  71. @pytest.fixture
  72. def float_frame_fill2():
  73. """
  74. Fixture for sparse DataFrame of floats with DatetimeIndex
  75. Columns are ['A', 'B', 'C', 'D']; missing entries have been filled with 2
  76. """
  77. values = SparseDataFrame(data).values
  78. values[np.isnan(values)] = 2
  79. return SparseDataFrame(values, columns=['A', 'B', 'C', 'D'],
  80. default_fill_value=2, index=dates)
  81. @pytest.fixture
  82. def empty_frame():
  83. """
  84. Fixture for empty SparseDataFrame
  85. """
  86. return SparseDataFrame()