|
17 | 17 | from pandas import DataFrame
|
18 | 18 | import pandas._testing as tm
|
19 | 19 | from pandas.core import ops
|
| 20 | +from pandas.core.indexes.api import Index, MultiIndex |
20 | 21 |
|
21 | 22 | hypothesis.settings.register_profile(
|
22 | 23 | "ci",
|
@@ -953,3 +954,69 @@ def __len__(self):
|
953 | 954 | return self._data.__len__()
|
954 | 955 |
|
955 | 956 | return TestNonDictMapping
|
| 957 | + |
| 958 | + |
| 959 | +indices_dict = { |
| 960 | + "unicode": tm.makeUnicodeIndex(100), |
| 961 | + "string": tm.makeStringIndex(100), |
| 962 | + "datetime": tm.makeDateIndex(100), |
| 963 | + "datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"), |
| 964 | + "period": tm.makePeriodIndex(100), |
| 965 | + "timedelta": tm.makeTimedeltaIndex(100), |
| 966 | + "int": tm.makeIntIndex(100), |
| 967 | + "uint": tm.makeUIntIndex(100), |
| 968 | + "range": tm.makeRangeIndex(100), |
| 969 | + "float": tm.makeFloatIndex(100), |
| 970 | + "bool": tm.makeBoolIndex(2), |
| 971 | + "categorical": tm.makeCategoricalIndex(100), |
| 972 | + "interval": tm.makeIntervalIndex(100), |
| 973 | + "empty": Index([]), |
| 974 | + "tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])), |
| 975 | + "repeats": Index([0, 0, 1, 1, 2, 2]), |
| 976 | +} |
| 977 | + |
| 978 | + |
| 979 | +@pytest.fixture(params=indices_dict.keys()) |
| 980 | +def indices(request): |
| 981 | + # copy to avoid mutation, e.g. setting .name |
| 982 | + return indices_dict[request.param].copy() |
| 983 | + |
| 984 | + |
| 985 | +def _create_series(index): |
| 986 | + """ Helper for the _series dict """ |
| 987 | + size = len(index) |
| 988 | + data = np.random.randn(size) |
| 989 | + return pd.Series(data, index=index, name="a") |
| 990 | + |
| 991 | + |
| 992 | +_series = { |
| 993 | + f"series-with-{index_id}-index": _create_series(index) |
| 994 | + for index_id, index in indices_dict.items() |
| 995 | +} |
| 996 | + |
| 997 | + |
| 998 | +_narrow_dtypes = [ |
| 999 | + np.float16, |
| 1000 | + np.float32, |
| 1001 | + np.int8, |
| 1002 | + np.int16, |
| 1003 | + np.int32, |
| 1004 | + np.uint8, |
| 1005 | + np.uint16, |
| 1006 | + np.uint32, |
| 1007 | +] |
| 1008 | +_narrow_series = { |
| 1009 | + f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype) |
| 1010 | + for dtype in _narrow_dtypes |
| 1011 | +} |
| 1012 | + |
| 1013 | +_index_or_series_objs = {**indices_dict, **_series, **_narrow_series} |
| 1014 | + |
| 1015 | + |
| 1016 | +@pytest.fixture(params=_index_or_series_objs.keys()) |
| 1017 | +def index_or_series_obj(request): |
| 1018 | + """ |
| 1019 | + Fixture for tests on indexes, series and series with a narrow dtype |
| 1020 | + copy to avoid mutation, e.g. setting .name |
| 1021 | + """ |
| 1022 | + return _index_or_series_objs[request.param].copy(deep=True) |
0 commit comments