ZTWHHH commited on
Commit
1ab4806
·
verified ·
1 Parent(s): f0a4e08

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__init__.py +0 -0
  2. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-310.pyc +0 -0
  3. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-310.pyc +0 -0
  4. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-310.pyc +0 -0
  5. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_setops.cpython-310.pyc +0 -0
  6. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-310.pyc +0 -0
  7. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_constructors.py +80 -0
  8. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_formats.py +163 -0
  9. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_indexing.py +104 -0
  10. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_pickle.py +11 -0
  11. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_reshape.py +95 -0
  12. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.py +266 -0
  13. vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_where.py +13 -0
  14. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__init__.py +0 -0
  15. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/__init__.cpython-310.pyc +0 -0
  16. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_append.cpython-310.pyc +0 -0
  17. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_astype.cpython-310.pyc +0 -0
  18. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_category.cpython-310.pyc +0 -0
  19. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_constructors.cpython-310.pyc +0 -0
  20. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_equals.cpython-310.pyc +0 -0
  21. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_fillna.cpython-310.pyc +0 -0
  22. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_formats.cpython-310.pyc +0 -0
  23. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_indexing.cpython-310.pyc +0 -0
  24. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_map.cpython-310.pyc +0 -0
  25. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_reindex.cpython-310.pyc +0 -0
  26. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_setops.cpython-310.pyc +0 -0
  27. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_append.py +62 -0
  28. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_astype.py +90 -0
  29. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_category.py +394 -0
  30. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_constructors.py +142 -0
  31. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_equals.py +96 -0
  32. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_fillna.py +54 -0
  33. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_formats.py +120 -0
  34. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_indexing.py +420 -0
  35. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_map.py +144 -0
  36. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_reindex.py +78 -0
  37. vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_setops.py +18 -0
  38. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__init__.py +0 -0
  39. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/__init__.cpython-310.pyc +0 -0
  40. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_drop_duplicates.cpython-310.pyc +0 -0
  41. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_equals.cpython-310.pyc +0 -0
  42. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_indexing.cpython-310.pyc +0 -0
  43. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_is_monotonic.cpython-310.pyc +0 -0
  44. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_nat.cpython-310.pyc +0 -0
  45. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_sort_values.cpython-310.pyc +0 -0
  46. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_value_counts.cpython-310.pyc +0 -0
  47. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py +89 -0
  48. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_equals.py +181 -0
  49. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_indexing.py +45 -0
  50. vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_is_monotonic.py +46 -0
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__init__.py ADDED
File without changes
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-310.pyc ADDED
Binary file (5.08 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-310.pyc ADDED
Binary file (549 Bytes). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-310.pyc ADDED
Binary file (3.5 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_setops.cpython-310.pyc ADDED
Binary file (8.25 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-310.pyc ADDED
Binary file (803 Bytes). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_constructors.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Index,
7
+ MultiIndex,
8
+ Series,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestIndexConstructor:
14
+ # Tests for the Index constructor, specifically for cases that do
15
+ # not return a subclass
16
+
17
+ @pytest.mark.parametrize("value", [1, np.int64(1)])
18
+ def test_constructor_corner(self, value):
19
+ # corner case
20
+ msg = (
21
+ r"Index\(\.\.\.\) must be called with a collection of some "
22
+ f"kind, {value} was passed"
23
+ )
24
+ with pytest.raises(TypeError, match=msg):
25
+ Index(value)
26
+
27
+ @pytest.mark.parametrize("index_vals", [[("A", 1), "B"], ["B", ("A", 1)]])
28
+ def test_construction_list_mixed_tuples(self, index_vals):
29
+ # see gh-10697: if we are constructing from a mixed list of tuples,
30
+ # make sure that we are independent of the sorting order.
31
+ index = Index(index_vals)
32
+ assert isinstance(index, Index)
33
+ assert not isinstance(index, MultiIndex)
34
+
35
+ def test_constructor_cast(self):
36
+ msg = "could not convert string to float"
37
+ with pytest.raises(ValueError, match=msg):
38
+ Index(["a", "b", "c"], dtype=float)
39
+
40
+ @pytest.mark.parametrize("tuple_list", [[()], [(), ()]])
41
+ def test_construct_empty_tuples(self, tuple_list):
42
+ # GH #45608
43
+ result = Index(tuple_list)
44
+ expected = MultiIndex.from_tuples(tuple_list)
45
+
46
+ tm.assert_index_equal(result, expected)
47
+
48
+ def test_index_string_inference(self):
49
+ # GH#54430
50
+ pytest.importorskip("pyarrow")
51
+ dtype = "string[pyarrow_numpy]"
52
+ expected = Index(["a", "b"], dtype=dtype)
53
+ with pd.option_context("future.infer_string", True):
54
+ ser = Index(["a", "b"])
55
+ tm.assert_index_equal(ser, expected)
56
+
57
+ expected = Index(["a", 1], dtype="object")
58
+ with pd.option_context("future.infer_string", True):
59
+ ser = Index(["a", 1])
60
+ tm.assert_index_equal(ser, expected)
61
+
62
+ def test_inference_on_pandas_objects(self):
63
+ # GH#56012
64
+ idx = Index([pd.Timestamp("2019-12-31")], dtype=object)
65
+ with tm.assert_produces_warning(FutureWarning, match="Dtype inference"):
66
+ result = Index(idx)
67
+ assert result.dtype != np.object_
68
+
69
+ ser = Series([pd.Timestamp("2019-12-31")], dtype=object)
70
+
71
+ with tm.assert_produces_warning(FutureWarning, match="Dtype inference"):
72
+ result = Index(ser)
73
+ assert result.dtype != np.object_
74
+
75
+ def test_constructor_not_read_only(self):
76
+ # GH#57130
77
+ ser = Series([1, 2], dtype=object)
78
+ with pd.option_context("mode.copy_on_write", True):
79
+ idx = Index(ser)
80
+ assert idx._values.flags.writeable
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_formats.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas._config import using_pyarrow_string_dtype
5
+ import pandas._config.config as cf
6
+
7
+ from pandas import Index
8
+ import pandas._testing as tm
9
+
10
+
11
+ class TestIndexRendering:
12
+ def test_repr_is_valid_construction_code(self):
13
+ # for the case of Index, where the repr is traditional rather than
14
+ # stylized
15
+ idx = Index(["a", "b"])
16
+ res = eval(repr(idx))
17
+ tm.assert_index_equal(res, idx)
18
+
19
+ @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="repr different")
20
+ @pytest.mark.parametrize(
21
+ "index,expected",
22
+ [
23
+ # ASCII
24
+ # short
25
+ (
26
+ Index(["a", "bb", "ccc"]),
27
+ """Index(['a', 'bb', 'ccc'], dtype='object')""",
28
+ ),
29
+ # multiple lines
30
+ (
31
+ Index(["a", "bb", "ccc"] * 10),
32
+ "Index(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', "
33
+ "'bb', 'ccc', 'a', 'bb', 'ccc',\n"
34
+ " 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', "
35
+ "'bb', 'ccc', 'a', 'bb', 'ccc',\n"
36
+ " 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],\n"
37
+ " dtype='object')",
38
+ ),
39
+ # truncated
40
+ (
41
+ Index(["a", "bb", "ccc"] * 100),
42
+ "Index(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',\n"
43
+ " ...\n"
44
+ " 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],\n"
45
+ " dtype='object', length=300)",
46
+ ),
47
+ # Non-ASCII
48
+ # short
49
+ (
50
+ Index(["あ", "いい", "ううう"]),
51
+ """Index(['あ', 'いい', 'ううう'], dtype='object')""",
52
+ ),
53
+ # multiple lines
54
+ (
55
+ Index(["あ", "いい", "ううう"] * 10),
56
+ (
57
+ "Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
58
+ "'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n"
59
+ " 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
60
+ "'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n"
61
+ " 'あ', 'いい', 'ううう', 'あ', 'いい', "
62
+ "'ううう'],\n"
63
+ " dtype='object')"
64
+ ),
65
+ ),
66
+ # truncated
67
+ (
68
+ Index(["あ", "いい", "ううう"] * 100),
69
+ (
70
+ "Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
71
+ "'あ', 'いい', 'ううう', 'あ',\n"
72
+ " ...\n"
73
+ " 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', "
74
+ "'ううう', 'あ', 'いい', 'ううう'],\n"
75
+ " dtype='object', length=300)"
76
+ ),
77
+ ),
78
+ ],
79
+ )
80
+ def test_string_index_repr(self, index, expected):
81
+ result = repr(index)
82
+ assert result == expected
83
+
84
+ @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="repr different")
85
+ @pytest.mark.parametrize(
86
+ "index,expected",
87
+ [
88
+ # short
89
+ (
90
+ Index(["あ", "いい", "ううう"]),
91
+ ("Index(['あ', 'いい', 'ううう'], dtype='object')"),
92
+ ),
93
+ # multiple lines
94
+ (
95
+ Index(["あ", "いい", "ううう"] * 10),
96
+ (
97
+ "Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
98
+ "'ううう', 'あ', 'いい', 'ううう',\n"
99
+ " 'あ', 'いい', 'ううう', 'あ', 'いい', "
100
+ "'ううう', 'あ', 'いい', 'ううう',\n"
101
+ " 'あ', 'いい', 'ううう', 'あ', 'いい', "
102
+ "'ううう', 'あ', 'いい', 'ううう',\n"
103
+ " 'あ', 'いい', 'ううう'],\n"
104
+ " dtype='object')"
105
+ ""
106
+ ),
107
+ ),
108
+ # truncated
109
+ (
110
+ Index(["あ", "いい", "ううう"] * 100),
111
+ (
112
+ "Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
113
+ "'ううう', 'あ', 'いい', 'ううう',\n"
114
+ " 'あ',\n"
115
+ " ...\n"
116
+ " 'ううう', 'あ', 'いい', 'ううう', 'あ', "
117
+ "'いい', 'ううう', 'あ', 'いい',\n"
118
+ " 'ううう'],\n"
119
+ " dtype='object', length=300)"
120
+ ),
121
+ ),
122
+ ],
123
+ )
124
+ def test_string_index_repr_with_unicode_option(self, index, expected):
125
+ # Enable Unicode option -----------------------------------------
126
+ with cf.option_context("display.unicode.east_asian_width", True):
127
+ result = repr(index)
128
+ assert result == expected
129
+
130
+ def test_repr_summary(self):
131
+ with cf.option_context("display.max_seq_items", 10):
132
+ result = repr(Index(np.arange(1000)))
133
+ assert len(result) < 200
134
+ assert "..." in result
135
+
136
+ def test_summary_bug(self):
137
+ # GH#3869
138
+ ind = Index(["{other}%s", "~:{range}:0"], name="A")
139
+ result = ind._summary()
140
+ # shouldn't be formatted accidentally.
141
+ assert "~:{range}:0" in result
142
+ assert "{other}%s" in result
143
+
144
+ def test_index_repr_bool_nan(self):
145
+ # GH32146
146
+ arr = Index([True, False, np.nan], dtype=object)
147
+ msg = "Index.format is deprecated"
148
+ with tm.assert_produces_warning(FutureWarning, match=msg):
149
+ exp1 = arr.format()
150
+ out1 = ["True", "False", "NaN"]
151
+ assert out1 == exp1
152
+
153
+ exp2 = repr(arr)
154
+ out2 = "Index([True, False, nan], dtype='object')"
155
+ assert out2 == exp2
156
+
157
+ def test_format_different_scalar_lengths(self):
158
+ # GH#35439
159
+ idx = Index(["aaaaaaaaa", "b"])
160
+ expected = ["aaaaaaaaa", "b"]
161
+ msg = r"Index\.format is deprecated"
162
+ with tm.assert_produces_warning(FutureWarning, match=msg):
163
+ assert idx.format() == expected
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_indexing.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas._libs import index as libindex
5
+
6
+ import pandas as pd
7
+ from pandas import (
8
+ Index,
9
+ NaT,
10
+ )
11
+ import pandas._testing as tm
12
+
13
+
14
+ class TestGetSliceBounds:
15
+ @pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)])
16
+ def test_get_slice_bounds_within(self, side, expected):
17
+ index = Index(list("abcdef"))
18
+ result = index.get_slice_bound("e", side=side)
19
+ assert result == expected
20
+
21
+ @pytest.mark.parametrize("side", ["left", "right"])
22
+ @pytest.mark.parametrize(
23
+ "data, bound, expected", [(list("abcdef"), "x", 6), (list("bcdefg"), "a", 0)]
24
+ )
25
+ def test_get_slice_bounds_outside(self, side, expected, data, bound):
26
+ index = Index(data)
27
+ result = index.get_slice_bound(bound, side=side)
28
+ assert result == expected
29
+
30
+ def test_get_slice_bounds_invalid_side(self):
31
+ with pytest.raises(ValueError, match="Invalid value for side kwarg"):
32
+ Index([]).get_slice_bound("a", side="middle")
33
+
34
+
35
+ class TestGetIndexerNonUnique:
36
+ def test_get_indexer_non_unique_dtype_mismatch(self):
37
+ # GH#25459
38
+ indexes, missing = Index(["A", "B"]).get_indexer_non_unique(Index([0]))
39
+ tm.assert_numpy_array_equal(np.array([-1], dtype=np.intp), indexes)
40
+ tm.assert_numpy_array_equal(np.array([0], dtype=np.intp), missing)
41
+
42
+ @pytest.mark.parametrize(
43
+ "idx_values,idx_non_unique",
44
+ [
45
+ ([np.nan, 100, 200, 100], [np.nan, 100]),
46
+ ([np.nan, 100.0, 200.0, 100.0], [np.nan, 100.0]),
47
+ ],
48
+ )
49
+ def test_get_indexer_non_unique_int_index(self, idx_values, idx_non_unique):
50
+ indexes, missing = Index(idx_values).get_indexer_non_unique(Index([np.nan]))
51
+ tm.assert_numpy_array_equal(np.array([0], dtype=np.intp), indexes)
52
+ tm.assert_numpy_array_equal(np.array([], dtype=np.intp), missing)
53
+
54
+ indexes, missing = Index(idx_values).get_indexer_non_unique(
55
+ Index(idx_non_unique)
56
+ )
57
+ tm.assert_numpy_array_equal(np.array([0, 1, 3], dtype=np.intp), indexes)
58
+ tm.assert_numpy_array_equal(np.array([], dtype=np.intp), missing)
59
+
60
+
61
+ class TestGetLoc:
62
+ @pytest.mark.slow # to_flat_index takes a while
63
+ def test_get_loc_tuple_monotonic_above_size_cutoff(self, monkeypatch):
64
+ # Go through the libindex path for which using
65
+ # _bin_search vs ndarray.searchsorted makes a difference
66
+
67
+ with monkeypatch.context():
68
+ monkeypatch.setattr(libindex, "_SIZE_CUTOFF", 100)
69
+ lev = list("ABCD")
70
+ dti = pd.date_range("2016-01-01", periods=10)
71
+
72
+ mi = pd.MultiIndex.from_product([lev, range(5), dti])
73
+ oidx = mi.to_flat_index()
74
+
75
+ loc = len(oidx) // 2
76
+ tup = oidx[loc]
77
+
78
+ res = oidx.get_loc(tup)
79
+ assert res == loc
80
+
81
+ def test_get_loc_nan_object_dtype_nonmonotonic_nonunique(self):
82
+ # case that goes through _maybe_get_bool_indexer
83
+ idx = Index(["foo", np.nan, None, "foo", 1.0, None], dtype=object)
84
+
85
+ # we dont raise KeyError on nan
86
+ res = idx.get_loc(np.nan)
87
+ assert res == 1
88
+
89
+ # we only match on None, not on np.nan
90
+ res = idx.get_loc(None)
91
+ expected = np.array([False, False, True, False, False, True])
92
+ tm.assert_numpy_array_equal(res, expected)
93
+
94
+ # we don't match at all on mismatched NA
95
+ with pytest.raises(KeyError, match="NaT"):
96
+ idx.get_loc(NaT)
97
+
98
+
99
+ def test_getitem_boolean_ea_indexer():
100
+ # GH#45806
101
+ ser = pd.Series([True, False, pd.NA], dtype="boolean")
102
+ result = ser.index[ser]
103
+ expected = Index([0])
104
+ tm.assert_index_equal(result, expected)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_pickle.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pandas import Index
2
+ import pandas._testing as tm
3
+
4
+
5
+ def test_pickle_preserves_object_dtype():
6
+ # GH#43188, GH#43155 don't infer numeric dtype
7
+ index = Index([1, 2, 3], dtype=object)
8
+
9
+ result = tm.round_trip_pickle(index)
10
+ assert result.dtype == object
11
+ tm.assert_index_equal(index, result)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_reshape.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests for ndarray-like method on the base Index class
3
+ """
4
+ import numpy as np
5
+ import pytest
6
+
7
+ from pandas import Index
8
+ import pandas._testing as tm
9
+
10
+
11
+ class TestReshape:
12
+ def test_repeat(self):
13
+ repeats = 2
14
+ index = Index([1, 2, 3])
15
+ expected = Index([1, 1, 2, 2, 3, 3])
16
+
17
+ result = index.repeat(repeats)
18
+ tm.assert_index_equal(result, expected)
19
+
20
+ def test_insert(self):
21
+ # GH 7256
22
+ # validate neg/pos inserts
23
+ result = Index(["b", "c", "d"])
24
+
25
+ # test 0th element
26
+ tm.assert_index_equal(Index(["a", "b", "c", "d"]), result.insert(0, "a"))
27
+
28
+ # test Nth element that follows Python list behavior
29
+ tm.assert_index_equal(Index(["b", "c", "e", "d"]), result.insert(-1, "e"))
30
+
31
+ # test loc +/- neq (0, -1)
32
+ tm.assert_index_equal(result.insert(1, "z"), result.insert(-2, "z"))
33
+
34
+ # test empty
35
+ null_index = Index([])
36
+ tm.assert_index_equal(Index(["a"], dtype=object), null_index.insert(0, "a"))
37
+
38
+ def test_insert_missing(self, nulls_fixture, using_infer_string):
39
+ # GH#22295
40
+ # test there is no mangling of NA values
41
+ expected = Index(["a", nulls_fixture, "b", "c"], dtype=object)
42
+ result = Index(list("abc"), dtype=object).insert(
43
+ 1, Index([nulls_fixture], dtype=object)
44
+ )
45
+ tm.assert_index_equal(result, expected)
46
+
47
+ @pytest.mark.parametrize(
48
+ "val", [(1, 2), np.datetime64("2019-12-31"), np.timedelta64(1, "D")]
49
+ )
50
+ @pytest.mark.parametrize("loc", [-1, 2])
51
+ def test_insert_datetime_into_object(self, loc, val):
52
+ # GH#44509
53
+ idx = Index(["1", "2", "3"])
54
+ result = idx.insert(loc, val)
55
+ expected = Index(["1", "2", val, "3"])
56
+ tm.assert_index_equal(result, expected)
57
+ assert type(expected[2]) is type(val)
58
+
59
+ def test_insert_none_into_string_numpy(self):
60
+ # GH#55365
61
+ pytest.importorskip("pyarrow")
62
+ index = Index(["a", "b", "c"], dtype="string[pyarrow_numpy]")
63
+ result = index.insert(-1, None)
64
+ expected = Index(["a", "b", None, "c"], dtype="string[pyarrow_numpy]")
65
+ tm.assert_index_equal(result, expected)
66
+
67
+ @pytest.mark.parametrize(
68
+ "pos,expected",
69
+ [
70
+ (0, Index(["b", "c", "d"], name="index")),
71
+ (-1, Index(["a", "b", "c"], name="index")),
72
+ ],
73
+ )
74
+ def test_delete(self, pos, expected):
75
+ index = Index(["a", "b", "c", "d"], name="index")
76
+ result = index.delete(pos)
77
+ tm.assert_index_equal(result, expected)
78
+ assert result.name == expected.name
79
+
80
+ def test_delete_raises(self):
81
+ index = Index(["a", "b", "c", "d"], name="index")
82
+ msg = "index 5 is out of bounds for axis 0 with size 4"
83
+ with pytest.raises(IndexError, match=msg):
84
+ index.delete(5)
85
+
86
+ def test_append_multiple(self):
87
+ index = Index(["a", "b", "c", "d", "e", "f"])
88
+
89
+ foos = [index[:2], index[2:4], index[4:]]
90
+ result = foos[0].append(foos[1:])
91
+ tm.assert_index_equal(result, index)
92
+
93
+ # empty
94
+ result = index.append([])
95
+ tm.assert_index_equal(result, index)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.py ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ import pandas as pd
7
+ from pandas import (
8
+ Index,
9
+ Series,
10
+ )
11
+ import pandas._testing as tm
12
+ from pandas.core.algorithms import safe_sort
13
+
14
+
15
+ def equal_contents(arr1, arr2) -> bool:
16
+ """
17
+ Checks if the set of unique elements of arr1 and arr2 are equivalent.
18
+ """
19
+ return frozenset(arr1) == frozenset(arr2)
20
+
21
+
22
+ class TestIndexSetOps:
23
+ @pytest.mark.parametrize(
24
+ "method", ["union", "intersection", "difference", "symmetric_difference"]
25
+ )
26
+ def test_setops_sort_validation(self, method):
27
+ idx1 = Index(["a", "b"])
28
+ idx2 = Index(["b", "c"])
29
+
30
+ with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
31
+ getattr(idx1, method)(idx2, sort=2)
32
+
33
+ # sort=True is supported as of GH#??
34
+ getattr(idx1, method)(idx2, sort=True)
35
+
36
+ def test_setops_preserve_object_dtype(self):
37
+ idx = Index([1, 2, 3], dtype=object)
38
+ result = idx.intersection(idx[1:])
39
+ expected = idx[1:]
40
+ tm.assert_index_equal(result, expected)
41
+
42
+ # if other is not monotonic increasing, intersection goes through
43
+ # a different route
44
+ result = idx.intersection(idx[1:][::-1])
45
+ tm.assert_index_equal(result, expected)
46
+
47
+ result = idx._union(idx[1:], sort=None)
48
+ expected = idx
49
+ tm.assert_numpy_array_equal(result, expected.values)
50
+
51
+ result = idx.union(idx[1:], sort=None)
52
+ tm.assert_index_equal(result, expected)
53
+
54
+ # if other is not monotonic increasing, _union goes through
55
+ # a different route
56
+ result = idx._union(idx[1:][::-1], sort=None)
57
+ tm.assert_numpy_array_equal(result, expected.values)
58
+
59
+ result = idx.union(idx[1:][::-1], sort=None)
60
+ tm.assert_index_equal(result, expected)
61
+
62
+ def test_union_base(self):
63
+ index = Index([0, "a", 1, "b", 2, "c"])
64
+ first = index[3:]
65
+ second = index[:5]
66
+
67
+ result = first.union(second)
68
+
69
+ expected = Index([0, 1, 2, "a", "b", "c"])
70
+ tm.assert_index_equal(result, expected)
71
+
72
+ @pytest.mark.parametrize("klass", [np.array, Series, list])
73
+ def test_union_different_type_base(self, klass):
74
+ # GH 10149
75
+ index = Index([0, "a", 1, "b", 2, "c"])
76
+ first = index[3:]
77
+ second = index[:5]
78
+
79
+ result = first.union(klass(second.values))
80
+
81
+ assert equal_contents(result, index)
82
+
83
+ def test_union_sort_other_incomparable(self):
84
+ # https://github.com/pandas-dev/pandas/issues/24959
85
+ idx = Index([1, pd.Timestamp("2000")])
86
+ # default (sort=None)
87
+ with tm.assert_produces_warning(RuntimeWarning):
88
+ result = idx.union(idx[:1])
89
+
90
+ tm.assert_index_equal(result, idx)
91
+
92
+ # sort=None
93
+ with tm.assert_produces_warning(RuntimeWarning):
94
+ result = idx.union(idx[:1], sort=None)
95
+ tm.assert_index_equal(result, idx)
96
+
97
+ # sort=False
98
+ result = idx.union(idx[:1], sort=False)
99
+ tm.assert_index_equal(result, idx)
100
+
101
+ def test_union_sort_other_incomparable_true(self):
102
+ idx = Index([1, pd.Timestamp("2000")])
103
+ with pytest.raises(TypeError, match=".*"):
104
+ idx.union(idx[:1], sort=True)
105
+
106
+ def test_intersection_equal_sort_true(self):
107
+ idx = Index(["c", "a", "b"])
108
+ sorted_ = Index(["a", "b", "c"])
109
+ tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
110
+
111
+ def test_intersection_base(self, sort):
112
+ # (same results for py2 and py3 but sortedness not tested elsewhere)
113
+ index = Index([0, "a", 1, "b", 2, "c"])
114
+ first = index[:5]
115
+ second = index[:3]
116
+
117
+ expected = Index([0, 1, "a"]) if sort is None else Index([0, "a", 1])
118
+ result = first.intersection(second, sort=sort)
119
+ tm.assert_index_equal(result, expected)
120
+
121
+ @pytest.mark.parametrize("klass", [np.array, Series, list])
122
+ def test_intersection_different_type_base(self, klass, sort):
123
+ # GH 10149
124
+ index = Index([0, "a", 1, "b", 2, "c"])
125
+ first = index[:5]
126
+ second = index[:3]
127
+
128
+ result = first.intersection(klass(second.values), sort=sort)
129
+ assert equal_contents(result, second)
130
+
131
+ def test_intersection_nosort(self):
132
+ result = Index(["c", "b", "a"]).intersection(["b", "a"])
133
+ expected = Index(["b", "a"])
134
+ tm.assert_index_equal(result, expected)
135
+
136
+ def test_intersection_equal_sort(self):
137
+ idx = Index(["c", "a", "b"])
138
+ tm.assert_index_equal(idx.intersection(idx, sort=False), idx)
139
+ tm.assert_index_equal(idx.intersection(idx, sort=None), idx)
140
+
141
+ def test_intersection_str_dates(self, sort):
142
+ dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)]
143
+
144
+ i1 = Index(dt_dates, dtype=object)
145
+ i2 = Index(["aa"], dtype=object)
146
+ result = i2.intersection(i1, sort=sort)
147
+
148
+ assert len(result) == 0
149
+
150
+ @pytest.mark.parametrize(
151
+ "index2,expected_arr",
152
+ [(Index(["B", "D"]), ["B"]), (Index(["B", "D", "A"]), ["A", "B"])],
153
+ )
154
+ def test_intersection_non_monotonic_non_unique(self, index2, expected_arr, sort):
155
+ # non-monotonic non-unique
156
+ index1 = Index(["A", "B", "A", "C"])
157
+ expected = Index(expected_arr)
158
+ result = index1.intersection(index2, sort=sort)
159
+ if sort is None:
160
+ expected = expected.sort_values()
161
+ tm.assert_index_equal(result, expected)
162
+
163
+ def test_difference_base(self, sort):
164
+ # (same results for py2 and py3 but sortedness not tested elsewhere)
165
+ index = Index([0, "a", 1, "b", 2, "c"])
166
+ first = index[:4]
167
+ second = index[3:]
168
+
169
+ result = first.difference(second, sort)
170
+ expected = Index([0, "a", 1])
171
+ if sort is None:
172
+ expected = Index(safe_sort(expected))
173
+ tm.assert_index_equal(result, expected)
174
+
175
+ def test_symmetric_difference(self):
176
+ # (same results for py2 and py3 but sortedness not tested elsewhere)
177
+ index = Index([0, "a", 1, "b", 2, "c"])
178
+ first = index[:4]
179
+ second = index[3:]
180
+
181
+ result = first.symmetric_difference(second)
182
+ expected = Index([0, 1, 2, "a", "c"])
183
+ tm.assert_index_equal(result, expected)
184
+
185
+ @pytest.mark.parametrize(
186
+ "method,expected,sort",
187
+ [
188
+ (
189
+ "intersection",
190
+ np.array(
191
+ [(1, "A"), (2, "A"), (1, "B"), (2, "B")],
192
+ dtype=[("num", int), ("let", "S1")],
193
+ ),
194
+ False,
195
+ ),
196
+ (
197
+ "intersection",
198
+ np.array(
199
+ [(1, "A"), (1, "B"), (2, "A"), (2, "B")],
200
+ dtype=[("num", int), ("let", "S1")],
201
+ ),
202
+ None,
203
+ ),
204
+ (
205
+ "union",
206
+ np.array(
207
+ [(1, "A"), (1, "B"), (1, "C"), (2, "A"), (2, "B"), (2, "C")],
208
+ dtype=[("num", int), ("let", "S1")],
209
+ ),
210
+ None,
211
+ ),
212
+ ],
213
+ )
214
+ def test_tuple_union_bug(self, method, expected, sort):
215
+ index1 = Index(
216
+ np.array(
217
+ [(1, "A"), (2, "A"), (1, "B"), (2, "B")],
218
+ dtype=[("num", int), ("let", "S1")],
219
+ )
220
+ )
221
+ index2 = Index(
222
+ np.array(
223
+ [(1, "A"), (2, "A"), (1, "B"), (2, "B"), (1, "C"), (2, "C")],
224
+ dtype=[("num", int), ("let", "S1")],
225
+ )
226
+ )
227
+
228
+ result = getattr(index1, method)(index2, sort=sort)
229
+ assert result.ndim == 1
230
+
231
+ expected = Index(expected)
232
+ tm.assert_index_equal(result, expected)
233
+
234
+ @pytest.mark.parametrize("first_list", [["b", "a"], []])
235
+ @pytest.mark.parametrize("second_list", [["a", "b"], []])
236
+ @pytest.mark.parametrize(
237
+ "first_name, second_name, expected_name",
238
+ [("A", "B", None), (None, "B", None), ("A", None, None)],
239
+ )
240
+ def test_union_name_preservation(
241
+ self, first_list, second_list, first_name, second_name, expected_name, sort
242
+ ):
243
+ first = Index(first_list, name=first_name)
244
+ second = Index(second_list, name=second_name)
245
+ union = first.union(second, sort=sort)
246
+
247
+ vals = set(first_list).union(second_list)
248
+
249
+ if sort is None and len(first_list) > 0 and len(second_list) > 0:
250
+ expected = Index(sorted(vals), name=expected_name)
251
+ tm.assert_index_equal(union, expected)
252
+ else:
253
+ expected = Index(vals, name=expected_name)
254
+ tm.assert_index_equal(union.sort_values(), expected.sort_values())
255
+
256
+ @pytest.mark.parametrize(
257
+ "diff_type, expected",
258
+ [["difference", [1, "B"]], ["symmetric_difference", [1, 2, "B", "C"]]],
259
+ )
260
+ def test_difference_object_type(self, diff_type, expected):
261
+ # GH 13432
262
+ idx1 = Index([0, 1, "A", "B"])
263
+ idx2 = Index([0, 2, "A", "C"])
264
+ result = getattr(idx1, diff_type)(idx2)
265
+ expected = Index(expected)
266
+ tm.assert_index_equal(result, expected)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_where.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from pandas import Index
4
+ import pandas._testing as tm
5
+
6
+
7
+ class TestWhere:
8
+ def test_where_intlike_str_doesnt_cast_ints(self):
9
+ idx = Index(range(3))
10
+ mask = np.array([True, False, True])
11
+ res = idx.where(mask, "2")
12
+ expected = Index([0, "2", 2])
13
+ tm.assert_index_equal(res, expected)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__init__.py ADDED
File without changes
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (182 Bytes). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_append.cpython-310.pyc ADDED
Binary file (2.74 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_astype.cpython-310.pyc ADDED
Binary file (2.34 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_category.cpython-310.pyc ADDED
Binary file (11.5 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_constructors.cpython-310.pyc ADDED
Binary file (3.89 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_equals.cpython-310.pyc ADDED
Binary file (3.05 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_fillna.cpython-310.pyc ADDED
Binary file (1.81 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_formats.cpython-310.pyc ADDED
Binary file (5.37 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_indexing.cpython-310.pyc ADDED
Binary file (13 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_map.cpython-310.pyc ADDED
Binary file (3.72 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_reindex.cpython-310.pyc ADDED
Binary file (3.18 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_setops.cpython-310.pyc ADDED
Binary file (713 Bytes). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_append.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import (
4
+ CategoricalIndex,
5
+ Index,
6
+ )
7
+ import pandas._testing as tm
8
+
9
+
10
+ class TestAppend:
11
+ @pytest.fixture
12
+ def ci(self):
13
+ categories = list("cab")
14
+ return CategoricalIndex(list("aabbca"), categories=categories, ordered=False)
15
+
16
+ def test_append(self, ci):
17
+ # append cats with the same categories
18
+ result = ci[:3].append(ci[3:])
19
+ tm.assert_index_equal(result, ci, exact=True)
20
+
21
+ foos = [ci[:1], ci[1:3], ci[3:]]
22
+ result = foos[0].append(foos[1:])
23
+ tm.assert_index_equal(result, ci, exact=True)
24
+
25
+ def test_append_empty(self, ci):
26
+ # empty
27
+ result = ci.append([])
28
+ tm.assert_index_equal(result, ci, exact=True)
29
+
30
+ def test_append_mismatched_categories(self, ci):
31
+ # appending with different categories or reordered is not ok
32
+ msg = "all inputs must be Index"
33
+ with pytest.raises(TypeError, match=msg):
34
+ ci.append(ci.values.set_categories(list("abcd")))
35
+ with pytest.raises(TypeError, match=msg):
36
+ ci.append(ci.values.reorder_categories(list("abc")))
37
+
38
+ def test_append_category_objects(self, ci):
39
+ # with objects
40
+ result = ci.append(Index(["c", "a"]))
41
+ expected = CategoricalIndex(list("aabbcaca"), categories=ci.categories)
42
+ tm.assert_index_equal(result, expected, exact=True)
43
+
44
+ def test_append_non_categories(self, ci):
45
+ # invalid objects -> cast to object via concat_compat
46
+ result = ci.append(Index(["a", "d"]))
47
+ expected = Index(["a", "a", "b", "b", "c", "a", "a", "d"])
48
+ tm.assert_index_equal(result, expected, exact=True)
49
+
50
+ def test_append_object(self, ci):
51
+ # GH#14298 - if base object is not categorical -> coerce to object
52
+ result = Index(["c", "a"]).append(ci)
53
+ expected = Index(list("caaabbca"))
54
+ tm.assert_index_equal(result, expected, exact=True)
55
+
56
+ def test_append_to_another(self):
57
+ # hits Index._concat
58
+ fst = Index(["a", "b"])
59
+ snd = CategoricalIndex(["d", "e"])
60
+ result = fst.append(snd)
61
+ expected = Index(["a", "b", "d", "e"])
62
+ tm.assert_index_equal(result, expected)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_astype.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import date
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ from pandas import (
7
+ Categorical,
8
+ CategoricalDtype,
9
+ CategoricalIndex,
10
+ Index,
11
+ IntervalIndex,
12
+ )
13
+ import pandas._testing as tm
14
+
15
+
16
+ class TestAstype:
17
+ def test_astype(self):
18
+ ci = CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False)
19
+
20
+ result = ci.astype(object)
21
+ tm.assert_index_equal(result, Index(np.array(ci), dtype=object))
22
+
23
+ # this IS equal, but not the same class
24
+ assert result.equals(ci)
25
+ assert isinstance(result, Index)
26
+ assert not isinstance(result, CategoricalIndex)
27
+
28
+ # interval
29
+ ii = IntervalIndex.from_arrays(left=[-0.001, 2.0], right=[2, 4], closed="right")
30
+
31
+ ci = CategoricalIndex(
32
+ Categorical.from_codes([0, 1, -1], categories=ii, ordered=True)
33
+ )
34
+
35
+ result = ci.astype("interval")
36
+ expected = ii.take([0, 1, -1], allow_fill=True, fill_value=np.nan)
37
+ tm.assert_index_equal(result, expected)
38
+
39
+ result = IntervalIndex(result.values)
40
+ tm.assert_index_equal(result, expected)
41
+
42
+ @pytest.mark.parametrize("name", [None, "foo"])
43
+ @pytest.mark.parametrize("dtype_ordered", [True, False])
44
+ @pytest.mark.parametrize("index_ordered", [True, False])
45
+ def test_astype_category(self, name, dtype_ordered, index_ordered):
46
+ # GH#18630
47
+ index = CategoricalIndex(
48
+ list("aabbca"), categories=list("cab"), ordered=index_ordered
49
+ )
50
+ if name:
51
+ index = index.rename(name)
52
+
53
+ # standard categories
54
+ dtype = CategoricalDtype(ordered=dtype_ordered)
55
+ result = index.astype(dtype)
56
+ expected = CategoricalIndex(
57
+ index.tolist(),
58
+ name=name,
59
+ categories=index.categories,
60
+ ordered=dtype_ordered,
61
+ )
62
+ tm.assert_index_equal(result, expected)
63
+
64
+ # non-standard categories
65
+ dtype = CategoricalDtype(index.unique().tolist()[:-1], dtype_ordered)
66
+ result = index.astype(dtype)
67
+ expected = CategoricalIndex(index.tolist(), name=name, dtype=dtype)
68
+ tm.assert_index_equal(result, expected)
69
+
70
+ if dtype_ordered is False:
71
+ # dtype='category' can't specify ordered, so only test once
72
+ result = index.astype("category")
73
+ expected = index
74
+ tm.assert_index_equal(result, expected)
75
+
76
+ @pytest.mark.parametrize("box", [True, False])
77
+ def test_categorical_date_roundtrip(self, box):
78
+ # astype to categorical and back should preserve date objects
79
+ v = date.today()
80
+
81
+ obj = Index([v, v])
82
+ assert obj.dtype == object
83
+ if box:
84
+ obj = obj.array
85
+
86
+ cat = obj.astype("category")
87
+
88
+ rtrip = cat.astype(object)
89
+ assert rtrip.dtype == object
90
+ assert type(rtrip[0]) is date
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_category.py ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas._config import using_pyarrow_string_dtype
5
+
6
+ from pandas._libs import index as libindex
7
+ from pandas._libs.arrays import NDArrayBacked
8
+
9
+ import pandas as pd
10
+ from pandas import (
11
+ Categorical,
12
+ CategoricalDtype,
13
+ )
14
+ import pandas._testing as tm
15
+ from pandas.core.indexes.api import (
16
+ CategoricalIndex,
17
+ Index,
18
+ )
19
+
20
+
21
+ class TestCategoricalIndex:
22
+ @pytest.fixture
23
+ def simple_index(self) -> CategoricalIndex:
24
+ return CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False)
25
+
26
+ def test_can_hold_identifiers(self):
27
+ idx = CategoricalIndex(list("aabbca"), categories=None, ordered=False)
28
+ key = idx[0]
29
+ assert idx._can_hold_identifiers_and_holds_name(key) is True
30
+
31
+ def test_insert(self, simple_index):
32
+ ci = simple_index
33
+ categories = ci.categories
34
+
35
+ # test 0th element
36
+ result = ci.insert(0, "a")
37
+ expected = CategoricalIndex(list("aaabbca"), categories=categories)
38
+ tm.assert_index_equal(result, expected, exact=True)
39
+
40
+ # test Nth element that follows Python list behavior
41
+ result = ci.insert(-1, "a")
42
+ expected = CategoricalIndex(list("aabbcaa"), categories=categories)
43
+ tm.assert_index_equal(result, expected, exact=True)
44
+
45
+ # test empty
46
+ result = CategoricalIndex([], categories=categories).insert(0, "a")
47
+ expected = CategoricalIndex(["a"], categories=categories)
48
+ tm.assert_index_equal(result, expected, exact=True)
49
+
50
+ # invalid -> cast to object
51
+ expected = ci.astype(object).insert(0, "d")
52
+ result = ci.insert(0, "d").astype(object)
53
+ tm.assert_index_equal(result, expected, exact=True)
54
+
55
+ # GH 18295 (test missing)
56
+ expected = CategoricalIndex(["a", np.nan, "a", "b", "c", "b"])
57
+ for na in (np.nan, pd.NaT, None):
58
+ result = CategoricalIndex(list("aabcb")).insert(1, na)
59
+ tm.assert_index_equal(result, expected)
60
+
61
+ def test_insert_na_mismatched_dtype(self):
62
+ ci = CategoricalIndex([0, 1, 1])
63
+ result = ci.insert(0, pd.NaT)
64
+ expected = Index([pd.NaT, 0, 1, 1], dtype=object)
65
+ tm.assert_index_equal(result, expected)
66
+
67
+ def test_delete(self, simple_index):
68
+ ci = simple_index
69
+ categories = ci.categories
70
+
71
+ result = ci.delete(0)
72
+ expected = CategoricalIndex(list("abbca"), categories=categories)
73
+ tm.assert_index_equal(result, expected, exact=True)
74
+
75
+ result = ci.delete(-1)
76
+ expected = CategoricalIndex(list("aabbc"), categories=categories)
77
+ tm.assert_index_equal(result, expected, exact=True)
78
+
79
+ with tm.external_error_raised((IndexError, ValueError)):
80
+ # Either depending on NumPy version
81
+ ci.delete(10)
82
+
83
+ @pytest.mark.parametrize(
84
+ "data, non_lexsorted_data",
85
+ [[[1, 2, 3], [9, 0, 1, 2, 3]], [list("abc"), list("fabcd")]],
86
+ )
87
+ def test_is_monotonic(self, data, non_lexsorted_data):
88
+ c = CategoricalIndex(data)
89
+ assert c.is_monotonic_increasing is True
90
+ assert c.is_monotonic_decreasing is False
91
+
92
+ c = CategoricalIndex(data, ordered=True)
93
+ assert c.is_monotonic_increasing is True
94
+ assert c.is_monotonic_decreasing is False
95
+
96
+ c = CategoricalIndex(data, categories=reversed(data))
97
+ assert c.is_monotonic_increasing is False
98
+ assert c.is_monotonic_decreasing is True
99
+
100
+ c = CategoricalIndex(data, categories=reversed(data), ordered=True)
101
+ assert c.is_monotonic_increasing is False
102
+ assert c.is_monotonic_decreasing is True
103
+
104
+ # test when data is neither monotonic increasing nor decreasing
105
+ reordered_data = [data[0], data[2], data[1]]
106
+ c = CategoricalIndex(reordered_data, categories=reversed(data))
107
+ assert c.is_monotonic_increasing is False
108
+ assert c.is_monotonic_decreasing is False
109
+
110
+ # non lexsorted categories
111
+ categories = non_lexsorted_data
112
+
113
+ c = CategoricalIndex(categories[:2], categories=categories)
114
+ assert c.is_monotonic_increasing is True
115
+ assert c.is_monotonic_decreasing is False
116
+
117
+ c = CategoricalIndex(categories[1:3], categories=categories)
118
+ assert c.is_monotonic_increasing is True
119
+ assert c.is_monotonic_decreasing is False
120
+
121
+ def test_has_duplicates(self):
122
+ idx = CategoricalIndex([0, 0, 0], name="foo")
123
+ assert idx.is_unique is False
124
+ assert idx.has_duplicates is True
125
+
126
+ idx = CategoricalIndex([0, 1], categories=[2, 3], name="foo")
127
+ assert idx.is_unique is False
128
+ assert idx.has_duplicates is True
129
+
130
+ idx = CategoricalIndex([0, 1, 2, 3], categories=[1, 2, 3], name="foo")
131
+ assert idx.is_unique is True
132
+ assert idx.has_duplicates is False
133
+
134
+ @pytest.mark.parametrize(
135
+ "data, categories, expected",
136
+ [
137
+ (
138
+ [1, 1, 1],
139
+ [1, 2, 3],
140
+ {
141
+ "first": np.array([False, True, True]),
142
+ "last": np.array([True, True, False]),
143
+ False: np.array([True, True, True]),
144
+ },
145
+ ),
146
+ (
147
+ [1, 1, 1],
148
+ list("abc"),
149
+ {
150
+ "first": np.array([False, True, True]),
151
+ "last": np.array([True, True, False]),
152
+ False: np.array([True, True, True]),
153
+ },
154
+ ),
155
+ (
156
+ [2, "a", "b"],
157
+ list("abc"),
158
+ {
159
+ "first": np.zeros(shape=(3), dtype=np.bool_),
160
+ "last": np.zeros(shape=(3), dtype=np.bool_),
161
+ False: np.zeros(shape=(3), dtype=np.bool_),
162
+ },
163
+ ),
164
+ (
165
+ list("abb"),
166
+ list("abc"),
167
+ {
168
+ "first": np.array([False, False, True]),
169
+ "last": np.array([False, True, False]),
170
+ False: np.array([False, True, True]),
171
+ },
172
+ ),
173
+ ],
174
+ )
175
+ def test_drop_duplicates(self, data, categories, expected):
176
+ idx = CategoricalIndex(data, categories=categories, name="foo")
177
+ for keep, e in expected.items():
178
+ tm.assert_numpy_array_equal(idx.duplicated(keep=keep), e)
179
+ e = idx[~e]
180
+ result = idx.drop_duplicates(keep=keep)
181
+ tm.assert_index_equal(result, e)
182
+
183
+ @pytest.mark.parametrize(
184
+ "data, categories, expected_data",
185
+ [
186
+ ([1, 1, 1], [1, 2, 3], [1]),
187
+ ([1, 1, 1], list("abc"), [np.nan]),
188
+ ([1, 2, "a"], [1, 2, 3], [1, 2, np.nan]),
189
+ ([2, "a", "b"], list("abc"), [np.nan, "a", "b"]),
190
+ ],
191
+ )
192
+ def test_unique(self, data, categories, expected_data, ordered):
193
+ dtype = CategoricalDtype(categories, ordered=ordered)
194
+
195
+ idx = CategoricalIndex(data, dtype=dtype)
196
+ expected = CategoricalIndex(expected_data, dtype=dtype)
197
+ tm.assert_index_equal(idx.unique(), expected)
198
+
199
+ @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="repr doesn't roundtrip")
200
+ def test_repr_roundtrip(self):
201
+ ci = CategoricalIndex(["a", "b"], categories=["a", "b"], ordered=True)
202
+ str(ci)
203
+ tm.assert_index_equal(eval(repr(ci)), ci, exact=True)
204
+
205
+ # formatting
206
+ str(ci)
207
+
208
+ # long format
209
+ # this is not reprable
210
+ ci = CategoricalIndex(np.random.default_rng(2).integers(0, 5, size=100))
211
+ str(ci)
212
+
213
+ def test_isin(self):
214
+ ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"])
215
+ tm.assert_numpy_array_equal(
216
+ ci.isin(["c"]), np.array([False, False, False, True, False, False])
217
+ )
218
+ tm.assert_numpy_array_equal(
219
+ ci.isin(["c", "a", "b"]), np.array([True] * 5 + [False])
220
+ )
221
+ tm.assert_numpy_array_equal(
222
+ ci.isin(["c", "a", "b", np.nan]), np.array([True] * 6)
223
+ )
224
+
225
+ # mismatched categorical -> coerced to ndarray so doesn't matter
226
+ result = ci.isin(ci.set_categories(list("abcdefghi")))
227
+ expected = np.array([True] * 6)
228
+ tm.assert_numpy_array_equal(result, expected)
229
+
230
+ result = ci.isin(ci.set_categories(list("defghi")))
231
+ expected = np.array([False] * 5 + [True])
232
+ tm.assert_numpy_array_equal(result, expected)
233
+
234
+ def test_isin_overlapping_intervals(self):
235
+ # GH 34974
236
+ idx = pd.IntervalIndex([pd.Interval(0, 2), pd.Interval(0, 1)])
237
+ result = CategoricalIndex(idx).isin(idx)
238
+ expected = np.array([True, True])
239
+ tm.assert_numpy_array_equal(result, expected)
240
+
241
+ def test_identical(self):
242
+ ci1 = CategoricalIndex(["a", "b"], categories=["a", "b"], ordered=True)
243
+ ci2 = CategoricalIndex(["a", "b"], categories=["a", "b", "c"], ordered=True)
244
+ assert ci1.identical(ci1)
245
+ assert ci1.identical(ci1.copy())
246
+ assert not ci1.identical(ci2)
247
+
248
+ def test_ensure_copied_data(self):
249
+ # gh-12309: Check the "copy" argument of each
250
+ # Index.__new__ is honored.
251
+ #
252
+ # Must be tested separately from other indexes because
253
+ # self.values is not an ndarray.
254
+ index = CategoricalIndex(list("ab") * 5)
255
+
256
+ result = CategoricalIndex(index.values, copy=True)
257
+ tm.assert_index_equal(index, result)
258
+ assert not np.shares_memory(result._data._codes, index._data._codes)
259
+
260
+ result = CategoricalIndex(index.values, copy=False)
261
+ assert result._data._codes is index._data._codes
262
+
263
+
264
+ class TestCategoricalIndex2:
265
+ def test_view_i8(self):
266
+ # GH#25464
267
+ ci = CategoricalIndex(list("ab") * 50)
268
+ msg = "When changing to a larger dtype, its size must be a divisor"
269
+ with pytest.raises(ValueError, match=msg):
270
+ ci.view("i8")
271
+ with pytest.raises(ValueError, match=msg):
272
+ ci._data.view("i8")
273
+
274
+ ci = ci[:-4] # length divisible by 8
275
+
276
+ res = ci.view("i8")
277
+ expected = ci._data.codes.view("i8")
278
+ tm.assert_numpy_array_equal(res, expected)
279
+
280
+ cat = ci._data
281
+ tm.assert_numpy_array_equal(cat.view("i8"), expected)
282
+
283
+ @pytest.mark.parametrize(
284
+ "dtype, engine_type",
285
+ [
286
+ (np.int8, libindex.Int8Engine),
287
+ (np.int16, libindex.Int16Engine),
288
+ (np.int32, libindex.Int32Engine),
289
+ (np.int64, libindex.Int64Engine),
290
+ ],
291
+ )
292
+ def test_engine_type(self, dtype, engine_type):
293
+ if dtype != np.int64:
294
+ # num. of uniques required to push CategoricalIndex.codes to a
295
+ # dtype (128 categories required for .codes dtype to be int16 etc.)
296
+ num_uniques = {np.int8: 1, np.int16: 128, np.int32: 32768}[dtype]
297
+ ci = CategoricalIndex(range(num_uniques))
298
+ else:
299
+ # having 2**32 - 2**31 categories would be very memory-intensive,
300
+ # so we cheat a bit with the dtype
301
+ ci = CategoricalIndex(range(32768)) # == 2**16 - 2**(16 - 1)
302
+ arr = ci.values._ndarray.astype("int64")
303
+ NDArrayBacked.__init__(ci._data, arr, ci.dtype)
304
+ assert np.issubdtype(ci.codes.dtype, dtype)
305
+ assert isinstance(ci._engine, engine_type)
306
+
307
+ @pytest.mark.parametrize(
308
+ "func,op_name",
309
+ [
310
+ (lambda idx: idx - idx, "__sub__"),
311
+ (lambda idx: idx + idx, "__add__"),
312
+ (lambda idx: idx - ["a", "b"], "__sub__"),
313
+ (lambda idx: idx + ["a", "b"], "__add__"),
314
+ (lambda idx: ["a", "b"] - idx, "__rsub__"),
315
+ (lambda idx: ["a", "b"] + idx, "__radd__"),
316
+ ],
317
+ )
318
+ def test_disallow_addsub_ops(self, func, op_name):
319
+ # GH 10039
320
+ # set ops (+/-) raise TypeError
321
+ idx = Index(Categorical(["a", "b"]))
322
+ cat_or_list = "'(Categorical|list)' and '(Categorical|list)'"
323
+ msg = "|".join(
324
+ [
325
+ f"cannot perform {op_name} with this index type: CategoricalIndex",
326
+ "can only concatenate list",
327
+ rf"unsupported operand type\(s\) for [\+-]: {cat_or_list}",
328
+ ]
329
+ )
330
+ with pytest.raises(TypeError, match=msg):
331
+ func(idx)
332
+
333
+ def test_method_delegation(self):
334
+ ci = CategoricalIndex(list("aabbca"), categories=list("cabdef"))
335
+ result = ci.set_categories(list("cab"))
336
+ tm.assert_index_equal(
337
+ result, CategoricalIndex(list("aabbca"), categories=list("cab"))
338
+ )
339
+
340
+ ci = CategoricalIndex(list("aabbca"), categories=list("cab"))
341
+ result = ci.rename_categories(list("efg"))
342
+ tm.assert_index_equal(
343
+ result, CategoricalIndex(list("ffggef"), categories=list("efg"))
344
+ )
345
+
346
+ # GH18862 (let rename_categories take callables)
347
+ result = ci.rename_categories(lambda x: x.upper())
348
+ tm.assert_index_equal(
349
+ result, CategoricalIndex(list("AABBCA"), categories=list("CAB"))
350
+ )
351
+
352
+ ci = CategoricalIndex(list("aabbca"), categories=list("cab"))
353
+ result = ci.add_categories(["d"])
354
+ tm.assert_index_equal(
355
+ result, CategoricalIndex(list("aabbca"), categories=list("cabd"))
356
+ )
357
+
358
+ ci = CategoricalIndex(list("aabbca"), categories=list("cab"))
359
+ result = ci.remove_categories(["c"])
360
+ tm.assert_index_equal(
361
+ result,
362
+ CategoricalIndex(list("aabb") + [np.nan] + ["a"], categories=list("ab")),
363
+ )
364
+
365
+ ci = CategoricalIndex(list("aabbca"), categories=list("cabdef"))
366
+ result = ci.as_unordered()
367
+ tm.assert_index_equal(result, ci)
368
+
369
+ ci = CategoricalIndex(list("aabbca"), categories=list("cabdef"))
370
+ result = ci.as_ordered()
371
+ tm.assert_index_equal(
372
+ result,
373
+ CategoricalIndex(list("aabbca"), categories=list("cabdef"), ordered=True),
374
+ )
375
+
376
+ # invalid
377
+ msg = "cannot use inplace with CategoricalIndex"
378
+ with pytest.raises(ValueError, match=msg):
379
+ ci.set_categories(list("cab"), inplace=True)
380
+
381
+ def test_remove_maintains_order(self):
382
+ ci = CategoricalIndex(list("abcdda"), categories=list("abcd"))
383
+ result = ci.reorder_categories(["d", "c", "b", "a"], ordered=True)
384
+ tm.assert_index_equal(
385
+ result,
386
+ CategoricalIndex(list("abcdda"), categories=list("dcba"), ordered=True),
387
+ )
388
+ result = result.remove_categories(["c"])
389
+ tm.assert_index_equal(
390
+ result,
391
+ CategoricalIndex(
392
+ ["a", "b", np.nan, "d", "d", "a"], categories=list("dba"), ordered=True
393
+ ),
394
+ )
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_constructors.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Categorical,
6
+ CategoricalDtype,
7
+ CategoricalIndex,
8
+ Index,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestCategoricalIndexConstructors:
14
+ def test_construction_disallows_scalar(self):
15
+ msg = "must be called with a collection of some kind"
16
+ with pytest.raises(TypeError, match=msg):
17
+ CategoricalIndex(data=1, categories=list("abcd"), ordered=False)
18
+ with pytest.raises(TypeError, match=msg):
19
+ CategoricalIndex(categories=list("abcd"), ordered=False)
20
+
21
+ def test_construction(self):
22
+ ci = CategoricalIndex(list("aabbca"), categories=list("abcd"), ordered=False)
23
+ categories = ci.categories
24
+
25
+ result = Index(ci)
26
+ tm.assert_index_equal(result, ci, exact=True)
27
+ assert not result.ordered
28
+
29
+ result = Index(ci.values)
30
+ tm.assert_index_equal(result, ci, exact=True)
31
+ assert not result.ordered
32
+
33
+ # empty
34
+ result = CategoricalIndex([], categories=categories)
35
+ tm.assert_index_equal(result.categories, Index(categories))
36
+ tm.assert_numpy_array_equal(result.codes, np.array([], dtype="int8"))
37
+ assert not result.ordered
38
+
39
+ # passing categories
40
+ result = CategoricalIndex(list("aabbca"), categories=categories)
41
+ tm.assert_index_equal(result.categories, Index(categories))
42
+ tm.assert_numpy_array_equal(
43
+ result.codes, np.array([0, 0, 1, 1, 2, 0], dtype="int8")
44
+ )
45
+
46
+ c = Categorical(list("aabbca"))
47
+ result = CategoricalIndex(c)
48
+ tm.assert_index_equal(result.categories, Index(list("abc")))
49
+ tm.assert_numpy_array_equal(
50
+ result.codes, np.array([0, 0, 1, 1, 2, 0], dtype="int8")
51
+ )
52
+ assert not result.ordered
53
+
54
+ result = CategoricalIndex(c, categories=categories)
55
+ tm.assert_index_equal(result.categories, Index(categories))
56
+ tm.assert_numpy_array_equal(
57
+ result.codes, np.array([0, 0, 1, 1, 2, 0], dtype="int8")
58
+ )
59
+ assert not result.ordered
60
+
61
+ ci = CategoricalIndex(c, categories=list("abcd"))
62
+ result = CategoricalIndex(ci)
63
+ tm.assert_index_equal(result.categories, Index(categories))
64
+ tm.assert_numpy_array_equal(
65
+ result.codes, np.array([0, 0, 1, 1, 2, 0], dtype="int8")
66
+ )
67
+ assert not result.ordered
68
+
69
+ result = CategoricalIndex(ci, categories=list("ab"))
70
+ tm.assert_index_equal(result.categories, Index(list("ab")))
71
+ tm.assert_numpy_array_equal(
72
+ result.codes, np.array([0, 0, 1, 1, -1, 0], dtype="int8")
73
+ )
74
+ assert not result.ordered
75
+
76
+ result = CategoricalIndex(ci, categories=list("ab"), ordered=True)
77
+ tm.assert_index_equal(result.categories, Index(list("ab")))
78
+ tm.assert_numpy_array_equal(
79
+ result.codes, np.array([0, 0, 1, 1, -1, 0], dtype="int8")
80
+ )
81
+ assert result.ordered
82
+
83
+ result = CategoricalIndex(ci, categories=list("ab"), ordered=True)
84
+ expected = CategoricalIndex(
85
+ ci, categories=list("ab"), ordered=True, dtype="category"
86
+ )
87
+ tm.assert_index_equal(result, expected, exact=True)
88
+
89
+ # turn me to an Index
90
+ result = Index(np.array(ci))
91
+ assert isinstance(result, Index)
92
+ assert not isinstance(result, CategoricalIndex)
93
+
94
+ def test_construction_with_dtype(self):
95
+ # specify dtype
96
+ ci = CategoricalIndex(list("aabbca"), categories=list("abc"), ordered=False)
97
+
98
+ result = Index(np.array(ci), dtype="category")
99
+ tm.assert_index_equal(result, ci, exact=True)
100
+
101
+ result = Index(np.array(ci).tolist(), dtype="category")
102
+ tm.assert_index_equal(result, ci, exact=True)
103
+
104
+ # these are generally only equal when the categories are reordered
105
+ ci = CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False)
106
+
107
+ result = Index(np.array(ci), dtype="category").reorder_categories(ci.categories)
108
+ tm.assert_index_equal(result, ci, exact=True)
109
+
110
+ # make sure indexes are handled
111
+ idx = Index(range(3))
112
+ expected = CategoricalIndex([0, 1, 2], categories=idx, ordered=True)
113
+ result = CategoricalIndex(idx, categories=idx, ordered=True)
114
+ tm.assert_index_equal(result, expected, exact=True)
115
+
116
+ def test_construction_empty_with_bool_categories(self):
117
+ # see GH#22702
118
+ cat = CategoricalIndex([], categories=[True, False])
119
+ categories = sorted(cat.categories.tolist())
120
+ assert categories == [False, True]
121
+
122
+ def test_construction_with_categorical_dtype(self):
123
+ # construction with CategoricalDtype
124
+ # GH#18109
125
+ data, cats, ordered = "a a b b".split(), "c b a".split(), True
126
+ dtype = CategoricalDtype(categories=cats, ordered=ordered)
127
+
128
+ result = CategoricalIndex(data, dtype=dtype)
129
+ expected = CategoricalIndex(data, categories=cats, ordered=ordered)
130
+ tm.assert_index_equal(result, expected, exact=True)
131
+
132
+ # GH#19032
133
+ result = Index(data, dtype=dtype)
134
+ tm.assert_index_equal(result, expected, exact=True)
135
+
136
+ # error when combining categories/ordered and dtype kwargs
137
+ msg = "Cannot specify `categories` or `ordered` together with `dtype`."
138
+ with pytest.raises(ValueError, match=msg):
139
+ CategoricalIndex(data, categories=cats, dtype=dtype)
140
+
141
+ with pytest.raises(ValueError, match=msg):
142
+ CategoricalIndex(data, ordered=ordered, dtype=dtype)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_equals.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Categorical,
6
+ CategoricalIndex,
7
+ Index,
8
+ MultiIndex,
9
+ )
10
+
11
+
12
+ class TestEquals:
13
+ def test_equals_categorical(self):
14
+ ci1 = CategoricalIndex(["a", "b"], categories=["a", "b"], ordered=True)
15
+ ci2 = CategoricalIndex(["a", "b"], categories=["a", "b", "c"], ordered=True)
16
+
17
+ assert ci1.equals(ci1)
18
+ assert not ci1.equals(ci2)
19
+ assert ci1.equals(ci1.astype(object))
20
+ assert ci1.astype(object).equals(ci1)
21
+
22
+ assert (ci1 == ci1).all()
23
+ assert not (ci1 != ci1).all()
24
+ assert not (ci1 > ci1).all()
25
+ assert not (ci1 < ci1).all()
26
+ assert (ci1 <= ci1).all()
27
+ assert (ci1 >= ci1).all()
28
+
29
+ assert not (ci1 == 1).all()
30
+ assert (ci1 == Index(["a", "b"])).all()
31
+ assert (ci1 == ci1.values).all()
32
+
33
+ # invalid comparisons
34
+ with pytest.raises(ValueError, match="Lengths must match"):
35
+ ci1 == Index(["a", "b", "c"])
36
+
37
+ msg = "Categoricals can only be compared if 'categories' are the same"
38
+ with pytest.raises(TypeError, match=msg):
39
+ ci1 == ci2
40
+ with pytest.raises(TypeError, match=msg):
41
+ ci1 == Categorical(ci1.values, ordered=False)
42
+ with pytest.raises(TypeError, match=msg):
43
+ ci1 == Categorical(ci1.values, categories=list("abc"))
44
+
45
+ # tests
46
+ # make sure that we are testing for category inclusion properly
47
+ ci = CategoricalIndex(list("aabca"), categories=["c", "a", "b"])
48
+ assert not ci.equals(list("aabca"))
49
+ # Same categories, but different order
50
+ # Unordered
51
+ assert ci.equals(CategoricalIndex(list("aabca")))
52
+ # Ordered
53
+ assert not ci.equals(CategoricalIndex(list("aabca"), ordered=True))
54
+ assert ci.equals(ci.copy())
55
+
56
+ ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"])
57
+ assert not ci.equals(list("aabca"))
58
+ assert not ci.equals(CategoricalIndex(list("aabca")))
59
+ assert ci.equals(ci.copy())
60
+
61
+ ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"])
62
+ assert not ci.equals(list("aabca") + [np.nan])
63
+ assert ci.equals(CategoricalIndex(list("aabca") + [np.nan]))
64
+ assert not ci.equals(CategoricalIndex(list("aabca") + [np.nan], ordered=True))
65
+ assert ci.equals(ci.copy())
66
+
67
+ def test_equals_categorical_unordered(self):
68
+ # https://github.com/pandas-dev/pandas/issues/16603
69
+ a = CategoricalIndex(["A"], categories=["A", "B"])
70
+ b = CategoricalIndex(["A"], categories=["B", "A"])
71
+ c = CategoricalIndex(["C"], categories=["B", "A"])
72
+ assert a.equals(b)
73
+ assert not a.equals(c)
74
+ assert not b.equals(c)
75
+
76
+ def test_equals_non_category(self):
77
+ # GH#37667 Case where other contains a value not among ci's
78
+ # categories ("D") and also contains np.nan
79
+ ci = CategoricalIndex(["A", "B", np.nan, np.nan])
80
+ other = Index(["A", "B", "D", np.nan])
81
+
82
+ assert not ci.equals(other)
83
+
84
+ def test_equals_multiindex(self):
85
+ # dont raise NotImplementedError when calling is_dtype_compat
86
+
87
+ mi = MultiIndex.from_arrays([["A", "B", "C", "D"], range(4)])
88
+ ci = mi.to_flat_index().astype("category")
89
+
90
+ assert not ci.equals(mi)
91
+
92
+ def test_equals_string_dtype(self, any_string_dtype):
93
+ # GH#55364
94
+ idx = CategoricalIndex(list("abc"), name="B")
95
+ other = Index(["a", "b", "c"], name="B", dtype=any_string_dtype)
96
+ assert idx.equals(other)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_fillna.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import CategoricalIndex
5
+ import pandas._testing as tm
6
+
7
+
8
+ class TestFillNA:
9
+ def test_fillna_categorical(self):
10
+ # GH#11343
11
+ idx = CategoricalIndex([1.0, np.nan, 3.0, 1.0], name="x")
12
+ # fill by value in categories
13
+ exp = CategoricalIndex([1.0, 1.0, 3.0, 1.0], name="x")
14
+ tm.assert_index_equal(idx.fillna(1.0), exp)
15
+
16
+ cat = idx._data
17
+
18
+ # fill by value not in categories raises TypeError on EA, casts on CI
19
+ msg = "Cannot setitem on a Categorical with a new category"
20
+ with pytest.raises(TypeError, match=msg):
21
+ cat.fillna(2.0)
22
+
23
+ result = idx.fillna(2.0)
24
+ expected = idx.astype(object).fillna(2.0)
25
+ tm.assert_index_equal(result, expected)
26
+
27
+ def test_fillna_copies_with_no_nas(self):
28
+ # Nothing to fill, should still get a copy for the Categorical method,
29
+ # but OK to get a view on CategoricalIndex method
30
+ ci = CategoricalIndex([0, 1, 1])
31
+ result = ci.fillna(0)
32
+ assert result is not ci
33
+ assert tm.shares_memory(result, ci)
34
+
35
+ # But at the EA level we always get a copy.
36
+ cat = ci._data
37
+ result = cat.fillna(0)
38
+ assert result._ndarray is not cat._ndarray
39
+ assert result._ndarray.base is None
40
+ assert not tm.shares_memory(result, cat)
41
+
42
+ def test_fillna_validates_with_no_nas(self):
43
+ # We validate the fill value even if fillna is a no-op
44
+ ci = CategoricalIndex([2, 3, 3])
45
+ cat = ci._data
46
+
47
+ msg = "Cannot setitem on a Categorical with a new category"
48
+ res = ci.fillna(False)
49
+ # nothing to fill, so we dont cast
50
+ tm.assert_index_equal(res, ci)
51
+
52
+ # Same check directly on the Categorical
53
+ with pytest.raises(TypeError, match=msg):
54
+ cat.fillna(False)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_formats.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests for CategoricalIndex.__repr__ and related methods.
3
+ """
4
+ import pytest
5
+
6
+ from pandas._config import using_pyarrow_string_dtype
7
+ import pandas._config.config as cf
8
+
9
+ from pandas import CategoricalIndex
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestCategoricalIndexRepr:
14
+ def test_format_different_scalar_lengths(self):
15
+ # GH#35439
16
+ idx = CategoricalIndex(["aaaaaaaaa", "b"])
17
+ expected = ["aaaaaaaaa", "b"]
18
+ msg = r"CategoricalIndex\.format is deprecated"
19
+ with tm.assert_produces_warning(FutureWarning, match=msg):
20
+ assert idx.format() == expected
21
+
22
+ @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="repr different")
23
+ def test_string_categorical_index_repr(self):
24
+ # short
25
+ idx = CategoricalIndex(["a", "bb", "ccc"])
26
+ expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa: E501
27
+ assert repr(idx) == expected
28
+
29
+ # multiple lines
30
+ idx = CategoricalIndex(["a", "bb", "ccc"] * 10)
31
+ expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
32
+ 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb',
33
+ 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
34
+ categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa: E501
35
+
36
+ assert repr(idx) == expected
37
+
38
+ # truncated
39
+ idx = CategoricalIndex(["a", "bb", "ccc"] * 100)
40
+ expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',
41
+ ...
42
+ 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],
43
+ categories=['a', 'bb', 'ccc'], ordered=False, dtype='category', length=300)""" # noqa: E501
44
+
45
+ assert repr(idx) == expected
46
+
47
+ # larger categories
48
+ idx = CategoricalIndex(list("abcdefghijklmmo"))
49
+ expected = """CategoricalIndex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
50
+ 'm', 'm', 'o'],
51
+ categories=['a', 'b', 'c', 'd', ..., 'k', 'l', 'm', 'o'], ordered=False, dtype='category')""" # noqa: E501
52
+
53
+ assert repr(idx) == expected
54
+
55
+ # short
56
+ idx = CategoricalIndex(["あ", "いい", "ううう"])
57
+ expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
58
+ assert repr(idx) == expected
59
+
60
+ # multiple lines
61
+ idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
62
+ expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
63
+ 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
64
+ 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
65
+ categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
66
+
67
+ assert repr(idx) == expected
68
+
69
+ # truncated
70
+ idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
71
+ expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
72
+ ...
73
+ 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
74
+ categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa: E501
75
+
76
+ assert repr(idx) == expected
77
+
78
+ # larger categories
79
+ idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
80
+ expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し',
81
+ 'す', 'せ', 'そ'],
82
+ categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""" # noqa: E501
83
+
84
+ assert repr(idx) == expected
85
+
86
+ # Enable Unicode option -----------------------------------------
87
+ with cf.option_context("display.unicode.east_asian_width", True):
88
+ # short
89
+ idx = CategoricalIndex(["あ", "いい", "ううう"])
90
+ expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
91
+ assert repr(idx) == expected
92
+
93
+ # multiple lines
94
+ idx = CategoricalIndex(["あ", "いい", "ううう"] * 10)
95
+ expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
96
+ 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
97
+ 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
98
+ 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
99
+ categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
100
+
101
+ assert repr(idx) == expected
102
+
103
+ # truncated
104
+ idx = CategoricalIndex(["あ", "いい", "ううう"] * 100)
105
+ expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
106
+ 'ううう', 'あ',
107
+ ...
108
+ 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
109
+ 'あ', 'いい', 'ううう'],
110
+ categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa: E501
111
+
112
+ assert repr(idx) == expected
113
+
114
+ # larger categories
115
+ idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
116
+ expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ',
117
+ 'さ', 'し', 'す', 'せ', 'そ'],
118
+ categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""" # noqa: E501
119
+
120
+ assert repr(idx) == expected
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_indexing.py ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas.errors import InvalidIndexError
5
+
6
+ import pandas as pd
7
+ from pandas import (
8
+ CategoricalIndex,
9
+ Index,
10
+ IntervalIndex,
11
+ Timestamp,
12
+ )
13
+ import pandas._testing as tm
14
+
15
+
16
+ class TestTake:
17
+ def test_take_fill_value(self):
18
+ # GH 12631
19
+
20
+ # numeric category
21
+ idx = CategoricalIndex([1, 2, 3], name="xxx")
22
+ result = idx.take(np.array([1, 0, -1]))
23
+ expected = CategoricalIndex([2, 1, 3], name="xxx")
24
+ tm.assert_index_equal(result, expected)
25
+ tm.assert_categorical_equal(result.values, expected.values)
26
+
27
+ # fill_value
28
+ result = idx.take(np.array([1, 0, -1]), fill_value=True)
29
+ expected = CategoricalIndex([2, 1, np.nan], categories=[1, 2, 3], name="xxx")
30
+ tm.assert_index_equal(result, expected)
31
+ tm.assert_categorical_equal(result.values, expected.values)
32
+
33
+ # allow_fill=False
34
+ result = idx.take(np.array([1, 0, -1]), allow_fill=False, fill_value=True)
35
+ expected = CategoricalIndex([2, 1, 3], name="xxx")
36
+ tm.assert_index_equal(result, expected)
37
+ tm.assert_categorical_equal(result.values, expected.values)
38
+
39
+ # object category
40
+ idx = CategoricalIndex(
41
+ list("CBA"), categories=list("ABC"), ordered=True, name="xxx"
42
+ )
43
+ result = idx.take(np.array([1, 0, -1]))
44
+ expected = CategoricalIndex(
45
+ list("BCA"), categories=list("ABC"), ordered=True, name="xxx"
46
+ )
47
+ tm.assert_index_equal(result, expected)
48
+ tm.assert_categorical_equal(result.values, expected.values)
49
+
50
+ # fill_value
51
+ result = idx.take(np.array([1, 0, -1]), fill_value=True)
52
+ expected = CategoricalIndex(
53
+ ["B", "C", np.nan], categories=list("ABC"), ordered=True, name="xxx"
54
+ )
55
+ tm.assert_index_equal(result, expected)
56
+ tm.assert_categorical_equal(result.values, expected.values)
57
+
58
+ # allow_fill=False
59
+ result = idx.take(np.array([1, 0, -1]), allow_fill=False, fill_value=True)
60
+ expected = CategoricalIndex(
61
+ list("BCA"), categories=list("ABC"), ordered=True, name="xxx"
62
+ )
63
+ tm.assert_index_equal(result, expected)
64
+ tm.assert_categorical_equal(result.values, expected.values)
65
+
66
+ msg = (
67
+ "When allow_fill=True and fill_value is not None, "
68
+ "all indices must be >= -1"
69
+ )
70
+ with pytest.raises(ValueError, match=msg):
71
+ idx.take(np.array([1, 0, -2]), fill_value=True)
72
+ with pytest.raises(ValueError, match=msg):
73
+ idx.take(np.array([1, 0, -5]), fill_value=True)
74
+
75
+ msg = "index -5 is out of bounds for (axis 0 with )?size 3"
76
+ with pytest.raises(IndexError, match=msg):
77
+ idx.take(np.array([1, -5]))
78
+
79
+ def test_take_fill_value_datetime(self):
80
+ # datetime category
81
+ idx = pd.DatetimeIndex(["2011-01-01", "2011-02-01", "2011-03-01"], name="xxx")
82
+ idx = CategoricalIndex(idx)
83
+ result = idx.take(np.array([1, 0, -1]))
84
+ expected = pd.DatetimeIndex(
85
+ ["2011-02-01", "2011-01-01", "2011-03-01"], name="xxx"
86
+ )
87
+ expected = CategoricalIndex(expected)
88
+ tm.assert_index_equal(result, expected)
89
+
90
+ # fill_value
91
+ result = idx.take(np.array([1, 0, -1]), fill_value=True)
92
+ expected = pd.DatetimeIndex(["2011-02-01", "2011-01-01", "NaT"], name="xxx")
93
+ exp_cats = pd.DatetimeIndex(["2011-01-01", "2011-02-01", "2011-03-01"])
94
+ expected = CategoricalIndex(expected, categories=exp_cats)
95
+ tm.assert_index_equal(result, expected)
96
+
97
+ # allow_fill=False
98
+ result = idx.take(np.array([1, 0, -1]), allow_fill=False, fill_value=True)
99
+ expected = pd.DatetimeIndex(
100
+ ["2011-02-01", "2011-01-01", "2011-03-01"], name="xxx"
101
+ )
102
+ expected = CategoricalIndex(expected)
103
+ tm.assert_index_equal(result, expected)
104
+
105
+ msg = (
106
+ "When allow_fill=True and fill_value is not None, "
107
+ "all indices must be >= -1"
108
+ )
109
+ with pytest.raises(ValueError, match=msg):
110
+ idx.take(np.array([1, 0, -2]), fill_value=True)
111
+ with pytest.raises(ValueError, match=msg):
112
+ idx.take(np.array([1, 0, -5]), fill_value=True)
113
+
114
+ msg = "index -5 is out of bounds for (axis 0 with )?size 3"
115
+ with pytest.raises(IndexError, match=msg):
116
+ idx.take(np.array([1, -5]))
117
+
118
+ def test_take_invalid_kwargs(self):
119
+ idx = CategoricalIndex([1, 2, 3], name="foo")
120
+ indices = [1, 0, -1]
121
+
122
+ msg = r"take\(\) got an unexpected keyword argument 'foo'"
123
+ with pytest.raises(TypeError, match=msg):
124
+ idx.take(indices, foo=2)
125
+
126
+ msg = "the 'out' parameter is not supported"
127
+ with pytest.raises(ValueError, match=msg):
128
+ idx.take(indices, out=indices)
129
+
130
+ msg = "the 'mode' parameter is not supported"
131
+ with pytest.raises(ValueError, match=msg):
132
+ idx.take(indices, mode="clip")
133
+
134
+
135
+ class TestGetLoc:
136
+ def test_get_loc(self):
137
+ # GH 12531
138
+ cidx1 = CategoricalIndex(list("abcde"), categories=list("edabc"))
139
+ idx1 = Index(list("abcde"))
140
+ assert cidx1.get_loc("a") == idx1.get_loc("a")
141
+ assert cidx1.get_loc("e") == idx1.get_loc("e")
142
+
143
+ for i in [cidx1, idx1]:
144
+ with pytest.raises(KeyError, match="'NOT-EXIST'"):
145
+ i.get_loc("NOT-EXIST")
146
+
147
+ # non-unique
148
+ cidx2 = CategoricalIndex(list("aacded"), categories=list("edabc"))
149
+ idx2 = Index(list("aacded"))
150
+
151
+ # results in bool array
152
+ res = cidx2.get_loc("d")
153
+ tm.assert_numpy_array_equal(res, idx2.get_loc("d"))
154
+ tm.assert_numpy_array_equal(
155
+ res, np.array([False, False, False, True, False, True])
156
+ )
157
+ # unique element results in scalar
158
+ res = cidx2.get_loc("e")
159
+ assert res == idx2.get_loc("e")
160
+ assert res == 4
161
+
162
+ for i in [cidx2, idx2]:
163
+ with pytest.raises(KeyError, match="'NOT-EXIST'"):
164
+ i.get_loc("NOT-EXIST")
165
+
166
+ # non-unique, sliceable
167
+ cidx3 = CategoricalIndex(list("aabbb"), categories=list("abc"))
168
+ idx3 = Index(list("aabbb"))
169
+
170
+ # results in slice
171
+ res = cidx3.get_loc("a")
172
+ assert res == idx3.get_loc("a")
173
+ assert res == slice(0, 2, None)
174
+
175
+ res = cidx3.get_loc("b")
176
+ assert res == idx3.get_loc("b")
177
+ assert res == slice(2, 5, None)
178
+
179
+ for i in [cidx3, idx3]:
180
+ with pytest.raises(KeyError, match="'c'"):
181
+ i.get_loc("c")
182
+
183
+ def test_get_loc_unique(self):
184
+ cidx = CategoricalIndex(list("abc"))
185
+ result = cidx.get_loc("b")
186
+ assert result == 1
187
+
188
+ def test_get_loc_monotonic_nonunique(self):
189
+ cidx = CategoricalIndex(list("abbc"))
190
+ result = cidx.get_loc("b")
191
+ expected = slice(1, 3, None)
192
+ assert result == expected
193
+
194
+ def test_get_loc_nonmonotonic_nonunique(self):
195
+ cidx = CategoricalIndex(list("abcb"))
196
+ result = cidx.get_loc("b")
197
+ expected = np.array([False, True, False, True], dtype=bool)
198
+ tm.assert_numpy_array_equal(result, expected)
199
+
200
+ def test_get_loc_nan(self):
201
+ # GH#41933
202
+ ci = CategoricalIndex(["A", "B", np.nan])
203
+ res = ci.get_loc(np.nan)
204
+
205
+ assert res == 2
206
+
207
+
208
+ class TestGetIndexer:
209
+ def test_get_indexer_base(self):
210
+ # Determined by cat ordering.
211
+ idx = CategoricalIndex(list("cab"), categories=list("cab"))
212
+ expected = np.arange(len(idx), dtype=np.intp)
213
+
214
+ actual = idx.get_indexer(idx)
215
+ tm.assert_numpy_array_equal(expected, actual)
216
+
217
+ with pytest.raises(ValueError, match="Invalid fill method"):
218
+ idx.get_indexer(idx, method="invalid")
219
+
220
+ def test_get_indexer_requires_unique(self):
221
+ ci = CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False)
222
+ oidx = Index(np.array(ci))
223
+
224
+ msg = "Reindexing only valid with uniquely valued Index objects"
225
+
226
+ for n in [1, 2, 5, len(ci)]:
227
+ finder = oidx[np.random.default_rng(2).integers(0, len(ci), size=n)]
228
+
229
+ with pytest.raises(InvalidIndexError, match=msg):
230
+ ci.get_indexer(finder)
231
+
232
+ # see gh-17323
233
+ #
234
+ # Even when indexer is equal to the
235
+ # members in the index, we should
236
+ # respect duplicates instead of taking
237
+ # the fast-track path.
238
+ for finder in [list("aabbca"), list("aababca")]:
239
+ with pytest.raises(InvalidIndexError, match=msg):
240
+ ci.get_indexer(finder)
241
+
242
+ def test_get_indexer_non_unique(self):
243
+ idx1 = CategoricalIndex(list("aabcde"), categories=list("edabc"))
244
+ idx2 = CategoricalIndex(list("abf"))
245
+
246
+ for indexer in [idx2, list("abf"), Index(list("abf"))]:
247
+ msg = "Reindexing only valid with uniquely valued Index objects"
248
+ with pytest.raises(InvalidIndexError, match=msg):
249
+ idx1.get_indexer(indexer)
250
+
251
+ r1, _ = idx1.get_indexer_non_unique(indexer)
252
+ expected = np.array([0, 1, 2, -1], dtype=np.intp)
253
+ tm.assert_almost_equal(r1, expected)
254
+
255
+ def test_get_indexer_method(self):
256
+ idx1 = CategoricalIndex(list("aabcde"), categories=list("edabc"))
257
+ idx2 = CategoricalIndex(list("abf"))
258
+
259
+ msg = "method pad not yet implemented for CategoricalIndex"
260
+ with pytest.raises(NotImplementedError, match=msg):
261
+ idx2.get_indexer(idx1, method="pad")
262
+ msg = "method backfill not yet implemented for CategoricalIndex"
263
+ with pytest.raises(NotImplementedError, match=msg):
264
+ idx2.get_indexer(idx1, method="backfill")
265
+
266
+ msg = "method nearest not yet implemented for CategoricalIndex"
267
+ with pytest.raises(NotImplementedError, match=msg):
268
+ idx2.get_indexer(idx1, method="nearest")
269
+
270
+ def test_get_indexer_array(self):
271
+ arr = np.array(
272
+ [Timestamp("1999-12-31 00:00:00"), Timestamp("2000-12-31 00:00:00")],
273
+ dtype=object,
274
+ )
275
+ cats = [Timestamp("1999-12-31 00:00:00"), Timestamp("2000-12-31 00:00:00")]
276
+ ci = CategoricalIndex(cats, categories=cats, ordered=False, dtype="category")
277
+ result = ci.get_indexer(arr)
278
+ expected = np.array([0, 1], dtype="intp")
279
+ tm.assert_numpy_array_equal(result, expected)
280
+
281
+ def test_get_indexer_same_categories_same_order(self):
282
+ ci = CategoricalIndex(["a", "b"], categories=["a", "b"])
283
+
284
+ result = ci.get_indexer(CategoricalIndex(["b", "b"], categories=["a", "b"]))
285
+ expected = np.array([1, 1], dtype="intp")
286
+ tm.assert_numpy_array_equal(result, expected)
287
+
288
+ def test_get_indexer_same_categories_different_order(self):
289
+ # https://github.com/pandas-dev/pandas/issues/19551
290
+ ci = CategoricalIndex(["a", "b"], categories=["a", "b"])
291
+
292
+ result = ci.get_indexer(CategoricalIndex(["b", "b"], categories=["b", "a"]))
293
+ expected = np.array([1, 1], dtype="intp")
294
+ tm.assert_numpy_array_equal(result, expected)
295
+
296
+ def test_get_indexer_nans_in_index_and_target(self):
297
+ # GH 45361
298
+ ci = CategoricalIndex([1, 2, np.nan, 3])
299
+ other1 = [2, 3, 4, np.nan]
300
+ res1 = ci.get_indexer(other1)
301
+ expected1 = np.array([1, 3, -1, 2], dtype=np.intp)
302
+ tm.assert_numpy_array_equal(res1, expected1)
303
+ other2 = [1, 4, 2, 3]
304
+ res2 = ci.get_indexer(other2)
305
+ expected2 = np.array([0, -1, 1, 3], dtype=np.intp)
306
+ tm.assert_numpy_array_equal(res2, expected2)
307
+
308
+
309
+ class TestWhere:
310
+ def test_where(self, listlike_box):
311
+ klass = listlike_box
312
+
313
+ i = CategoricalIndex(list("aabbca"), categories=list("cab"), ordered=False)
314
+ cond = [True] * len(i)
315
+ expected = i
316
+ result = i.where(klass(cond))
317
+ tm.assert_index_equal(result, expected)
318
+
319
+ cond = [False] + [True] * (len(i) - 1)
320
+ expected = CategoricalIndex([np.nan] + i[1:].tolist(), categories=i.categories)
321
+ result = i.where(klass(cond))
322
+ tm.assert_index_equal(result, expected)
323
+
324
+ def test_where_non_categories(self):
325
+ ci = CategoricalIndex(["a", "b", "c", "d"])
326
+ mask = np.array([True, False, True, False])
327
+
328
+ result = ci.where(mask, 2)
329
+ expected = Index(["a", 2, "c", 2], dtype=object)
330
+ tm.assert_index_equal(result, expected)
331
+
332
+ msg = "Cannot setitem on a Categorical with a new category"
333
+ with pytest.raises(TypeError, match=msg):
334
+ # Test the Categorical method directly
335
+ ci._data._where(mask, 2)
336
+
337
+
338
+ class TestContains:
339
+ def test_contains(self):
340
+ ci = CategoricalIndex(list("aabbca"), categories=list("cabdef"), ordered=False)
341
+
342
+ assert "a" in ci
343
+ assert "z" not in ci
344
+ assert "e" not in ci
345
+ assert np.nan not in ci
346
+
347
+ # assert codes NOT in index
348
+ assert 0 not in ci
349
+ assert 1 not in ci
350
+
351
+ def test_contains_nan(self):
352
+ ci = CategoricalIndex(list("aabbca") + [np.nan], categories=list("cabdef"))
353
+ assert np.nan in ci
354
+
355
+ @pytest.mark.parametrize("unwrap", [True, False])
356
+ def test_contains_na_dtype(self, unwrap):
357
+ dti = pd.date_range("2016-01-01", periods=100).insert(0, pd.NaT)
358
+ pi = dti.to_period("D")
359
+ tdi = dti - dti[-1]
360
+ ci = CategoricalIndex(dti)
361
+
362
+ obj = ci
363
+ if unwrap:
364
+ obj = ci._data
365
+
366
+ assert np.nan in obj
367
+ assert None in obj
368
+ assert pd.NaT in obj
369
+ assert np.datetime64("NaT") in obj
370
+ assert np.timedelta64("NaT") not in obj
371
+
372
+ obj2 = CategoricalIndex(tdi)
373
+ if unwrap:
374
+ obj2 = obj2._data
375
+
376
+ assert np.nan in obj2
377
+ assert None in obj2
378
+ assert pd.NaT in obj2
379
+ assert np.datetime64("NaT") not in obj2
380
+ assert np.timedelta64("NaT") in obj2
381
+
382
+ obj3 = CategoricalIndex(pi)
383
+ if unwrap:
384
+ obj3 = obj3._data
385
+
386
+ assert np.nan in obj3
387
+ assert None in obj3
388
+ assert pd.NaT in obj3
389
+ assert np.datetime64("NaT") not in obj3
390
+ assert np.timedelta64("NaT") not in obj3
391
+
392
+ @pytest.mark.parametrize(
393
+ "item, expected",
394
+ [
395
+ (pd.Interval(0, 1), True),
396
+ (1.5, True),
397
+ (pd.Interval(0.5, 1.5), False),
398
+ ("a", False),
399
+ (Timestamp(1), False),
400
+ (pd.Timedelta(1), False),
401
+ ],
402
+ ids=str,
403
+ )
404
+ def test_contains_interval(self, item, expected):
405
+ # GH 23705
406
+ ci = CategoricalIndex(IntervalIndex.from_breaks(range(3)))
407
+ result = item in ci
408
+ assert result is expected
409
+
410
+ def test_contains_list(self):
411
+ # GH#21729
412
+ idx = CategoricalIndex([1, 2, 3])
413
+
414
+ assert "a" not in idx
415
+
416
+ with pytest.raises(TypeError, match="unhashable type"):
417
+ ["a"] in idx
418
+
419
+ with pytest.raises(TypeError, match="unhashable type"):
420
+ ["a", "b"] in idx
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_map.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ CategoricalIndex,
7
+ Index,
8
+ Series,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ @pytest.mark.parametrize(
14
+ "data, categories",
15
+ [
16
+ (list("abcbca"), list("cab")),
17
+ (pd.interval_range(0, 3).repeat(3), pd.interval_range(0, 3)),
18
+ ],
19
+ ids=["string", "interval"],
20
+ )
21
+ def test_map_str(data, categories, ordered):
22
+ # GH 31202 - override base class since we want to maintain categorical/ordered
23
+ index = CategoricalIndex(data, categories=categories, ordered=ordered)
24
+ result = index.map(str)
25
+ expected = CategoricalIndex(
26
+ map(str, data), categories=map(str, categories), ordered=ordered
27
+ )
28
+ tm.assert_index_equal(result, expected)
29
+
30
+
31
+ def test_map():
32
+ ci = CategoricalIndex(list("ABABC"), categories=list("CBA"), ordered=True)
33
+ result = ci.map(lambda x: x.lower())
34
+ exp = CategoricalIndex(list("ababc"), categories=list("cba"), ordered=True)
35
+ tm.assert_index_equal(result, exp)
36
+
37
+ ci = CategoricalIndex(
38
+ list("ABABC"), categories=list("BAC"), ordered=False, name="XXX"
39
+ )
40
+ result = ci.map(lambda x: x.lower())
41
+ exp = CategoricalIndex(
42
+ list("ababc"), categories=list("bac"), ordered=False, name="XXX"
43
+ )
44
+ tm.assert_index_equal(result, exp)
45
+
46
+ # GH 12766: Return an index not an array
47
+ tm.assert_index_equal(
48
+ ci.map(lambda x: 1), Index(np.array([1] * 5, dtype=np.int64), name="XXX")
49
+ )
50
+
51
+ # change categories dtype
52
+ ci = CategoricalIndex(list("ABABC"), categories=list("BAC"), ordered=False)
53
+
54
+ def f(x):
55
+ return {"A": 10, "B": 20, "C": 30}.get(x)
56
+
57
+ result = ci.map(f)
58
+ exp = CategoricalIndex([10, 20, 10, 20, 30], categories=[20, 10, 30], ordered=False)
59
+ tm.assert_index_equal(result, exp)
60
+
61
+ result = ci.map(Series([10, 20, 30], index=["A", "B", "C"]))
62
+ tm.assert_index_equal(result, exp)
63
+
64
+ result = ci.map({"A": 10, "B": 20, "C": 30})
65
+ tm.assert_index_equal(result, exp)
66
+
67
+
68
+ def test_map_with_categorical_series():
69
+ # GH 12756
70
+ a = Index([1, 2, 3, 4])
71
+ b = Series(["even", "odd", "even", "odd"], dtype="category")
72
+ c = Series(["even", "odd", "even", "odd"])
73
+
74
+ exp = CategoricalIndex(["odd", "even", "odd", np.nan])
75
+ tm.assert_index_equal(a.map(b), exp)
76
+ exp = Index(["odd", "even", "odd", np.nan])
77
+ tm.assert_index_equal(a.map(c), exp)
78
+
79
+
80
+ @pytest.mark.parametrize(
81
+ ("data", "f", "expected"),
82
+ (
83
+ ([1, 1, np.nan], pd.isna, CategoricalIndex([False, False, np.nan])),
84
+ ([1, 2, np.nan], pd.isna, Index([False, False, np.nan])),
85
+ ([1, 1, np.nan], {1: False}, CategoricalIndex([False, False, np.nan])),
86
+ ([1, 2, np.nan], {1: False, 2: False}, Index([False, False, np.nan])),
87
+ (
88
+ [1, 1, np.nan],
89
+ Series([False, False]),
90
+ CategoricalIndex([False, False, np.nan]),
91
+ ),
92
+ (
93
+ [1, 2, np.nan],
94
+ Series([False, False, False]),
95
+ Index([False, False, np.nan]),
96
+ ),
97
+ ),
98
+ )
99
+ def test_map_with_nan_ignore(data, f, expected): # GH 24241
100
+ values = CategoricalIndex(data)
101
+ result = values.map(f, na_action="ignore")
102
+ tm.assert_index_equal(result, expected)
103
+
104
+
105
+ @pytest.mark.parametrize(
106
+ ("data", "f", "expected"),
107
+ (
108
+ ([1, 1, np.nan], pd.isna, Index([False, False, True])),
109
+ ([1, 2, np.nan], pd.isna, Index([False, False, True])),
110
+ ([1, 1, np.nan], {1: False}, CategoricalIndex([False, False, np.nan])),
111
+ ([1, 2, np.nan], {1: False, 2: False}, Index([False, False, np.nan])),
112
+ (
113
+ [1, 1, np.nan],
114
+ Series([False, False]),
115
+ CategoricalIndex([False, False, np.nan]),
116
+ ),
117
+ (
118
+ [1, 2, np.nan],
119
+ Series([False, False, False]),
120
+ Index([False, False, np.nan]),
121
+ ),
122
+ ),
123
+ )
124
+ def test_map_with_nan_none(data, f, expected): # GH 24241
125
+ values = CategoricalIndex(data)
126
+ result = values.map(f, na_action=None)
127
+ tm.assert_index_equal(result, expected)
128
+
129
+
130
+ def test_map_with_dict_or_series():
131
+ orig_values = ["a", "B", 1, "a"]
132
+ new_values = ["one", 2, 3.0, "one"]
133
+ cur_index = CategoricalIndex(orig_values, name="XXX")
134
+ expected = CategoricalIndex(new_values, name="XXX", categories=[3.0, 2, "one"])
135
+
136
+ mapper = Series(new_values[:-1], index=orig_values[:-1])
137
+ result = cur_index.map(mapper)
138
+ # Order of categories in result can be different
139
+ tm.assert_index_equal(result, expected)
140
+
141
+ mapper = dict(zip(orig_values[:-1], new_values[:-1]))
142
+ result = cur_index.map(mapper)
143
+ # Order of categories in result can be different
144
+ tm.assert_index_equal(result, expected)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_reindex.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Categorical,
6
+ CategoricalIndex,
7
+ Index,
8
+ Interval,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestReindex:
14
+ def test_reindex_list_non_unique(self):
15
+ # GH#11586
16
+ msg = "cannot reindex on an axis with duplicate labels"
17
+ ci = CategoricalIndex(["a", "b", "c", "a"])
18
+ with pytest.raises(ValueError, match=msg):
19
+ ci.reindex(["a", "c"])
20
+
21
+ def test_reindex_categorical_non_unique(self):
22
+ msg = "cannot reindex on an axis with duplicate labels"
23
+ ci = CategoricalIndex(["a", "b", "c", "a"])
24
+ with pytest.raises(ValueError, match=msg):
25
+ ci.reindex(Categorical(["a", "c"]))
26
+
27
+ def test_reindex_list_non_unique_unused_category(self):
28
+ msg = "cannot reindex on an axis with duplicate labels"
29
+ ci = CategoricalIndex(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
30
+ with pytest.raises(ValueError, match=msg):
31
+ ci.reindex(["a", "c"])
32
+
33
+ def test_reindex_categorical_non_unique_unused_category(self):
34
+ msg = "cannot reindex on an axis with duplicate labels"
35
+ ci = CategoricalIndex(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
36
+ with pytest.raises(ValueError, match=msg):
37
+ ci.reindex(Categorical(["a", "c"]))
38
+
39
+ def test_reindex_duplicate_target(self):
40
+ # See GH25459
41
+ cat = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c", "d"])
42
+ res, indexer = cat.reindex(["a", "c", "c"])
43
+ exp = Index(["a", "c", "c"])
44
+ tm.assert_index_equal(res, exp, exact=True)
45
+ tm.assert_numpy_array_equal(indexer, np.array([0, 2, 2], dtype=np.intp))
46
+
47
+ res, indexer = cat.reindex(
48
+ CategoricalIndex(["a", "c", "c"], categories=["a", "b", "c", "d"])
49
+ )
50
+ exp = CategoricalIndex(["a", "c", "c"], categories=["a", "b", "c", "d"])
51
+ tm.assert_index_equal(res, exp, exact=True)
52
+ tm.assert_numpy_array_equal(indexer, np.array([0, 2, 2], dtype=np.intp))
53
+
54
+ def test_reindex_empty_index(self):
55
+ # See GH16770
56
+ c = CategoricalIndex([])
57
+ res, indexer = c.reindex(["a", "b"])
58
+ tm.assert_index_equal(res, Index(["a", "b"]), exact=True)
59
+ tm.assert_numpy_array_equal(indexer, np.array([-1, -1], dtype=np.intp))
60
+
61
+ def test_reindex_categorical_added_category(self):
62
+ # GH 42424
63
+ ci = CategoricalIndex(
64
+ [Interval(0, 1, closed="right"), Interval(1, 2, closed="right")],
65
+ ordered=True,
66
+ )
67
+ ci_add = CategoricalIndex(
68
+ [
69
+ Interval(0, 1, closed="right"),
70
+ Interval(1, 2, closed="right"),
71
+ Interval(2, 3, closed="right"),
72
+ Interval(3, 4, closed="right"),
73
+ ],
74
+ ordered=True,
75
+ )
76
+ result, _ = ci.reindex(ci_add)
77
+ expected = ci_add
78
+ tm.assert_index_equal(expected, result)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_setops.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ CategoricalIndex,
6
+ Index,
7
+ )
8
+ import pandas._testing as tm
9
+
10
+
11
+ @pytest.mark.parametrize("na_value", [None, np.nan])
12
+ def test_difference_with_na(na_value):
13
+ # GH 57318
14
+ ci = CategoricalIndex(["a", "b", "c", None])
15
+ other = Index(["c", na_value])
16
+ result = ci.difference(other)
17
+ expected = CategoricalIndex(["a", "b"], categories=["a", "b", "c"])
18
+ tm.assert_index_equal(result, expected)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__init__.py ADDED
File without changes
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (184 Bytes). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_drop_duplicates.cpython-310.pyc ADDED
Binary file (2.94 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_equals.cpython-310.pyc ADDED
Binary file (6.06 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_indexing.cpython-310.pyc ADDED
Binary file (1.39 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_is_monotonic.cpython-310.pyc ADDED
Binary file (1.01 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_nat.cpython-310.pyc ADDED
Binary file (1.93 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_sort_values.cpython-310.pyc ADDED
Binary file (7.6 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_value_counts.cpython-310.pyc ADDED
Binary file (3.28 kB). View file
 
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ PeriodIndex,
6
+ Series,
7
+ date_range,
8
+ period_range,
9
+ timedelta_range,
10
+ )
11
+ import pandas._testing as tm
12
+
13
+
14
+ class DropDuplicates:
15
+ def test_drop_duplicates_metadata(self, idx):
16
+ # GH#10115
17
+ result = idx.drop_duplicates()
18
+ tm.assert_index_equal(idx, result)
19
+ assert idx.freq == result.freq
20
+
21
+ idx_dup = idx.append(idx)
22
+ result = idx_dup.drop_duplicates()
23
+
24
+ expected = idx
25
+ if not isinstance(idx, PeriodIndex):
26
+ # freq is reset except for PeriodIndex
27
+ assert idx_dup.freq is None
28
+ assert result.freq is None
29
+ expected = idx._with_freq(None)
30
+ else:
31
+ assert result.freq == expected.freq
32
+
33
+ tm.assert_index_equal(result, expected)
34
+
35
+ @pytest.mark.parametrize(
36
+ "keep, expected, index",
37
+ [
38
+ (
39
+ "first",
40
+ np.concatenate(([False] * 10, [True] * 5)),
41
+ np.arange(0, 10, dtype=np.int64),
42
+ ),
43
+ (
44
+ "last",
45
+ np.concatenate(([True] * 5, [False] * 10)),
46
+ np.arange(5, 15, dtype=np.int64),
47
+ ),
48
+ (
49
+ False,
50
+ np.concatenate(([True] * 5, [False] * 5, [True] * 5)),
51
+ np.arange(5, 10, dtype=np.int64),
52
+ ),
53
+ ],
54
+ )
55
+ def test_drop_duplicates(self, keep, expected, index, idx):
56
+ # to check Index/Series compat
57
+ idx = idx.append(idx[:5])
58
+
59
+ tm.assert_numpy_array_equal(idx.duplicated(keep=keep), expected)
60
+ expected = idx[~expected]
61
+
62
+ result = idx.drop_duplicates(keep=keep)
63
+ tm.assert_index_equal(result, expected)
64
+
65
+ result = Series(idx).drop_duplicates(keep=keep)
66
+ expected = Series(expected, index=index)
67
+ tm.assert_series_equal(result, expected)
68
+
69
+
70
+ class TestDropDuplicatesPeriodIndex(DropDuplicates):
71
+ @pytest.fixture(params=["D", "3D", "h", "2h", "min", "2min", "s", "3s"])
72
+ def freq(self, request):
73
+ return request.param
74
+
75
+ @pytest.fixture
76
+ def idx(self, freq):
77
+ return period_range("2011-01-01", periods=10, freq=freq, name="idx")
78
+
79
+
80
+ class TestDropDuplicatesDatetimeIndex(DropDuplicates):
81
+ @pytest.fixture
82
+ def idx(self, freq_sample):
83
+ return date_range("2011-01-01", freq=freq_sample, periods=10, name="idx")
84
+
85
+
86
+ class TestDropDuplicatesTimedeltaIndex(DropDuplicates):
87
+ @pytest.fixture
88
+ def idx(self, freq_sample):
89
+ return timedelta_range("1 day", periods=10, freq=freq_sample, name="idx")
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_equals.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests shared for DatetimeIndex/TimedeltaIndex/PeriodIndex
3
+ """
4
+ from datetime import (
5
+ datetime,
6
+ timedelta,
7
+ )
8
+
9
+ import numpy as np
10
+ import pytest
11
+
12
+ import pandas as pd
13
+ from pandas import (
14
+ CategoricalIndex,
15
+ DatetimeIndex,
16
+ Index,
17
+ PeriodIndex,
18
+ TimedeltaIndex,
19
+ date_range,
20
+ period_range,
21
+ timedelta_range,
22
+ )
23
+ import pandas._testing as tm
24
+
25
+
26
+ class EqualsTests:
27
+ def test_not_equals_numeric(self, index):
28
+ assert not index.equals(Index(index.asi8))
29
+ assert not index.equals(Index(index.asi8.astype("u8")))
30
+ assert not index.equals(Index(index.asi8).astype("f8"))
31
+
32
+ def test_equals(self, index):
33
+ assert index.equals(index)
34
+ assert index.equals(index.astype(object))
35
+ assert index.equals(CategoricalIndex(index))
36
+ assert index.equals(CategoricalIndex(index.astype(object)))
37
+
38
+ def test_not_equals_non_arraylike(self, index):
39
+ assert not index.equals(list(index))
40
+
41
+ def test_not_equals_strings(self, index):
42
+ other = Index([str(x) for x in index], dtype=object)
43
+ assert not index.equals(other)
44
+ assert not index.equals(CategoricalIndex(other))
45
+
46
+ def test_not_equals_misc_strs(self, index):
47
+ other = Index(list("abc"))
48
+ assert not index.equals(other)
49
+
50
+
51
+ class TestPeriodIndexEquals(EqualsTests):
52
+ @pytest.fixture
53
+ def index(self):
54
+ return period_range("2013-01-01", periods=5, freq="D")
55
+
56
+ # TODO: de-duplicate with other test_equals2 methods
57
+ @pytest.mark.parametrize("freq", ["D", "M"])
58
+ def test_equals2(self, freq):
59
+ # GH#13107
60
+ idx = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq=freq)
61
+ assert idx.equals(idx)
62
+ assert idx.equals(idx.copy())
63
+ assert idx.equals(idx.astype(object))
64
+ assert idx.astype(object).equals(idx)
65
+ assert idx.astype(object).equals(idx.astype(object))
66
+ assert not idx.equals(list(idx))
67
+ assert not idx.equals(pd.Series(idx))
68
+
69
+ idx2 = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq="h")
70
+ assert not idx.equals(idx2)
71
+ assert not idx.equals(idx2.copy())
72
+ assert not idx.equals(idx2.astype(object))
73
+ assert not idx.astype(object).equals(idx2)
74
+ assert not idx.equals(list(idx2))
75
+ assert not idx.equals(pd.Series(idx2))
76
+
77
+ # same internal, different tz
78
+ idx3 = PeriodIndex._simple_new(
79
+ idx._values._simple_new(idx._values.asi8, dtype=pd.PeriodDtype("h"))
80
+ )
81
+ tm.assert_numpy_array_equal(idx.asi8, idx3.asi8)
82
+ assert not idx.equals(idx3)
83
+ assert not idx.equals(idx3.copy())
84
+ assert not idx.equals(idx3.astype(object))
85
+ assert not idx.astype(object).equals(idx3)
86
+ assert not idx.equals(list(idx3))
87
+ assert not idx.equals(pd.Series(idx3))
88
+
89
+
90
+ class TestDatetimeIndexEquals(EqualsTests):
91
+ @pytest.fixture
92
+ def index(self):
93
+ return date_range("2013-01-01", periods=5)
94
+
95
+ def test_equals2(self):
96
+ # GH#13107
97
+ idx = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"])
98
+ assert idx.equals(idx)
99
+ assert idx.equals(idx.copy())
100
+ assert idx.equals(idx.astype(object))
101
+ assert idx.astype(object).equals(idx)
102
+ assert idx.astype(object).equals(idx.astype(object))
103
+ assert not idx.equals(list(idx))
104
+ assert not idx.equals(pd.Series(idx))
105
+
106
+ idx2 = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"], tz="US/Pacific")
107
+ assert not idx.equals(idx2)
108
+ assert not idx.equals(idx2.copy())
109
+ assert not idx.equals(idx2.astype(object))
110
+ assert not idx.astype(object).equals(idx2)
111
+ assert not idx.equals(list(idx2))
112
+ assert not idx.equals(pd.Series(idx2))
113
+
114
+ # same internal, different tz
115
+ idx3 = DatetimeIndex(idx.asi8, tz="US/Pacific")
116
+ tm.assert_numpy_array_equal(idx.asi8, idx3.asi8)
117
+ assert not idx.equals(idx3)
118
+ assert not idx.equals(idx3.copy())
119
+ assert not idx.equals(idx3.astype(object))
120
+ assert not idx.astype(object).equals(idx3)
121
+ assert not idx.equals(list(idx3))
122
+ assert not idx.equals(pd.Series(idx3))
123
+
124
+ # check that we do not raise when comparing with OutOfBounds objects
125
+ oob = Index([datetime(2500, 1, 1)] * 3, dtype=object)
126
+ assert not idx.equals(oob)
127
+ assert not idx2.equals(oob)
128
+ assert not idx3.equals(oob)
129
+
130
+ # check that we do not raise when comparing with OutOfBounds dt64
131
+ oob2 = oob.map(np.datetime64)
132
+ assert not idx.equals(oob2)
133
+ assert not idx2.equals(oob2)
134
+ assert not idx3.equals(oob2)
135
+
136
+ @pytest.mark.parametrize("freq", ["B", "C"])
137
+ def test_not_equals_bday(self, freq):
138
+ rng = date_range("2009-01-01", "2010-01-01", freq=freq)
139
+ assert not rng.equals(list(rng))
140
+
141
+
142
+ class TestTimedeltaIndexEquals(EqualsTests):
143
+ @pytest.fixture
144
+ def index(self):
145
+ return timedelta_range("1 day", periods=10)
146
+
147
+ def test_equals2(self):
148
+ # GH#13107
149
+ idx = TimedeltaIndex(["1 days", "2 days", "NaT"])
150
+ assert idx.equals(idx)
151
+ assert idx.equals(idx.copy())
152
+ assert idx.equals(idx.astype(object))
153
+ assert idx.astype(object).equals(idx)
154
+ assert idx.astype(object).equals(idx.astype(object))
155
+ assert not idx.equals(list(idx))
156
+ assert not idx.equals(pd.Series(idx))
157
+
158
+ idx2 = TimedeltaIndex(["2 days", "1 days", "NaT"])
159
+ assert not idx.equals(idx2)
160
+ assert not idx.equals(idx2.copy())
161
+ assert not idx.equals(idx2.astype(object))
162
+ assert not idx.astype(object).equals(idx2)
163
+ assert not idx.astype(object).equals(idx2.astype(object))
164
+ assert not idx.equals(list(idx2))
165
+ assert not idx.equals(pd.Series(idx2))
166
+
167
+ # Check that we dont raise OverflowError on comparisons outside the
168
+ # implementation range GH#28532
169
+ oob = Index([timedelta(days=10**6)] * 3, dtype=object)
170
+ assert not idx.equals(oob)
171
+ assert not idx2.equals(oob)
172
+
173
+ oob2 = Index([np.timedelta64(x) for x in oob], dtype=object)
174
+ assert (oob == oob2).all()
175
+ assert not idx.equals(oob2)
176
+ assert not idx2.equals(oob2)
177
+
178
+ oob3 = oob.map(np.timedelta64)
179
+ assert (oob3 == oob).all()
180
+ assert not idx.equals(oob3)
181
+ assert not idx2.equals(oob3)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_indexing.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ DatetimeIndex,
7
+ Index,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+ dtlike_dtypes = [
12
+ np.dtype("timedelta64[ns]"),
13
+ np.dtype("datetime64[ns]"),
14
+ pd.DatetimeTZDtype("ns", "Asia/Tokyo"),
15
+ pd.PeriodDtype("ns"),
16
+ ]
17
+
18
+
19
+ @pytest.mark.parametrize("ldtype", dtlike_dtypes)
20
+ @pytest.mark.parametrize("rdtype", dtlike_dtypes)
21
+ def test_get_indexer_non_unique_wrong_dtype(ldtype, rdtype):
22
+ vals = np.tile(3600 * 10**9 * np.arange(3, dtype=np.int64), 2)
23
+
24
+ def construct(dtype):
25
+ if dtype is dtlike_dtypes[-1]:
26
+ # PeriodArray will try to cast ints to strings
27
+ return DatetimeIndex(vals).astype(dtype)
28
+ return Index(vals, dtype=dtype)
29
+
30
+ left = construct(ldtype)
31
+ right = construct(rdtype)
32
+
33
+ result = left.get_indexer_non_unique(right)
34
+
35
+ if ldtype is rdtype:
36
+ ex1 = np.array([0, 3, 1, 4, 2, 5] * 2, dtype=np.intp)
37
+ ex2 = np.array([], dtype=np.intp)
38
+ tm.assert_numpy_array_equal(result[0], ex1)
39
+ tm.assert_numpy_array_equal(result[1], ex2)
40
+
41
+ else:
42
+ no_matches = np.array([-1] * 6, dtype=np.intp)
43
+ missing = np.arange(6, dtype=np.intp)
44
+ tm.assert_numpy_array_equal(result[0], no_matches)
45
+ tm.assert_numpy_array_equal(result[1], missing)
vllm/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_is_monotonic.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pandas import (
2
+ Index,
3
+ NaT,
4
+ date_range,
5
+ )
6
+
7
+
8
+ def test_is_monotonic_with_nat():
9
+ # GH#31437
10
+ # PeriodIndex.is_monotonic_increasing should behave analogously to DatetimeIndex,
11
+ # in particular never be monotonic when we have NaT
12
+ dti = date_range("2016-01-01", periods=3)
13
+ pi = dti.to_period("D")
14
+ tdi = Index(dti.view("timedelta64[ns]"))
15
+
16
+ for obj in [pi, pi._engine, dti, dti._engine, tdi, tdi._engine]:
17
+ if isinstance(obj, Index):
18
+ # i.e. not Engines
19
+ assert obj.is_monotonic_increasing
20
+ assert obj.is_monotonic_increasing
21
+ assert not obj.is_monotonic_decreasing
22
+ assert obj.is_unique
23
+
24
+ dti1 = dti.insert(0, NaT)
25
+ pi1 = dti1.to_period("D")
26
+ tdi1 = Index(dti1.view("timedelta64[ns]"))
27
+
28
+ for obj in [pi1, pi1._engine, dti1, dti1._engine, tdi1, tdi1._engine]:
29
+ if isinstance(obj, Index):
30
+ # i.e. not Engines
31
+ assert not obj.is_monotonic_increasing
32
+ assert not obj.is_monotonic_increasing
33
+ assert not obj.is_monotonic_decreasing
34
+ assert obj.is_unique
35
+
36
+ dti2 = dti.insert(3, NaT)
37
+ pi2 = dti2.to_period("h")
38
+ tdi2 = Index(dti2.view("timedelta64[ns]"))
39
+
40
+ for obj in [pi2, pi2._engine, dti2, dti2._engine, tdi2, tdi2._engine]:
41
+ if isinstance(obj, Index):
42
+ # i.e. not Engines
43
+ assert not obj.is_monotonic_increasing
44
+ assert not obj.is_monotonic_increasing
45
+ assert not obj.is_monotonic_decreasing
46
+ assert obj.is_unique