Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_any_index.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_datetimelike.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_index_new.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_numpy_compat.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_subclass.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__init__.py +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_indexing.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_constructors.py +80 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_formats.py +163 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_indexing.py +104 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_pickle.py +11 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_reshape.py +95 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.py +266 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_where.py +13 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__init__.py +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/conftest.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_analytics.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_astype.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_compat.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_constructors.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_conversion.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_copy.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_drop.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_duplicates.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_equivalence.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_formats.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_get_level_values.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_get_set.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_indexing.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_integrity.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_isin.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_join.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_lexsort.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_missing.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_monotonic.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_names.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_partial_indexing.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_pickle.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_reindex.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_reshape.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_setops.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_sorting.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_take.cpython-310.pyc +0 -0
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (185 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_any_index.cpython-310.pyc
ADDED
Binary file (6.76 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-310.pyc
ADDED
Binary file (53.3 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_datetimelike.cpython-310.pyc
ADDED
Binary file (5.87 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_index_new.cpython-310.pyc
ADDED
Binary file (15.1 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_numpy_compat.cpython-310.pyc
ADDED
Binary file (4.47 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_subclass.cpython-310.pyc
ADDED
Binary file (1.53 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__init__.py
ADDED
File without changes
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-310.pyc
ADDED
Binary file (5.09 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_indexing.cpython-310.pyc
ADDED
Binary file (4.33 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-310.pyc
ADDED
Binary file (564 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-310.pyc
ADDED
Binary file (3.52 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-310.pyc
ADDED
Binary file (818 Bytes). View file
|
|
env-llmeval/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
|
env-llmeval/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
|
env-llmeval/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)
|
env-llmeval/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)
|
env-llmeval/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)
|
env-llmeval/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)
|
env-llmeval/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)
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__init__.py
ADDED
File without changes
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (191 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/conftest.cpython-310.pyc
ADDED
Binary file (745 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_analytics.cpython-310.pyc
ADDED
Binary file (7.1 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_astype.cpython-310.pyc
ADDED
Binary file (1.2 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_compat.cpython-310.pyc
ADDED
Binary file (3.01 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_constructors.cpython-310.pyc
ADDED
Binary file (22.6 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_conversion.cpython-310.pyc
ADDED
Binary file (3.94 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_copy.cpython-310.pyc
ADDED
Binary file (2.4 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_drop.cpython-310.pyc
ADDED
Binary file (5.43 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_duplicates.cpython-310.pyc
ADDED
Binary file (10.1 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_equivalence.cpython-310.pyc
ADDED
Binary file (6.58 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_formats.cpython-310.pyc
ADDED
Binary file (10.1 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_get_level_values.cpython-310.pyc
ADDED
Binary file (4.03 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_get_set.cpython-310.pyc
ADDED
Binary file (11 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_indexing.cpython-310.pyc
ADDED
Binary file (29.5 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_integrity.cpython-310.pyc
ADDED
Binary file (8.96 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_isin.cpython-310.pyc
ADDED
Binary file (3.55 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_join.cpython-310.pyc
ADDED
Binary file (6.7 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_lexsort.cpython-310.pyc
ADDED
Binary file (1.45 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_missing.cpython-310.pyc
ADDED
Binary file (3.06 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_monotonic.cpython-310.pyc
ADDED
Binary file (4.19 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_names.cpython-310.pyc
ADDED
Binary file (6.73 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_partial_indexing.cpython-310.pyc
ADDED
Binary file (3.3 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_pickle.cpython-310.pyc
ADDED
Binary file (505 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_reindex.cpython-310.pyc
ADDED
Binary file (5.9 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_reshape.cpython-310.pyc
ADDED
Binary file (5.98 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_setops.cpython-310.pyc
ADDED
Binary file (19.8 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_sorting.cpython-310.pyc
ADDED
Binary file (9.49 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/pandas/tests/indexes/multi/__pycache__/test_take.cpython-310.pyc
ADDED
Binary file (2.41 kB). View file
|
|