conftest.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import numpy as np
  2. import pytest
  3. import pandas as pd
  4. import pandas._testing as tm
  5. from pandas.core.indexes.api import Index, MultiIndex
  6. indices_dict = {
  7. "unicode": tm.makeUnicodeIndex(100),
  8. "string": tm.makeStringIndex(100),
  9. "datetime": tm.makeDateIndex(100),
  10. "period": tm.makePeriodIndex(100),
  11. "timedelta": tm.makeTimedeltaIndex(100),
  12. "int": tm.makeIntIndex(100),
  13. "uint": tm.makeUIntIndex(100),
  14. "range": tm.makeRangeIndex(100),
  15. "float": tm.makeFloatIndex(100),
  16. "bool": Index([True, False]),
  17. "categorical": tm.makeCategoricalIndex(100),
  18. "interval": tm.makeIntervalIndex(100),
  19. "empty": Index([]),
  20. "tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])),
  21. "repeats": Index([0, 0, 1, 1, 2, 2]),
  22. }
  23. @pytest.fixture(params=indices_dict.keys())
  24. def indices(request):
  25. # copy to avoid mutation, e.g. setting .name
  26. return indices_dict[request.param].copy()
  27. @pytest.fixture(params=[1, np.array(1, dtype=np.int64)])
  28. def one(request):
  29. # zero-dim integer array behaves like an integer
  30. return request.param
  31. zeros = [
  32. box([0] * 5, dtype=dtype)
  33. for box in [pd.Index, np.array]
  34. for dtype in [np.int64, np.uint64, np.float64]
  35. ]
  36. zeros.extend([np.array(0, dtype=dtype) for dtype in [np.int64, np.uint64, np.float64]])
  37. zeros.extend([0, 0.0])
  38. @pytest.fixture(params=zeros)
  39. def zero(request):
  40. # For testing division by (or of) zero for Index with length 5, this
  41. # gives several scalar-zeros and length-5 vector-zeros
  42. return request.param