conftest.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import numpy as np
  2. import pytest
  3. import pandas as pd
  4. from pandas import Index, MultiIndex
  5. @pytest.fixture
  6. def idx():
  7. # a MultiIndex used to test the general functionality of the
  8. # general functionality of this object
  9. major_axis = Index(["foo", "bar", "baz", "qux"])
  10. minor_axis = Index(["one", "two"])
  11. major_codes = np.array([0, 0, 1, 2, 3, 3])
  12. minor_codes = np.array([0, 1, 0, 1, 0, 1])
  13. index_names = ["first", "second"]
  14. mi = MultiIndex(
  15. levels=[major_axis, minor_axis],
  16. codes=[major_codes, minor_codes],
  17. names=index_names,
  18. verify_integrity=False,
  19. )
  20. return mi
  21. @pytest.fixture
  22. def idx_dup():
  23. # compare tests/indexes/multi/conftest.py
  24. major_axis = Index(["foo", "bar", "baz", "qux"])
  25. minor_axis = Index(["one", "two"])
  26. major_codes = np.array([0, 0, 1, 0, 1, 1])
  27. minor_codes = np.array([0, 1, 0, 1, 0, 1])
  28. index_names = ["first", "second"]
  29. mi = MultiIndex(
  30. levels=[major_axis, minor_axis],
  31. codes=[major_codes, minor_codes],
  32. names=index_names,
  33. verify_integrity=False,
  34. )
  35. return mi
  36. @pytest.fixture
  37. def index_names():
  38. # names that match those in the idx fixture for testing equality of
  39. # names assigned to the idx
  40. return ["first", "second"]
  41. @pytest.fixture
  42. def holder():
  43. # the MultiIndex constructor used to base compatibility with pickle
  44. return MultiIndex
  45. @pytest.fixture
  46. def compat_props():
  47. # a MultiIndex must have these properties associated with it
  48. return ["shape", "ndim", "size"]
  49. @pytest.fixture
  50. def narrow_multi_index():
  51. """
  52. Return a MultiIndex that is narrower than the display (<80 characters).
  53. """
  54. n = 1000
  55. ci = pd.CategoricalIndex(list("a" * n) + (["abc"] * n))
  56. dti = pd.date_range("2000-01-01", freq="s", periods=n * 2)
  57. return pd.MultiIndex.from_arrays([ci, ci.codes + 9, dti], names=["a", "b", "dti"])
  58. @pytest.fixture
  59. def wide_multi_index():
  60. """
  61. Return a MultiIndex that is wider than the display (>80 characters).
  62. """
  63. n = 1000
  64. ci = pd.CategoricalIndex(list("a" * n) + (["abc"] * n))
  65. dti = pd.date_range("2000-01-01", freq="s", periods=n * 2)
  66. levels = [ci, ci.codes + 9, dti, dti, dti]
  67. names = ["a", "b", "dti_1", "dti_2", "dti_3"]
  68. return pd.MultiIndex.from_arrays(levels, names=names)