conftest.py 2.1 KB

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