|
| 1 | +import pytest |
| 2 | + |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +from pandas import compat |
| 6 | +import pandas.util.testing as tm |
| 7 | +from pandas import DataFrame, date_range, NaT |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | +def float_frame(): |
| 12 | + """ |
| 13 | + Fixture for DataFrame of floats with index of unique strings |
| 14 | +
|
| 15 | + Columns are ['A', 'B', 'C', 'D']. |
| 16 | + """ |
| 17 | + return DataFrame(tm.getSeriesData()) |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def float_frame2(): |
| 22 | + """ |
| 23 | + Fixture for DataFrame of floats with index of unique strings |
| 24 | +
|
| 25 | + Columns are ['D', 'C', 'B', 'A'] |
| 26 | + """ |
| 27 | + return DataFrame(tm.getSeriesData(), columns=['D', 'C', 'B', 'A']) |
| 28 | + |
| 29 | + |
| 30 | +@pytest.fixture |
| 31 | +def int_frame(): |
| 32 | + """ |
| 33 | + Fixture for DataFrame of ints with index of unique strings |
| 34 | +
|
| 35 | + Columns are ['A', 'B', 'C', 'D'] |
| 36 | + """ |
| 37 | + df = DataFrame({k: v.astype(int) |
| 38 | + for k, v in compat.iteritems(tm.getSeriesData())}) |
| 39 | + # force these all to int64 to avoid platform testing issues |
| 40 | + return DataFrame({c: s for c, s in compat.iteritems(df)}, dtype=np.int64) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.fixture |
| 44 | +def datetime_frame(): |
| 45 | + """ |
| 46 | + Fixture for DataFrame of floats with DatetimeIndex |
| 47 | +
|
| 48 | + Columns are ['A', 'B', 'C', 'D'] |
| 49 | + """ |
| 50 | + return DataFrame(tm.getTimeSeriesData()) |
| 51 | + |
| 52 | + |
| 53 | +@pytest.fixture |
| 54 | +def float_string_frame(): |
| 55 | + """ |
| 56 | + Fixture for DataFrame of floats and strings with index of unique strings |
| 57 | +
|
| 58 | + Columns are ['A', 'B', 'C', 'D', 'foo']. |
| 59 | + """ |
| 60 | + df = DataFrame(tm.getSeriesData()) |
| 61 | + df['foo'] = 'bar' |
| 62 | + return df |
| 63 | + |
| 64 | + |
| 65 | +@pytest.fixture |
| 66 | +def mixed_float_frame(): |
| 67 | + """ |
| 68 | + Fixture for DataFrame of different float types with index of unique strings |
| 69 | +
|
| 70 | + Columns are ['A', 'B', 'C', 'D']. |
| 71 | + """ |
| 72 | + df = DataFrame(tm.getSeriesData()) |
| 73 | + df.A = df.A.astype('float16') |
| 74 | + df.B = df.B.astype('float32') |
| 75 | + df.C = df.C.astype('float64') |
| 76 | + return df |
| 77 | + |
| 78 | + |
| 79 | +@pytest.fixture |
| 80 | +def mixed_float_frame2(): |
| 81 | + """ |
| 82 | + Fixture for DataFrame of different float types with index of unique strings |
| 83 | +
|
| 84 | + Columns are ['A', 'B', 'C', 'D']. |
| 85 | + """ |
| 86 | + df = DataFrame(tm.getSeriesData()) |
| 87 | + df.D = df.D.astype('float16') |
| 88 | + df.C = df.C.astype('float32') |
| 89 | + df.B = df.B.astype('float64') |
| 90 | + return df |
| 91 | + |
| 92 | + |
| 93 | +@pytest.fixture |
| 94 | +def mixed_int_frame(): |
| 95 | + """ |
| 96 | + Fixture for DataFrame of different int types with index of unique strings |
| 97 | +
|
| 98 | + Columns are ['A', 'B', 'C', 'D']. |
| 99 | + """ |
| 100 | + df = DataFrame({k: v.astype(int) |
| 101 | + for k, v in compat.iteritems(tm.getSeriesData())}) |
| 102 | + df.A = df.A.astype('uint8') |
| 103 | + df.B = df.B.astype('int32') |
| 104 | + df.C = df.C.astype('int64') |
| 105 | + df.D = np.ones(len(df.D), dtype='uint64') |
| 106 | + return df |
| 107 | + |
| 108 | + |
| 109 | +@pytest.fixture |
| 110 | +def mixed_type_frame(): |
| 111 | + """ |
| 112 | + Fixture for DataFrame of float/int/string columns with RangeIndex |
| 113 | +
|
| 114 | + Columns are ['a', 'b', 'c', 'float32', 'int32']. |
| 115 | + """ |
| 116 | + return DataFrame({'a': 1., 'b': 2, 'c': 'foo', |
| 117 | + 'float32': np.array([1.] * 10, dtype='float32'), |
| 118 | + 'int32': np.array([1] * 10, dtype='int32')}, |
| 119 | + index=np.arange(10)) |
| 120 | + |
| 121 | + |
| 122 | +@pytest.fixture |
| 123 | +def timezone_frame(): |
| 124 | + """ |
| 125 | + Fixture for DataFrame of date_range Series with different time zones |
| 126 | +
|
| 127 | + Columns are ['A', 'B', 'C']; some entries are missing |
| 128 | + """ |
| 129 | + df = DataFrame({'A': date_range('20130101', periods=3), |
| 130 | + 'B': date_range('20130101', periods=3, |
| 131 | + tz='US/Eastern'), |
| 132 | + 'C': date_range('20130101', periods=3, |
| 133 | + tz='CET')}) |
| 134 | + df.iloc[1, 1] = NaT |
| 135 | + df.iloc[1, 2] = NaT |
| 136 | + return df |
| 137 | + |
| 138 | + |
| 139 | +@pytest.fixture |
| 140 | +def empty_frame(): |
| 141 | + """ |
| 142 | + Fixture for empty DataFrame |
| 143 | + """ |
| 144 | + return DataFrame({}) |
| 145 | + |
| 146 | + |
| 147 | +@pytest.fixture |
| 148 | +def datetime_series(): |
| 149 | + """ |
| 150 | + Fixture for Series of floats with DatetimeIndex |
| 151 | + """ |
| 152 | + return tm.makeTimeSeries(nper=30) |
| 153 | + |
| 154 | + |
| 155 | +@pytest.fixture |
| 156 | +def datetime_series_short(): |
| 157 | + """ |
| 158 | + Fixture for Series of floats with DatetimeIndex |
| 159 | + """ |
| 160 | + return tm.makeTimeSeries(nper=30)[5:] |
| 161 | + |
| 162 | + |
| 163 | +@pytest.fixture |
| 164 | +def simple_frame(): |
| 165 | + """ |
| 166 | + Fixture for simple 3x3 DataFrame |
| 167 | +
|
| 168 | + Columns are ['one', 'two', 'three'], index is ['a', 'b', 'c']. |
| 169 | + """ |
| 170 | + arr = np.array([[1., 2., 3.], |
| 171 | + [4., 5., 6.], |
| 172 | + [7., 8., 9.]]) |
| 173 | + |
| 174 | + return DataFrame(arr, columns=['one', 'two', 'three'], |
| 175 | + index=['a', 'b', 'c']) |
| 176 | + |
| 177 | + |
| 178 | +@pytest.fixture |
| 179 | +def frame_of_index_cols(): |
| 180 | + """ |
| 181 | + Fixture for DataFrame of columns that can be used for indexing |
| 182 | +
|
| 183 | + Columns are ['A', 'B', 'C', 'D', 'E']; 'A' & 'B' contain duplicates (but |
| 184 | + are jointly unique), the rest are unique. |
| 185 | + """ |
| 186 | + df = DataFrame({'A': ['foo', 'foo', 'foo', 'bar', 'bar'], |
| 187 | + 'B': ['one', 'two', 'three', 'one', 'two'], |
| 188 | + 'C': ['a', 'b', 'c', 'd', 'e'], |
| 189 | + 'D': np.random.randn(5), |
| 190 | + 'E': np.random.randn(5)}) |
| 191 | + return df |
0 commit comments