ZTWHHH commited on
Commit
2c6e2db
·
verified ·
1 Parent(s): 60a4f4f

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. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/conftest.py +41 -0
  2. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__init__.py +0 -0
  3. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/__init__.cpython-310.pyc +0 -0
  4. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_astype.cpython-310.pyc +0 -0
  5. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_indexing.cpython-310.pyc +0 -0
  6. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_join.cpython-310.pyc +0 -0
  7. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_numeric.cpython-310.pyc +0 -0
  8. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_setops.cpython-310.pyc +0 -0
  9. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_astype.py +95 -0
  10. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_indexing.py +611 -0
  11. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_join.py +380 -0
  12. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_numeric.py +553 -0
  13. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_setops.py +168 -0
  14. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_any_index.py +172 -0
  15. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_base.py +1737 -0
  16. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_frozen.py +113 -0
  17. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_index_new.py +432 -0
  18. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_numpy_compat.py +189 -0
  19. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_subclass.py +40 -0
  20. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/__init__.py +0 -0
  21. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_join.py +47 -0
  22. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_ops.py +14 -0
  23. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_setops.py +254 -0
  24. mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_timedelta.py +61 -0
  25. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/BUILD_SHARED_LIBS.rst +43 -0
  26. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_ANDROID_JAVA_SOURCE_DIR.rst +7 -0
  27. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_ANDROID_NDK_DEPRECATED_HEADERS.rst +11 -0
  28. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_AUTOMOC_COMPILER_PREDEFINES.rst +10 -0
  29. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_AUTOMOC_PATH_PREFIX.rst +13 -0
  30. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_COMPILER_2005.rst +6 -0
  31. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_COMPILE_WARNING_AS_ERROR.rst +9 -0
  32. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_CUDA_STANDARD_REQUIRED.rst +10 -0
  33. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_CXX_EXTENSIONS.rst +10 -0
  34. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst +10 -0
  35. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.rst +28 -0
  36. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_EDIT_COMMAND.rst +9 -0
  37. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst +86 -0
  38. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_EXPORT_FIND_PACKAGE_NAME.rst +8 -0
  39. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_FIND_APPBUNDLE.rst +24 -0
  40. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst +12 -0
  41. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_FIND_PACKAGE_REDIRECTS_DIR.rst +28 -0
  42. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HIP_PLATFORM.rst +22 -0
  43. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_LINUX.rst +6 -0
  44. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_SYSTEM.rst +10 -0
  45. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_SYSTEM_PROCESSOR.rst +42 -0
  46. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_WIN32.rst +6 -0
  47. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE.rst +9 -0
  48. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_INSTALL_MESSAGE.rst +32 -0
  49. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.rst +13 -0
  50. openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst +13 -0
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/conftest.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Series,
6
+ array,
7
+ )
8
+
9
+
10
+ @pytest.fixture(params=[None, False])
11
+ def sort(request):
12
+ """
13
+ Valid values for the 'sort' parameter used in the Index
14
+ setops methods (intersection, union, etc.)
15
+
16
+ Caution:
17
+ Don't confuse this one with the "sort" fixture used
18
+ for DataFrame.append or concat. That one has
19
+ parameters [True, False].
20
+
21
+ We can't combine them as sort=True is not permitted
22
+ in the Index setops methods.
23
+ """
24
+ return request.param
25
+
26
+
27
+ @pytest.fixture(params=["D", "3D", "-3D", "h", "2h", "-2h", "min", "2min", "s", "-3s"])
28
+ def freq_sample(request):
29
+ """
30
+ Valid values for 'freq' parameter used to create date_range and
31
+ timedelta_range..
32
+ """
33
+ return request.param
34
+
35
+
36
+ @pytest.fixture(params=[list, tuple, np.array, array, Series])
37
+ def listlike_box(request):
38
+ """
39
+ Types that may be passed as the indexer to searchsorted.
40
+ """
41
+ return request.param
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__init__.py ADDED
File without changes
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (184 Bytes). View file
 
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_astype.cpython-310.pyc ADDED
Binary file (3.84 kB). View file
 
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_indexing.cpython-310.pyc ADDED
Binary file (22.5 kB). View file
 
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_join.cpython-310.pyc ADDED
Binary file (10 kB). View file
 
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_numeric.cpython-310.pyc ADDED
Binary file (16.9 kB). View file
 
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/__pycache__/test_setops.cpython-310.pyc ADDED
Binary file (5.61 kB). View file
 
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_astype.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Index,
6
+ to_datetime,
7
+ to_timedelta,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ class TestAstype:
13
+ def test_astype_float64_to_uint64(self):
14
+ # GH#45309 used to incorrectly return Index with int64 dtype
15
+ idx = Index([0.0, 5.0, 10.0, 15.0, 20.0], dtype=np.float64)
16
+ result = idx.astype("u8")
17
+ expected = Index([0, 5, 10, 15, 20], dtype=np.uint64)
18
+ tm.assert_index_equal(result, expected, exact=True)
19
+
20
+ idx_with_negatives = idx - 10
21
+ with pytest.raises(ValueError, match="losslessly"):
22
+ idx_with_negatives.astype(np.uint64)
23
+
24
+ def test_astype_float64_to_object(self):
25
+ float_index = Index([0.0, 2.5, 5.0, 7.5, 10.0], dtype=np.float64)
26
+ result = float_index.astype(object)
27
+ assert result.equals(float_index)
28
+ assert float_index.equals(result)
29
+ assert isinstance(result, Index) and result.dtype == object
30
+
31
+ def test_astype_float64_mixed_to_object(self):
32
+ # mixed int-float
33
+ idx = Index([1.5, 2, 3, 4, 5], dtype=np.float64)
34
+ idx.name = "foo"
35
+ result = idx.astype(object)
36
+ assert result.equals(idx)
37
+ assert idx.equals(result)
38
+ assert isinstance(result, Index) and result.dtype == object
39
+
40
+ @pytest.mark.parametrize("dtype", ["int16", "int32", "int64"])
41
+ def test_astype_float64_to_int_dtype(self, dtype):
42
+ # GH#12881
43
+ # a float astype int
44
+ idx = Index([0, 1, 2], dtype=np.float64)
45
+ result = idx.astype(dtype)
46
+ expected = Index([0, 1, 2], dtype=dtype)
47
+ tm.assert_index_equal(result, expected, exact=True)
48
+
49
+ idx = Index([0, 1.1, 2], dtype=np.float64)
50
+ result = idx.astype(dtype)
51
+ expected = Index([0, 1, 2], dtype=dtype)
52
+ tm.assert_index_equal(result, expected, exact=True)
53
+
54
+ @pytest.mark.parametrize("dtype", ["float32", "float64"])
55
+ def test_astype_float64_to_float_dtype(self, dtype):
56
+ # GH#12881
57
+ # a float astype int
58
+ idx = Index([0, 1, 2], dtype=np.float64)
59
+ result = idx.astype(dtype)
60
+ assert isinstance(result, Index) and result.dtype == dtype
61
+
62
+ @pytest.mark.parametrize("dtype", ["M8[ns]", "m8[ns]"])
63
+ def test_astype_float_to_datetimelike(self, dtype):
64
+ # GH#49660 pre-2.0 Index.astype from floating to M8/m8/Period raised,
65
+ # inconsistent with Series.astype
66
+ idx = Index([0, 1.1, 2], dtype=np.float64)
67
+
68
+ result = idx.astype(dtype)
69
+ if dtype[0] == "M":
70
+ expected = to_datetime(idx.values)
71
+ else:
72
+ expected = to_timedelta(idx.values)
73
+ tm.assert_index_equal(result, expected)
74
+
75
+ # check that we match Series behavior
76
+ result = idx.to_series().set_axis(range(3)).astype(dtype)
77
+ expected = expected.to_series().set_axis(range(3))
78
+ tm.assert_series_equal(result, expected)
79
+
80
+ @pytest.mark.parametrize("dtype", [int, "int16", "int32", "int64"])
81
+ @pytest.mark.parametrize("non_finite", [np.inf, np.nan])
82
+ def test_cannot_cast_inf_to_int(self, non_finite, dtype):
83
+ # GH#13149
84
+ idx = Index([1, 2, non_finite], dtype=np.float64)
85
+
86
+ msg = r"Cannot convert non-finite values \(NA or inf\) to integer"
87
+ with pytest.raises(ValueError, match=msg):
88
+ idx.astype(dtype)
89
+
90
+ def test_astype_from_object(self):
91
+ index = Index([1.0, np.nan, 0.2], dtype="object")
92
+ result = index.astype(float)
93
+ expected = Index([1.0, np.nan, 0.2], dtype=np.float64)
94
+ assert result.dtype == expected.dtype
95
+ tm.assert_index_equal(result, expected)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_indexing.py ADDED
@@ -0,0 +1,611 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas.errors import InvalidIndexError
5
+
6
+ from pandas import (
7
+ NA,
8
+ Index,
9
+ RangeIndex,
10
+ Series,
11
+ Timestamp,
12
+ )
13
+ import pandas._testing as tm
14
+ from pandas.core.arrays import (
15
+ ArrowExtensionArray,
16
+ FloatingArray,
17
+ )
18
+
19
+
20
+ @pytest.fixture
21
+ def index_large():
22
+ # large values used in Index[uint64] tests where no compat needed with Int64/Float64
23
+ large = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25]
24
+ return Index(large, dtype=np.uint64)
25
+
26
+
27
+ class TestGetLoc:
28
+ def test_get_loc(self):
29
+ index = Index([0, 1, 2])
30
+ assert index.get_loc(1) == 1
31
+
32
+ def test_get_loc_raises_bad_label(self):
33
+ index = Index([0, 1, 2])
34
+ with pytest.raises(InvalidIndexError, match=r"\[1, 2\]"):
35
+ index.get_loc([1, 2])
36
+
37
+ def test_get_loc_float64(self):
38
+ idx = Index([0.0, 1.0, 2.0], dtype=np.float64)
39
+
40
+ with pytest.raises(KeyError, match="^'foo'$"):
41
+ idx.get_loc("foo")
42
+ with pytest.raises(KeyError, match=r"^1\.5$"):
43
+ idx.get_loc(1.5)
44
+ with pytest.raises(KeyError, match="^True$"):
45
+ idx.get_loc(True)
46
+ with pytest.raises(KeyError, match="^False$"):
47
+ idx.get_loc(False)
48
+
49
+ def test_get_loc_na(self):
50
+ idx = Index([np.nan, 1, 2], dtype=np.float64)
51
+ assert idx.get_loc(1) == 1
52
+ assert idx.get_loc(np.nan) == 0
53
+
54
+ idx = Index([np.nan, 1, np.nan], dtype=np.float64)
55
+ assert idx.get_loc(1) == 1
56
+
57
+ # representable by slice [0:2:2]
58
+ msg = "'Cannot get left slice bound for non-unique label: nan'"
59
+ with pytest.raises(KeyError, match=msg):
60
+ idx.slice_locs(np.nan)
61
+ # not representable by slice
62
+ idx = Index([np.nan, 1, np.nan, np.nan], dtype=np.float64)
63
+ assert idx.get_loc(1) == 1
64
+ msg = "'Cannot get left slice bound for non-unique label: nan"
65
+ with pytest.raises(KeyError, match=msg):
66
+ idx.slice_locs(np.nan)
67
+
68
+ def test_get_loc_missing_nan(self):
69
+ # GH#8569
70
+ idx = Index([1, 2], dtype=np.float64)
71
+ assert idx.get_loc(1) == 0
72
+ with pytest.raises(KeyError, match=r"^3$"):
73
+ idx.get_loc(3)
74
+ with pytest.raises(KeyError, match="^nan$"):
75
+ idx.get_loc(np.nan)
76
+ with pytest.raises(InvalidIndexError, match=r"\[nan\]"):
77
+ # listlike/non-hashable raises TypeError
78
+ idx.get_loc([np.nan])
79
+
80
+ @pytest.mark.parametrize("vals", [[1], [1.0], [Timestamp("2019-12-31")], ["test"]])
81
+ def test_get_loc_float_index_nan_with_method(self, vals):
82
+ # GH#39382
83
+ idx = Index(vals)
84
+ with pytest.raises(KeyError, match="nan"):
85
+ idx.get_loc(np.nan)
86
+
87
+ @pytest.mark.parametrize("dtype", ["f8", "i8", "u8"])
88
+ def test_get_loc_numericindex_none_raises(self, dtype):
89
+ # case that goes through searchsorted and key is non-comparable to values
90
+ arr = np.arange(10**7, dtype=dtype)
91
+ idx = Index(arr)
92
+ with pytest.raises(KeyError, match="None"):
93
+ idx.get_loc(None)
94
+
95
+ def test_get_loc_overflows(self):
96
+ # unique but non-monotonic goes through IndexEngine.mapping.get_item
97
+ idx = Index([0, 2, 1])
98
+
99
+ val = np.iinfo(np.int64).max + 1
100
+
101
+ with pytest.raises(KeyError, match=str(val)):
102
+ idx.get_loc(val)
103
+ with pytest.raises(KeyError, match=str(val)):
104
+ idx._engine.get_loc(val)
105
+
106
+
107
+ class TestGetIndexer:
108
+ def test_get_indexer(self):
109
+ index1 = Index([1, 2, 3, 4, 5])
110
+ index2 = Index([2, 4, 6])
111
+
112
+ r1 = index1.get_indexer(index2)
113
+ e1 = np.array([1, 3, -1], dtype=np.intp)
114
+ tm.assert_almost_equal(r1, e1)
115
+
116
+ @pytest.mark.parametrize("reverse", [True, False])
117
+ @pytest.mark.parametrize(
118
+ "expected,method",
119
+ [
120
+ (np.array([-1, 0, 0, 1, 1], dtype=np.intp), "pad"),
121
+ (np.array([-1, 0, 0, 1, 1], dtype=np.intp), "ffill"),
122
+ (np.array([0, 0, 1, 1, 2], dtype=np.intp), "backfill"),
123
+ (np.array([0, 0, 1, 1, 2], dtype=np.intp), "bfill"),
124
+ ],
125
+ )
126
+ def test_get_indexer_methods(self, reverse, expected, method):
127
+ index1 = Index([1, 2, 3, 4, 5])
128
+ index2 = Index([2, 4, 6])
129
+
130
+ if reverse:
131
+ index1 = index1[::-1]
132
+ expected = expected[::-1]
133
+
134
+ result = index2.get_indexer(index1, method=method)
135
+ tm.assert_almost_equal(result, expected)
136
+
137
+ def test_get_indexer_invalid(self):
138
+ # GH10411
139
+ index = Index(np.arange(10))
140
+
141
+ with pytest.raises(ValueError, match="tolerance argument"):
142
+ index.get_indexer([1, 0], tolerance=1)
143
+
144
+ with pytest.raises(ValueError, match="limit argument"):
145
+ index.get_indexer([1, 0], limit=1)
146
+
147
+ @pytest.mark.parametrize(
148
+ "method, tolerance, indexer, expected",
149
+ [
150
+ ("pad", None, [0, 5, 9], [0, 5, 9]),
151
+ ("backfill", None, [0, 5, 9], [0, 5, 9]),
152
+ ("nearest", None, [0, 5, 9], [0, 5, 9]),
153
+ ("pad", 0, [0, 5, 9], [0, 5, 9]),
154
+ ("backfill", 0, [0, 5, 9], [0, 5, 9]),
155
+ ("nearest", 0, [0, 5, 9], [0, 5, 9]),
156
+ ("pad", None, [0.2, 1.8, 8.5], [0, 1, 8]),
157
+ ("backfill", None, [0.2, 1.8, 8.5], [1, 2, 9]),
158
+ ("nearest", None, [0.2, 1.8, 8.5], [0, 2, 9]),
159
+ ("pad", 1, [0.2, 1.8, 8.5], [0, 1, 8]),
160
+ ("backfill", 1, [0.2, 1.8, 8.5], [1, 2, 9]),
161
+ ("nearest", 1, [0.2, 1.8, 8.5], [0, 2, 9]),
162
+ ("pad", 0.2, [0.2, 1.8, 8.5], [0, -1, -1]),
163
+ ("backfill", 0.2, [0.2, 1.8, 8.5], [-1, 2, -1]),
164
+ ("nearest", 0.2, [0.2, 1.8, 8.5], [0, 2, -1]),
165
+ ],
166
+ )
167
+ def test_get_indexer_nearest(self, method, tolerance, indexer, expected):
168
+ index = Index(np.arange(10))
169
+
170
+ actual = index.get_indexer(indexer, method=method, tolerance=tolerance)
171
+ tm.assert_numpy_array_equal(actual, np.array(expected, dtype=np.intp))
172
+
173
+ @pytest.mark.parametrize("listtype", [list, tuple, Series, np.array])
174
+ @pytest.mark.parametrize(
175
+ "tolerance, expected",
176
+ list(
177
+ zip(
178
+ [[0.3, 0.3, 0.1], [0.2, 0.1, 0.1], [0.1, 0.5, 0.5]],
179
+ [[0, 2, -1], [0, -1, -1], [-1, 2, 9]],
180
+ )
181
+ ),
182
+ )
183
+ def test_get_indexer_nearest_listlike_tolerance(
184
+ self, tolerance, expected, listtype
185
+ ):
186
+ index = Index(np.arange(10))
187
+
188
+ actual = index.get_indexer(
189
+ [0.2, 1.8, 8.5], method="nearest", tolerance=listtype(tolerance)
190
+ )
191
+ tm.assert_numpy_array_equal(actual, np.array(expected, dtype=np.intp))
192
+
193
+ def test_get_indexer_nearest_error(self):
194
+ index = Index(np.arange(10))
195
+ with pytest.raises(ValueError, match="limit argument"):
196
+ index.get_indexer([1, 0], method="nearest", limit=1)
197
+
198
+ with pytest.raises(ValueError, match="tolerance size must match"):
199
+ index.get_indexer([1, 0], method="nearest", tolerance=[1, 2, 3])
200
+
201
+ @pytest.mark.parametrize(
202
+ "method,expected",
203
+ [("pad", [8, 7, 0]), ("backfill", [9, 8, 1]), ("nearest", [9, 7, 0])],
204
+ )
205
+ def test_get_indexer_nearest_decreasing(self, method, expected):
206
+ index = Index(np.arange(10))[::-1]
207
+
208
+ actual = index.get_indexer([0, 5, 9], method=method)
209
+ tm.assert_numpy_array_equal(actual, np.array([9, 4, 0], dtype=np.intp))
210
+
211
+ actual = index.get_indexer([0.2, 1.8, 8.5], method=method)
212
+ tm.assert_numpy_array_equal(actual, np.array(expected, dtype=np.intp))
213
+
214
+ @pytest.mark.parametrize("idx_dtype", ["int64", "float64", "uint64", "range"])
215
+ @pytest.mark.parametrize("method", ["get_indexer", "get_indexer_non_unique"])
216
+ def test_get_indexer_numeric_index_boolean_target(self, method, idx_dtype):
217
+ # GH 16877
218
+
219
+ if idx_dtype == "range":
220
+ numeric_index = RangeIndex(4)
221
+ else:
222
+ numeric_index = Index(np.arange(4, dtype=idx_dtype))
223
+
224
+ other = Index([True, False, True])
225
+
226
+ result = getattr(numeric_index, method)(other)
227
+ expected = np.array([-1, -1, -1], dtype=np.intp)
228
+ if method == "get_indexer":
229
+ tm.assert_numpy_array_equal(result, expected)
230
+ else:
231
+ missing = np.arange(3, dtype=np.intp)
232
+ tm.assert_numpy_array_equal(result[0], expected)
233
+ tm.assert_numpy_array_equal(result[1], missing)
234
+
235
+ @pytest.mark.parametrize("method", ["pad", "backfill", "nearest"])
236
+ def test_get_indexer_with_method_numeric_vs_bool(self, method):
237
+ left = Index([1, 2, 3])
238
+ right = Index([True, False])
239
+
240
+ with pytest.raises(TypeError, match="Cannot compare"):
241
+ left.get_indexer(right, method=method)
242
+
243
+ with pytest.raises(TypeError, match="Cannot compare"):
244
+ right.get_indexer(left, method=method)
245
+
246
+ def test_get_indexer_numeric_vs_bool(self):
247
+ left = Index([1, 2, 3])
248
+ right = Index([True, False])
249
+
250
+ res = left.get_indexer(right)
251
+ expected = -1 * np.ones(len(right), dtype=np.intp)
252
+ tm.assert_numpy_array_equal(res, expected)
253
+
254
+ res = right.get_indexer(left)
255
+ expected = -1 * np.ones(len(left), dtype=np.intp)
256
+ tm.assert_numpy_array_equal(res, expected)
257
+
258
+ res = left.get_indexer_non_unique(right)[0]
259
+ expected = -1 * np.ones(len(right), dtype=np.intp)
260
+ tm.assert_numpy_array_equal(res, expected)
261
+
262
+ res = right.get_indexer_non_unique(left)[0]
263
+ expected = -1 * np.ones(len(left), dtype=np.intp)
264
+ tm.assert_numpy_array_equal(res, expected)
265
+
266
+ def test_get_indexer_float64(self):
267
+ idx = Index([0.0, 1.0, 2.0], dtype=np.float64)
268
+ tm.assert_numpy_array_equal(
269
+ idx.get_indexer(idx), np.array([0, 1, 2], dtype=np.intp)
270
+ )
271
+
272
+ target = [-0.1, 0.5, 1.1]
273
+ tm.assert_numpy_array_equal(
274
+ idx.get_indexer(target, "pad"), np.array([-1, 0, 1], dtype=np.intp)
275
+ )
276
+ tm.assert_numpy_array_equal(
277
+ idx.get_indexer(target, "backfill"), np.array([0, 1, 2], dtype=np.intp)
278
+ )
279
+ tm.assert_numpy_array_equal(
280
+ idx.get_indexer(target, "nearest"), np.array([0, 1, 1], dtype=np.intp)
281
+ )
282
+
283
+ def test_get_indexer_nan(self):
284
+ # GH#7820
285
+ result = Index([1, 2, np.nan], dtype=np.float64).get_indexer([np.nan])
286
+ expected = np.array([2], dtype=np.intp)
287
+ tm.assert_numpy_array_equal(result, expected)
288
+
289
+ def test_get_indexer_int64(self):
290
+ index = Index(range(0, 20, 2), dtype=np.int64)
291
+ target = Index(np.arange(10), dtype=np.int64)
292
+ indexer = index.get_indexer(target)
293
+ expected = np.array([0, -1, 1, -1, 2, -1, 3, -1, 4, -1], dtype=np.intp)
294
+ tm.assert_numpy_array_equal(indexer, expected)
295
+
296
+ target = Index(np.arange(10), dtype=np.int64)
297
+ indexer = index.get_indexer(target, method="pad")
298
+ expected = np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4], dtype=np.intp)
299
+ tm.assert_numpy_array_equal(indexer, expected)
300
+
301
+ target = Index(np.arange(10), dtype=np.int64)
302
+ indexer = index.get_indexer(target, method="backfill")
303
+ expected = np.array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5], dtype=np.intp)
304
+ tm.assert_numpy_array_equal(indexer, expected)
305
+
306
+ def test_get_indexer_uint64(self, index_large):
307
+ target = Index(np.arange(10).astype("uint64") * 5 + 2**63)
308
+ indexer = index_large.get_indexer(target)
309
+ expected = np.array([0, -1, 1, 2, 3, 4, -1, -1, -1, -1], dtype=np.intp)
310
+ tm.assert_numpy_array_equal(indexer, expected)
311
+
312
+ target = Index(np.arange(10).astype("uint64") * 5 + 2**63)
313
+ indexer = index_large.get_indexer(target, method="pad")
314
+ expected = np.array([0, 0, 1, 2, 3, 4, 4, 4, 4, 4], dtype=np.intp)
315
+ tm.assert_numpy_array_equal(indexer, expected)
316
+
317
+ target = Index(np.arange(10).astype("uint64") * 5 + 2**63)
318
+ indexer = index_large.get_indexer(target, method="backfill")
319
+ expected = np.array([0, 1, 1, 2, 3, 4, -1, -1, -1, -1], dtype=np.intp)
320
+ tm.assert_numpy_array_equal(indexer, expected)
321
+
322
+ @pytest.mark.parametrize("val, val2", [(4, 5), (4, 4), (4, NA), (NA, NA)])
323
+ def test_get_loc_masked(self, val, val2, any_numeric_ea_and_arrow_dtype):
324
+ # GH#39133
325
+ idx = Index([1, 2, 3, val, val2], dtype=any_numeric_ea_and_arrow_dtype)
326
+ result = idx.get_loc(2)
327
+ assert result == 1
328
+
329
+ with pytest.raises(KeyError, match="9"):
330
+ idx.get_loc(9)
331
+
332
+ def test_get_loc_masked_na(self, any_numeric_ea_and_arrow_dtype):
333
+ # GH#39133
334
+ idx = Index([1, 2, NA], dtype=any_numeric_ea_and_arrow_dtype)
335
+ result = idx.get_loc(NA)
336
+ assert result == 2
337
+
338
+ idx = Index([1, 2, NA, NA], dtype=any_numeric_ea_and_arrow_dtype)
339
+ result = idx.get_loc(NA)
340
+ tm.assert_numpy_array_equal(result, np.array([False, False, True, True]))
341
+
342
+ idx = Index([1, 2, 3], dtype=any_numeric_ea_and_arrow_dtype)
343
+ with pytest.raises(KeyError, match="NA"):
344
+ idx.get_loc(NA)
345
+
346
+ def test_get_loc_masked_na_and_nan(self):
347
+ # GH#39133
348
+ idx = Index(
349
+ FloatingArray(
350
+ np.array([1, 2, 1, np.nan]), mask=np.array([False, False, True, False])
351
+ )
352
+ )
353
+ result = idx.get_loc(NA)
354
+ assert result == 2
355
+ result = idx.get_loc(np.nan)
356
+ assert result == 3
357
+
358
+ idx = Index(
359
+ FloatingArray(np.array([1, 2, 1.0]), mask=np.array([False, False, True]))
360
+ )
361
+ result = idx.get_loc(NA)
362
+ assert result == 2
363
+ with pytest.raises(KeyError, match="nan"):
364
+ idx.get_loc(np.nan)
365
+
366
+ idx = Index(
367
+ FloatingArray(
368
+ np.array([1, 2, np.nan]), mask=np.array([False, False, False])
369
+ )
370
+ )
371
+ result = idx.get_loc(np.nan)
372
+ assert result == 2
373
+ with pytest.raises(KeyError, match="NA"):
374
+ idx.get_loc(NA)
375
+
376
+ @pytest.mark.parametrize("val", [4, 2])
377
+ def test_get_indexer_masked_na(self, any_numeric_ea_and_arrow_dtype, val):
378
+ # GH#39133
379
+ idx = Index([1, 2, NA, 3, val], dtype=any_numeric_ea_and_arrow_dtype)
380
+ result = idx.get_indexer_for([1, NA, 5])
381
+ expected = np.array([0, 2, -1])
382
+ tm.assert_numpy_array_equal(result, expected, check_dtype=False)
383
+
384
+ @pytest.mark.parametrize("dtype", ["boolean", "bool[pyarrow]"])
385
+ def test_get_indexer_masked_na_boolean(self, dtype):
386
+ # GH#39133
387
+ if dtype == "bool[pyarrow]":
388
+ pytest.importorskip("pyarrow")
389
+ idx = Index([True, False, NA], dtype=dtype)
390
+ result = idx.get_loc(False)
391
+ assert result == 1
392
+ result = idx.get_loc(NA)
393
+ assert result == 2
394
+
395
+ def test_get_indexer_arrow_dictionary_target(self):
396
+ pa = pytest.importorskip("pyarrow")
397
+ target = Index(
398
+ ArrowExtensionArray(
399
+ pa.array([1, 2], type=pa.dictionary(pa.int8(), pa.int8()))
400
+ )
401
+ )
402
+ idx = Index([1])
403
+
404
+ result = idx.get_indexer(target)
405
+ expected = np.array([0, -1], dtype=np.int64)
406
+ tm.assert_numpy_array_equal(result, expected)
407
+
408
+ result_1, result_2 = idx.get_indexer_non_unique(target)
409
+ expected_1, expected_2 = np.array([0, -1], dtype=np.int64), np.array(
410
+ [1], dtype=np.int64
411
+ )
412
+ tm.assert_numpy_array_equal(result_1, expected_1)
413
+ tm.assert_numpy_array_equal(result_2, expected_2)
414
+
415
+
416
+ class TestWhere:
417
+ @pytest.mark.parametrize(
418
+ "index",
419
+ [
420
+ Index(np.arange(5, dtype="float64")),
421
+ Index(range(0, 20, 2), dtype=np.int64),
422
+ Index(np.arange(5, dtype="uint64")),
423
+ ],
424
+ )
425
+ def test_where(self, listlike_box, index):
426
+ cond = [True] * len(index)
427
+ expected = index
428
+ result = index.where(listlike_box(cond))
429
+
430
+ cond = [False] + [True] * (len(index) - 1)
431
+ expected = Index([index._na_value] + index[1:].tolist(), dtype=np.float64)
432
+ result = index.where(listlike_box(cond))
433
+ tm.assert_index_equal(result, expected)
434
+
435
+ def test_where_uint64(self):
436
+ idx = Index([0, 6, 2], dtype=np.uint64)
437
+ mask = np.array([False, True, False])
438
+ other = np.array([1], dtype=np.int64)
439
+
440
+ expected = Index([1, 6, 1], dtype=np.uint64)
441
+
442
+ result = idx.where(mask, other)
443
+ tm.assert_index_equal(result, expected)
444
+
445
+ result = idx.putmask(~mask, other)
446
+ tm.assert_index_equal(result, expected)
447
+
448
+ def test_where_infers_type_instead_of_trying_to_convert_string_to_float(self):
449
+ # GH 32413
450
+ index = Index([1, np.nan])
451
+ cond = index.notna()
452
+ other = Index(["a", "b"], dtype="string")
453
+
454
+ expected = Index([1.0, "b"])
455
+ result = index.where(cond, other)
456
+
457
+ tm.assert_index_equal(result, expected)
458
+
459
+
460
+ class TestTake:
461
+ @pytest.mark.parametrize("idx_dtype", [np.float64, np.int64, np.uint64])
462
+ def test_take_preserve_name(self, idx_dtype):
463
+ index = Index([1, 2, 3, 4], dtype=idx_dtype, name="foo")
464
+ taken = index.take([3, 0, 1])
465
+ assert index.name == taken.name
466
+
467
+ def test_take_fill_value_float64(self):
468
+ # GH 12631
469
+ idx = Index([1.0, 2.0, 3.0], name="xxx", dtype=np.float64)
470
+ result = idx.take(np.array([1, 0, -1]))
471
+ expected = Index([2.0, 1.0, 3.0], dtype=np.float64, name="xxx")
472
+ tm.assert_index_equal(result, expected)
473
+
474
+ # fill_value
475
+ result = idx.take(np.array([1, 0, -1]), fill_value=True)
476
+ expected = Index([2.0, 1.0, np.nan], dtype=np.float64, name="xxx")
477
+ tm.assert_index_equal(result, expected)
478
+
479
+ # allow_fill=False
480
+ result = idx.take(np.array([1, 0, -1]), allow_fill=False, fill_value=True)
481
+ expected = Index([2.0, 1.0, 3.0], dtype=np.float64, name="xxx")
482
+ tm.assert_index_equal(result, expected)
483
+
484
+ msg = (
485
+ "When allow_fill=True and fill_value is not None, "
486
+ "all indices must be >= -1"
487
+ )
488
+ with pytest.raises(ValueError, match=msg):
489
+ idx.take(np.array([1, 0, -2]), fill_value=True)
490
+ with pytest.raises(ValueError, match=msg):
491
+ idx.take(np.array([1, 0, -5]), fill_value=True)
492
+
493
+ msg = "index -5 is out of bounds for (axis 0 with )?size 3"
494
+ with pytest.raises(IndexError, match=msg):
495
+ idx.take(np.array([1, -5]))
496
+
497
+ @pytest.mark.parametrize("dtype", [np.int64, np.uint64])
498
+ def test_take_fill_value_ints(self, dtype):
499
+ # see gh-12631
500
+ idx = Index([1, 2, 3], dtype=dtype, name="xxx")
501
+ result = idx.take(np.array([1, 0, -1]))
502
+ expected = Index([2, 1, 3], dtype=dtype, name="xxx")
503
+ tm.assert_index_equal(result, expected)
504
+
505
+ name = type(idx).__name__
506
+ msg = f"Unable to fill values because {name} cannot contain NA"
507
+
508
+ # fill_value=True
509
+ with pytest.raises(ValueError, match=msg):
510
+ idx.take(np.array([1, 0, -1]), fill_value=True)
511
+
512
+ # allow_fill=False
513
+ result = idx.take(np.array([1, 0, -1]), allow_fill=False, fill_value=True)
514
+ expected = Index([2, 1, 3], dtype=dtype, name="xxx")
515
+ tm.assert_index_equal(result, expected)
516
+
517
+ with pytest.raises(ValueError, match=msg):
518
+ idx.take(np.array([1, 0, -2]), fill_value=True)
519
+ with pytest.raises(ValueError, match=msg):
520
+ idx.take(np.array([1, 0, -5]), fill_value=True)
521
+
522
+ msg = "index -5 is out of bounds for (axis 0 with )?size 3"
523
+ with pytest.raises(IndexError, match=msg):
524
+ idx.take(np.array([1, -5]))
525
+
526
+
527
+ class TestContains:
528
+ @pytest.mark.parametrize("dtype", [np.float64, np.int64, np.uint64])
529
+ def test_contains_none(self, dtype):
530
+ # GH#35788 should return False, not raise TypeError
531
+ index = Index([0, 1, 2, 3, 4], dtype=dtype)
532
+ assert None not in index
533
+
534
+ def test_contains_float64_nans(self):
535
+ index = Index([1.0, 2.0, np.nan], dtype=np.float64)
536
+ assert np.nan in index
537
+
538
+ def test_contains_float64_not_nans(self):
539
+ index = Index([1.0, 2.0, np.nan], dtype=np.float64)
540
+ assert 1.0 in index
541
+
542
+
543
+ class TestSliceLocs:
544
+ @pytest.mark.parametrize("dtype", [int, float])
545
+ def test_slice_locs(self, dtype):
546
+ index = Index(np.array([0, 1, 2, 5, 6, 7, 9, 10], dtype=dtype))
547
+ n = len(index)
548
+
549
+ assert index.slice_locs(start=2) == (2, n)
550
+ assert index.slice_locs(start=3) == (3, n)
551
+ assert index.slice_locs(3, 8) == (3, 6)
552
+ assert index.slice_locs(5, 10) == (3, n)
553
+ assert index.slice_locs(end=8) == (0, 6)
554
+ assert index.slice_locs(end=9) == (0, 7)
555
+
556
+ # reversed
557
+ index2 = index[::-1]
558
+ assert index2.slice_locs(8, 2) == (2, 6)
559
+ assert index2.slice_locs(7, 3) == (2, 5)
560
+
561
+ @pytest.mark.parametrize("dtype", [int, float])
562
+ def test_slice_locs_float_locs(self, dtype):
563
+ index = Index(np.array([0, 1, 2, 5, 6, 7, 9, 10], dtype=dtype))
564
+ n = len(index)
565
+ assert index.slice_locs(5.0, 10.0) == (3, n)
566
+ assert index.slice_locs(4.5, 10.5) == (3, 8)
567
+
568
+ index2 = index[::-1]
569
+ assert index2.slice_locs(8.5, 1.5) == (2, 6)
570
+ assert index2.slice_locs(10.5, -1) == (0, n)
571
+
572
+ @pytest.mark.parametrize("dtype", [int, float])
573
+ def test_slice_locs_dup_numeric(self, dtype):
574
+ index = Index(np.array([10, 12, 12, 14], dtype=dtype))
575
+ assert index.slice_locs(12, 12) == (1, 3)
576
+ assert index.slice_locs(11, 13) == (1, 3)
577
+
578
+ index2 = index[::-1]
579
+ assert index2.slice_locs(12, 12) == (1, 3)
580
+ assert index2.slice_locs(13, 11) == (1, 3)
581
+
582
+ def test_slice_locs_na(self):
583
+ index = Index([np.nan, 1, 2])
584
+ assert index.slice_locs(1) == (1, 3)
585
+ assert index.slice_locs(np.nan) == (0, 3)
586
+
587
+ index = Index([0, np.nan, np.nan, 1, 2])
588
+ assert index.slice_locs(np.nan) == (1, 5)
589
+
590
+ def test_slice_locs_na_raises(self):
591
+ index = Index([np.nan, 1, 2])
592
+ with pytest.raises(KeyError, match=""):
593
+ index.slice_locs(start=1.5)
594
+
595
+ with pytest.raises(KeyError, match=""):
596
+ index.slice_locs(end=1.5)
597
+
598
+
599
+ class TestGetSliceBounds:
600
+ @pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)])
601
+ def test_get_slice_bounds_within(self, side, expected):
602
+ index = Index(range(6))
603
+ result = index.get_slice_bound(4, side=side)
604
+ assert result == expected
605
+
606
+ @pytest.mark.parametrize("side", ["left", "right"])
607
+ @pytest.mark.parametrize("bound, expected", [(-1, 0), (10, 6)])
608
+ def test_get_slice_bounds_outside(self, side, expected, bound):
609
+ index = Index(range(6))
610
+ result = index.get_slice_bound(bound, side=side)
611
+ assert result == expected
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_join.py ADDED
@@ -0,0 +1,380 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas._testing as tm
5
+ from pandas.core.indexes.api import Index
6
+
7
+
8
+ class TestJoinInt64Index:
9
+ def test_join_non_unique(self):
10
+ left = Index([4, 4, 3, 3])
11
+
12
+ joined, lidx, ridx = left.join(left, return_indexers=True)
13
+
14
+ exp_joined = Index([4, 4, 4, 4, 3, 3, 3, 3])
15
+ tm.assert_index_equal(joined, exp_joined)
16
+
17
+ exp_lidx = np.array([0, 0, 1, 1, 2, 2, 3, 3], dtype=np.intp)
18
+ tm.assert_numpy_array_equal(lidx, exp_lidx)
19
+
20
+ exp_ridx = np.array([0, 1, 0, 1, 2, 3, 2, 3], dtype=np.intp)
21
+ tm.assert_numpy_array_equal(ridx, exp_ridx)
22
+
23
+ def test_join_inner(self):
24
+ index = Index(range(0, 20, 2), dtype=np.int64)
25
+ other = Index([7, 12, 25, 1, 2, 5], dtype=np.int64)
26
+ other_mono = Index([1, 2, 5, 7, 12, 25], dtype=np.int64)
27
+
28
+ # not monotonic
29
+ res, lidx, ridx = index.join(other, how="inner", return_indexers=True)
30
+
31
+ # no guarantee of sortedness, so sort for comparison purposes
32
+ ind = res.argsort()
33
+ res = res.take(ind)
34
+ lidx = lidx.take(ind)
35
+ ridx = ridx.take(ind)
36
+
37
+ eres = Index([2, 12], dtype=np.int64)
38
+ elidx = np.array([1, 6], dtype=np.intp)
39
+ eridx = np.array([4, 1], dtype=np.intp)
40
+
41
+ assert isinstance(res, Index) and res.dtype == np.int64
42
+ tm.assert_index_equal(res, eres)
43
+ tm.assert_numpy_array_equal(lidx, elidx)
44
+ tm.assert_numpy_array_equal(ridx, eridx)
45
+
46
+ # monotonic
47
+ res, lidx, ridx = index.join(other_mono, how="inner", return_indexers=True)
48
+
49
+ res2 = index.intersection(other_mono)
50
+ tm.assert_index_equal(res, res2)
51
+
52
+ elidx = np.array([1, 6], dtype=np.intp)
53
+ eridx = np.array([1, 4], dtype=np.intp)
54
+ assert isinstance(res, Index) and res.dtype == np.int64
55
+ tm.assert_index_equal(res, eres)
56
+ tm.assert_numpy_array_equal(lidx, elidx)
57
+ tm.assert_numpy_array_equal(ridx, eridx)
58
+
59
+ def test_join_left(self):
60
+ index = Index(range(0, 20, 2), dtype=np.int64)
61
+ other = Index([7, 12, 25, 1, 2, 5], dtype=np.int64)
62
+ other_mono = Index([1, 2, 5, 7, 12, 25], dtype=np.int64)
63
+
64
+ # not monotonic
65
+ res, lidx, ridx = index.join(other, how="left", return_indexers=True)
66
+ eres = index
67
+ eridx = np.array([-1, 4, -1, -1, -1, -1, 1, -1, -1, -1], dtype=np.intp)
68
+
69
+ assert isinstance(res, Index) and res.dtype == np.int64
70
+ tm.assert_index_equal(res, eres)
71
+ assert lidx is None
72
+ tm.assert_numpy_array_equal(ridx, eridx)
73
+
74
+ # monotonic
75
+ res, lidx, ridx = index.join(other_mono, how="left", return_indexers=True)
76
+ eridx = np.array([-1, 1, -1, -1, -1, -1, 4, -1, -1, -1], dtype=np.intp)
77
+ assert isinstance(res, Index) and res.dtype == np.int64
78
+ tm.assert_index_equal(res, eres)
79
+ assert lidx is None
80
+ tm.assert_numpy_array_equal(ridx, eridx)
81
+
82
+ # non-unique
83
+ idx = Index([1, 1, 2, 5])
84
+ idx2 = Index([1, 2, 5, 7, 9])
85
+ res, lidx, ridx = idx2.join(idx, how="left", return_indexers=True)
86
+ eres = Index([1, 1, 2, 5, 7, 9]) # 1 is in idx2, so it should be x2
87
+ eridx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp)
88
+ elidx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp)
89
+ tm.assert_index_equal(res, eres)
90
+ tm.assert_numpy_array_equal(lidx, elidx)
91
+ tm.assert_numpy_array_equal(ridx, eridx)
92
+
93
+ def test_join_right(self):
94
+ index = Index(range(0, 20, 2), dtype=np.int64)
95
+ other = Index([7, 12, 25, 1, 2, 5], dtype=np.int64)
96
+ other_mono = Index([1, 2, 5, 7, 12, 25], dtype=np.int64)
97
+
98
+ # not monotonic
99
+ res, lidx, ridx = index.join(other, how="right", return_indexers=True)
100
+ eres = other
101
+ elidx = np.array([-1, 6, -1, -1, 1, -1], dtype=np.intp)
102
+
103
+ assert isinstance(other, Index) and other.dtype == np.int64
104
+ tm.assert_index_equal(res, eres)
105
+ tm.assert_numpy_array_equal(lidx, elidx)
106
+ assert ridx is None
107
+
108
+ # monotonic
109
+ res, lidx, ridx = index.join(other_mono, how="right", return_indexers=True)
110
+ eres = other_mono
111
+ elidx = np.array([-1, 1, -1, -1, 6, -1], dtype=np.intp)
112
+ assert isinstance(other, Index) and other.dtype == np.int64
113
+ tm.assert_index_equal(res, eres)
114
+ tm.assert_numpy_array_equal(lidx, elidx)
115
+ assert ridx is None
116
+
117
+ # non-unique
118
+ idx = Index([1, 1, 2, 5])
119
+ idx2 = Index([1, 2, 5, 7, 9])
120
+ res, lidx, ridx = idx.join(idx2, how="right", return_indexers=True)
121
+ eres = Index([1, 1, 2, 5, 7, 9]) # 1 is in idx2, so it should be x2
122
+ elidx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp)
123
+ eridx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp)
124
+ tm.assert_index_equal(res, eres)
125
+ tm.assert_numpy_array_equal(lidx, elidx)
126
+ tm.assert_numpy_array_equal(ridx, eridx)
127
+
128
+ def test_join_non_int_index(self):
129
+ index = Index(range(0, 20, 2), dtype=np.int64)
130
+ other = Index([3, 6, 7, 8, 10], dtype=object)
131
+
132
+ outer = index.join(other, how="outer")
133
+ outer2 = other.join(index, how="outer")
134
+ expected = Index([0, 2, 3, 4, 6, 7, 8, 10, 12, 14, 16, 18])
135
+ tm.assert_index_equal(outer, outer2)
136
+ tm.assert_index_equal(outer, expected)
137
+
138
+ inner = index.join(other, how="inner")
139
+ inner2 = other.join(index, how="inner")
140
+ expected = Index([6, 8, 10])
141
+ tm.assert_index_equal(inner, inner2)
142
+ tm.assert_index_equal(inner, expected)
143
+
144
+ left = index.join(other, how="left")
145
+ tm.assert_index_equal(left, index.astype(object))
146
+
147
+ left2 = other.join(index, how="left")
148
+ tm.assert_index_equal(left2, other)
149
+
150
+ right = index.join(other, how="right")
151
+ tm.assert_index_equal(right, other)
152
+
153
+ right2 = other.join(index, how="right")
154
+ tm.assert_index_equal(right2, index.astype(object))
155
+
156
+ def test_join_outer(self):
157
+ index = Index(range(0, 20, 2), dtype=np.int64)
158
+ other = Index([7, 12, 25, 1, 2, 5], dtype=np.int64)
159
+ other_mono = Index([1, 2, 5, 7, 12, 25], dtype=np.int64)
160
+
161
+ # not monotonic
162
+ # guarantee of sortedness
163
+ res, lidx, ridx = index.join(other, how="outer", return_indexers=True)
164
+ noidx_res = index.join(other, how="outer")
165
+ tm.assert_index_equal(res, noidx_res)
166
+
167
+ eres = Index([0, 1, 2, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 25], dtype=np.int64)
168
+ elidx = np.array([0, -1, 1, 2, -1, 3, -1, 4, 5, 6, 7, 8, 9, -1], dtype=np.intp)
169
+ eridx = np.array(
170
+ [-1, 3, 4, -1, 5, -1, 0, -1, -1, 1, -1, -1, -1, 2], dtype=np.intp
171
+ )
172
+
173
+ assert isinstance(res, Index) and res.dtype == np.int64
174
+ tm.assert_index_equal(res, eres)
175
+ tm.assert_numpy_array_equal(lidx, elidx)
176
+ tm.assert_numpy_array_equal(ridx, eridx)
177
+
178
+ # monotonic
179
+ res, lidx, ridx = index.join(other_mono, how="outer", return_indexers=True)
180
+ noidx_res = index.join(other_mono, how="outer")
181
+ tm.assert_index_equal(res, noidx_res)
182
+
183
+ elidx = np.array([0, -1, 1, 2, -1, 3, -1, 4, 5, 6, 7, 8, 9, -1], dtype=np.intp)
184
+ eridx = np.array(
185
+ [-1, 0, 1, -1, 2, -1, 3, -1, -1, 4, -1, -1, -1, 5], dtype=np.intp
186
+ )
187
+ assert isinstance(res, Index) and res.dtype == np.int64
188
+ tm.assert_index_equal(res, eres)
189
+ tm.assert_numpy_array_equal(lidx, elidx)
190
+ tm.assert_numpy_array_equal(ridx, eridx)
191
+
192
+
193
+ class TestJoinUInt64Index:
194
+ @pytest.fixture
195
+ def index_large(self):
196
+ # large values used in TestUInt64Index where no compat needed with int64/float64
197
+ large = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25]
198
+ return Index(large, dtype=np.uint64)
199
+
200
+ def test_join_inner(self, index_large):
201
+ other = Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64"))
202
+ other_mono = Index(2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64"))
203
+
204
+ # not monotonic
205
+ res, lidx, ridx = index_large.join(other, how="inner", return_indexers=True)
206
+
207
+ # no guarantee of sortedness, so sort for comparison purposes
208
+ ind = res.argsort()
209
+ res = res.take(ind)
210
+ lidx = lidx.take(ind)
211
+ ridx = ridx.take(ind)
212
+
213
+ eres = Index(2**63 + np.array([10, 25], dtype="uint64"))
214
+ elidx = np.array([1, 4], dtype=np.intp)
215
+ eridx = np.array([5, 2], dtype=np.intp)
216
+
217
+ assert isinstance(res, Index) and res.dtype == np.uint64
218
+ tm.assert_index_equal(res, eres)
219
+ tm.assert_numpy_array_equal(lidx, elidx)
220
+ tm.assert_numpy_array_equal(ridx, eridx)
221
+
222
+ # monotonic
223
+ res, lidx, ridx = index_large.join(
224
+ other_mono, how="inner", return_indexers=True
225
+ )
226
+
227
+ res2 = index_large.intersection(other_mono)
228
+ tm.assert_index_equal(res, res2)
229
+
230
+ elidx = np.array([1, 4], dtype=np.intp)
231
+ eridx = np.array([3, 5], dtype=np.intp)
232
+
233
+ assert isinstance(res, Index) and res.dtype == np.uint64
234
+ tm.assert_index_equal(res, eres)
235
+ tm.assert_numpy_array_equal(lidx, elidx)
236
+ tm.assert_numpy_array_equal(ridx, eridx)
237
+
238
+ def test_join_left(self, index_large):
239
+ other = Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64"))
240
+ other_mono = Index(2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64"))
241
+
242
+ # not monotonic
243
+ res, lidx, ridx = index_large.join(other, how="left", return_indexers=True)
244
+ eres = index_large
245
+ eridx = np.array([-1, 5, -1, -1, 2], dtype=np.intp)
246
+
247
+ assert isinstance(res, Index) and res.dtype == np.uint64
248
+ tm.assert_index_equal(res, eres)
249
+ assert lidx is None
250
+ tm.assert_numpy_array_equal(ridx, eridx)
251
+
252
+ # monotonic
253
+ res, lidx, ridx = index_large.join(other_mono, how="left", return_indexers=True)
254
+ eridx = np.array([-1, 3, -1, -1, 5], dtype=np.intp)
255
+
256
+ assert isinstance(res, Index) and res.dtype == np.uint64
257
+ tm.assert_index_equal(res, eres)
258
+ assert lidx is None
259
+ tm.assert_numpy_array_equal(ridx, eridx)
260
+
261
+ # non-unique
262
+ idx = Index(2**63 + np.array([1, 1, 2, 5], dtype="uint64"))
263
+ idx2 = Index(2**63 + np.array([1, 2, 5, 7, 9], dtype="uint64"))
264
+ res, lidx, ridx = idx2.join(idx, how="left", return_indexers=True)
265
+
266
+ # 1 is in idx2, so it should be x2
267
+ eres = Index(2**63 + np.array([1, 1, 2, 5, 7, 9], dtype="uint64"))
268
+ eridx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp)
269
+ elidx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp)
270
+
271
+ tm.assert_index_equal(res, eres)
272
+ tm.assert_numpy_array_equal(lidx, elidx)
273
+ tm.assert_numpy_array_equal(ridx, eridx)
274
+
275
+ def test_join_right(self, index_large):
276
+ other = Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64"))
277
+ other_mono = Index(2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64"))
278
+
279
+ # not monotonic
280
+ res, lidx, ridx = index_large.join(other, how="right", return_indexers=True)
281
+ eres = other
282
+ elidx = np.array([-1, -1, 4, -1, -1, 1], dtype=np.intp)
283
+
284
+ tm.assert_numpy_array_equal(lidx, elidx)
285
+ assert isinstance(other, Index) and other.dtype == np.uint64
286
+ tm.assert_index_equal(res, eres)
287
+ assert ridx is None
288
+
289
+ # monotonic
290
+ res, lidx, ridx = index_large.join(
291
+ other_mono, how="right", return_indexers=True
292
+ )
293
+ eres = other_mono
294
+ elidx = np.array([-1, -1, -1, 1, -1, 4], dtype=np.intp)
295
+
296
+ assert isinstance(other, Index) and other.dtype == np.uint64
297
+ tm.assert_numpy_array_equal(lidx, elidx)
298
+ tm.assert_index_equal(res, eres)
299
+ assert ridx is None
300
+
301
+ # non-unique
302
+ idx = Index(2**63 + np.array([1, 1, 2, 5], dtype="uint64"))
303
+ idx2 = Index(2**63 + np.array([1, 2, 5, 7, 9], dtype="uint64"))
304
+ res, lidx, ridx = idx.join(idx2, how="right", return_indexers=True)
305
+
306
+ # 1 is in idx2, so it should be x2
307
+ eres = Index(2**63 + np.array([1, 1, 2, 5, 7, 9], dtype="uint64"))
308
+ elidx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp)
309
+ eridx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp)
310
+
311
+ tm.assert_index_equal(res, eres)
312
+ tm.assert_numpy_array_equal(lidx, elidx)
313
+ tm.assert_numpy_array_equal(ridx, eridx)
314
+
315
+ def test_join_non_int_index(self, index_large):
316
+ other = Index(
317
+ 2**63 + np.array([1, 5, 7, 10, 20], dtype="uint64"), dtype=object
318
+ )
319
+
320
+ outer = index_large.join(other, how="outer")
321
+ outer2 = other.join(index_large, how="outer")
322
+ expected = Index(
323
+ 2**63 + np.array([0, 1, 5, 7, 10, 15, 20, 25], dtype="uint64")
324
+ )
325
+ tm.assert_index_equal(outer, outer2)
326
+ tm.assert_index_equal(outer, expected)
327
+
328
+ inner = index_large.join(other, how="inner")
329
+ inner2 = other.join(index_large, how="inner")
330
+ expected = Index(2**63 + np.array([10, 20], dtype="uint64"))
331
+ tm.assert_index_equal(inner, inner2)
332
+ tm.assert_index_equal(inner, expected)
333
+
334
+ left = index_large.join(other, how="left")
335
+ tm.assert_index_equal(left, index_large.astype(object))
336
+
337
+ left2 = other.join(index_large, how="left")
338
+ tm.assert_index_equal(left2, other)
339
+
340
+ right = index_large.join(other, how="right")
341
+ tm.assert_index_equal(right, other)
342
+
343
+ right2 = other.join(index_large, how="right")
344
+ tm.assert_index_equal(right2, index_large.astype(object))
345
+
346
+ def test_join_outer(self, index_large):
347
+ other = Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64"))
348
+ other_mono = Index(2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64"))
349
+
350
+ # not monotonic
351
+ # guarantee of sortedness
352
+ res, lidx, ridx = index_large.join(other, how="outer", return_indexers=True)
353
+ noidx_res = index_large.join(other, how="outer")
354
+ tm.assert_index_equal(res, noidx_res)
355
+
356
+ eres = Index(
357
+ 2**63 + np.array([0, 1, 2, 7, 10, 12, 15, 20, 25], dtype="uint64")
358
+ )
359
+ elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp)
360
+ eridx = np.array([-1, 3, 4, 0, 5, 1, -1, -1, 2], dtype=np.intp)
361
+
362
+ assert isinstance(res, Index) and res.dtype == np.uint64
363
+ tm.assert_index_equal(res, eres)
364
+ tm.assert_numpy_array_equal(lidx, elidx)
365
+ tm.assert_numpy_array_equal(ridx, eridx)
366
+
367
+ # monotonic
368
+ res, lidx, ridx = index_large.join(
369
+ other_mono, how="outer", return_indexers=True
370
+ )
371
+ noidx_res = index_large.join(other_mono, how="outer")
372
+ tm.assert_index_equal(res, noidx_res)
373
+
374
+ elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp)
375
+ eridx = np.array([-1, 0, 1, 2, 3, 4, -1, -1, 5], dtype=np.intp)
376
+
377
+ assert isinstance(res, Index) and res.dtype == np.uint64
378
+ tm.assert_index_equal(res, eres)
379
+ tm.assert_numpy_array_equal(lidx, elidx)
380
+ tm.assert_numpy_array_equal(ridx, eridx)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_numeric.py ADDED
@@ -0,0 +1,553 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Index,
7
+ Series,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ class TestFloatNumericIndex:
13
+ @pytest.fixture(params=[np.float64, np.float32])
14
+ def dtype(self, request):
15
+ return request.param
16
+
17
+ @pytest.fixture
18
+ def simple_index(self, dtype):
19
+ values = np.arange(5, dtype=dtype)
20
+ return Index(values)
21
+
22
+ @pytest.fixture(
23
+ params=[
24
+ [1.5, 2, 3, 4, 5],
25
+ [0.0, 2.5, 5.0, 7.5, 10.0],
26
+ [5, 4, 3, 2, 1.5],
27
+ [10.0, 7.5, 5.0, 2.5, 0.0],
28
+ ],
29
+ ids=["mixed", "float", "mixed_dec", "float_dec"],
30
+ )
31
+ def index(self, request, dtype):
32
+ return Index(request.param, dtype=dtype)
33
+
34
+ @pytest.fixture
35
+ def mixed_index(self, dtype):
36
+ return Index([1.5, 2, 3, 4, 5], dtype=dtype)
37
+
38
+ @pytest.fixture
39
+ def float_index(self, dtype):
40
+ return Index([0.0, 2.5, 5.0, 7.5, 10.0], dtype=dtype)
41
+
42
+ def test_repr_roundtrip(self, index):
43
+ tm.assert_index_equal(eval(repr(index)), index, exact=True)
44
+
45
+ def check_coerce(self, a, b, is_float_index=True):
46
+ assert a.equals(b)
47
+ tm.assert_index_equal(a, b, exact=False)
48
+ if is_float_index:
49
+ assert isinstance(b, Index)
50
+ else:
51
+ assert type(b) is Index
52
+
53
+ def test_constructor_from_list_no_dtype(self):
54
+ index = Index([1.5, 2.5, 3.5])
55
+ assert index.dtype == np.float64
56
+
57
+ def test_constructor(self, dtype):
58
+ index_cls = Index
59
+
60
+ # explicit construction
61
+ index = index_cls([1, 2, 3, 4, 5], dtype=dtype)
62
+
63
+ assert isinstance(index, index_cls)
64
+ assert index.dtype == dtype
65
+
66
+ expected = np.array([1, 2, 3, 4, 5], dtype=dtype)
67
+ tm.assert_numpy_array_equal(index.values, expected)
68
+
69
+ index = index_cls(np.array([1, 2, 3, 4, 5]), dtype=dtype)
70
+ assert isinstance(index, index_cls)
71
+ assert index.dtype == dtype
72
+
73
+ index = index_cls([1.0, 2, 3, 4, 5], dtype=dtype)
74
+ assert isinstance(index, index_cls)
75
+ assert index.dtype == dtype
76
+
77
+ index = index_cls(np.array([1.0, 2, 3, 4, 5]), dtype=dtype)
78
+ assert isinstance(index, index_cls)
79
+ assert index.dtype == dtype
80
+
81
+ index = index_cls([1.0, 2, 3, 4, 5], dtype=dtype)
82
+ assert isinstance(index, index_cls)
83
+ assert index.dtype == dtype
84
+
85
+ index = index_cls(np.array([1.0, 2, 3, 4, 5]), dtype=dtype)
86
+ assert isinstance(index, index_cls)
87
+ assert index.dtype == dtype
88
+
89
+ # nan handling
90
+ result = index_cls([np.nan, np.nan], dtype=dtype)
91
+ assert pd.isna(result.values).all()
92
+
93
+ result = index_cls(np.array([np.nan]), dtype=dtype)
94
+ assert pd.isna(result.values).all()
95
+
96
+ def test_constructor_invalid(self):
97
+ index_cls = Index
98
+ cls_name = index_cls.__name__
99
+ # invalid
100
+ msg = (
101
+ rf"{cls_name}\(\.\.\.\) must be called with a collection of "
102
+ r"some kind, 0\.0 was passed"
103
+ )
104
+ with pytest.raises(TypeError, match=msg):
105
+ index_cls(0.0)
106
+
107
+ def test_constructor_coerce(self, mixed_index, float_index):
108
+ self.check_coerce(mixed_index, Index([1.5, 2, 3, 4, 5]))
109
+ self.check_coerce(float_index, Index(np.arange(5) * 2.5))
110
+
111
+ result = Index(np.array(np.arange(5) * 2.5, dtype=object))
112
+ assert result.dtype == object # as of 2.0 to match Series
113
+ self.check_coerce(float_index, result.astype("float64"))
114
+
115
+ def test_constructor_explicit(self, mixed_index, float_index):
116
+ # these don't auto convert
117
+ self.check_coerce(
118
+ float_index, Index((np.arange(5) * 2.5), dtype=object), is_float_index=False
119
+ )
120
+ self.check_coerce(
121
+ mixed_index, Index([1.5, 2, 3, 4, 5], dtype=object), is_float_index=False
122
+ )
123
+
124
+ def test_type_coercion_fail(self, any_int_numpy_dtype):
125
+ # see gh-15832
126
+ msg = "Trying to coerce float values to integers"
127
+ with pytest.raises(ValueError, match=msg):
128
+ Index([1, 2, 3.5], dtype=any_int_numpy_dtype)
129
+
130
+ def test_equals_numeric(self):
131
+ index_cls = Index
132
+
133
+ idx = index_cls([1.0, 2.0])
134
+ assert idx.equals(idx)
135
+ assert idx.identical(idx)
136
+
137
+ idx2 = index_cls([1.0, 2.0])
138
+ assert idx.equals(idx2)
139
+
140
+ idx = index_cls([1.0, np.nan])
141
+ assert idx.equals(idx)
142
+ assert idx.identical(idx)
143
+
144
+ idx2 = index_cls([1.0, np.nan])
145
+ assert idx.equals(idx2)
146
+
147
+ @pytest.mark.parametrize(
148
+ "other",
149
+ (
150
+ Index([1, 2], dtype=np.int64),
151
+ Index([1.0, 2.0], dtype=object),
152
+ Index([1, 2], dtype=object),
153
+ ),
154
+ )
155
+ def test_equals_numeric_other_index_type(self, other):
156
+ idx = Index([1.0, 2.0])
157
+ assert idx.equals(other)
158
+ assert other.equals(idx)
159
+
160
+ @pytest.mark.parametrize(
161
+ "vals",
162
+ [
163
+ pd.date_range("2016-01-01", periods=3),
164
+ pd.timedelta_range("1 Day", periods=3),
165
+ ],
166
+ )
167
+ def test_lookups_datetimelike_values(self, vals, dtype):
168
+ # If we have datetime64 or timedelta64 values, make sure they are
169
+ # wrapped correctly GH#31163
170
+ ser = Series(vals, index=range(3, 6))
171
+ ser.index = ser.index.astype(dtype)
172
+
173
+ expected = vals[1]
174
+
175
+ result = ser[4.0]
176
+ assert isinstance(result, type(expected)) and result == expected
177
+ result = ser[4]
178
+ assert isinstance(result, type(expected)) and result == expected
179
+
180
+ result = ser.loc[4.0]
181
+ assert isinstance(result, type(expected)) and result == expected
182
+ result = ser.loc[4]
183
+ assert isinstance(result, type(expected)) and result == expected
184
+
185
+ result = ser.at[4.0]
186
+ assert isinstance(result, type(expected)) and result == expected
187
+ # GH#31329 .at[4] should cast to 4.0, matching .loc behavior
188
+ result = ser.at[4]
189
+ assert isinstance(result, type(expected)) and result == expected
190
+
191
+ result = ser.iloc[1]
192
+ assert isinstance(result, type(expected)) and result == expected
193
+
194
+ result = ser.iat[1]
195
+ assert isinstance(result, type(expected)) and result == expected
196
+
197
+ def test_doesnt_contain_all_the_things(self):
198
+ idx = Index([np.nan])
199
+ assert not idx.isin([0]).item()
200
+ assert not idx.isin([1]).item()
201
+ assert idx.isin([np.nan]).item()
202
+
203
+ def test_nan_multiple_containment(self):
204
+ index_cls = Index
205
+
206
+ idx = index_cls([1.0, np.nan])
207
+ tm.assert_numpy_array_equal(idx.isin([1.0]), np.array([True, False]))
208
+ tm.assert_numpy_array_equal(idx.isin([2.0, np.pi]), np.array([False, False]))
209
+ tm.assert_numpy_array_equal(idx.isin([np.nan]), np.array([False, True]))
210
+ tm.assert_numpy_array_equal(idx.isin([1.0, np.nan]), np.array([True, True]))
211
+ idx = index_cls([1.0, 2.0])
212
+ tm.assert_numpy_array_equal(idx.isin([np.nan]), np.array([False, False]))
213
+
214
+ def test_fillna_float64(self):
215
+ index_cls = Index
216
+ # GH 11343
217
+ idx = Index([1.0, np.nan, 3.0], dtype=float, name="x")
218
+ # can't downcast
219
+ exp = Index([1.0, 0.1, 3.0], name="x")
220
+ tm.assert_index_equal(idx.fillna(0.1), exp, exact=True)
221
+
222
+ # downcast
223
+ exp = index_cls([1.0, 2.0, 3.0], name="x")
224
+ tm.assert_index_equal(idx.fillna(2), exp)
225
+
226
+ # object
227
+ exp = Index([1.0, "obj", 3.0], name="x")
228
+ tm.assert_index_equal(idx.fillna("obj"), exp, exact=True)
229
+
230
+ def test_logical_compat(self, simple_index):
231
+ idx = simple_index
232
+ assert idx.all() == idx.values.all()
233
+ assert idx.any() == idx.values.any()
234
+
235
+ assert idx.all() == idx.to_series().all()
236
+ assert idx.any() == idx.to_series().any()
237
+
238
+
239
+ class TestNumericInt:
240
+ @pytest.fixture(params=[np.int64, np.int32, np.int16, np.int8, np.uint64])
241
+ def dtype(self, request):
242
+ return request.param
243
+
244
+ @pytest.fixture
245
+ def simple_index(self, dtype):
246
+ return Index(range(0, 20, 2), dtype=dtype)
247
+
248
+ def test_is_monotonic(self):
249
+ index_cls = Index
250
+
251
+ index = index_cls([1, 2, 3, 4])
252
+ assert index.is_monotonic_increasing is True
253
+ assert index.is_monotonic_increasing is True
254
+ assert index._is_strictly_monotonic_increasing is True
255
+ assert index.is_monotonic_decreasing is False
256
+ assert index._is_strictly_monotonic_decreasing is False
257
+
258
+ index = index_cls([4, 3, 2, 1])
259
+ assert index.is_monotonic_increasing is False
260
+ assert index._is_strictly_monotonic_increasing is False
261
+ assert index._is_strictly_monotonic_decreasing is True
262
+
263
+ index = index_cls([1])
264
+ assert index.is_monotonic_increasing is True
265
+ assert index.is_monotonic_increasing is True
266
+ assert index.is_monotonic_decreasing is True
267
+ assert index._is_strictly_monotonic_increasing is True
268
+ assert index._is_strictly_monotonic_decreasing is True
269
+
270
+ def test_is_strictly_monotonic(self):
271
+ index_cls = Index
272
+
273
+ index = index_cls([1, 1, 2, 3])
274
+ assert index.is_monotonic_increasing is True
275
+ assert index._is_strictly_monotonic_increasing is False
276
+
277
+ index = index_cls([3, 2, 1, 1])
278
+ assert index.is_monotonic_decreasing is True
279
+ assert index._is_strictly_monotonic_decreasing is False
280
+
281
+ index = index_cls([1, 1])
282
+ assert index.is_monotonic_increasing
283
+ assert index.is_monotonic_decreasing
284
+ assert not index._is_strictly_monotonic_increasing
285
+ assert not index._is_strictly_monotonic_decreasing
286
+
287
+ def test_logical_compat(self, simple_index):
288
+ idx = simple_index
289
+ assert idx.all() == idx.values.all()
290
+ assert idx.any() == idx.values.any()
291
+
292
+ def test_identical(self, simple_index, dtype):
293
+ index = simple_index
294
+
295
+ idx = Index(index.copy())
296
+ assert idx.identical(index)
297
+
298
+ same_values_different_type = Index(idx, dtype=object)
299
+ assert not idx.identical(same_values_different_type)
300
+
301
+ idx = index.astype(dtype=object)
302
+ idx = idx.rename("foo")
303
+ same_values = Index(idx, dtype=object)
304
+ assert same_values.identical(idx)
305
+
306
+ assert not idx.identical(index)
307
+ assert Index(same_values, name="foo", dtype=object).identical(idx)
308
+
309
+ assert not index.astype(dtype=object).identical(index.astype(dtype=dtype))
310
+
311
+ def test_cant_or_shouldnt_cast(self, dtype):
312
+ msg = r"invalid literal for int\(\) with base 10: 'foo'"
313
+
314
+ # can't
315
+ data = ["foo", "bar", "baz"]
316
+ with pytest.raises(ValueError, match=msg):
317
+ Index(data, dtype=dtype)
318
+
319
+ def test_view_index(self, simple_index):
320
+ index = simple_index
321
+ msg = "Passing a type in .*Index.view is deprecated"
322
+ with tm.assert_produces_warning(FutureWarning, match=msg):
323
+ index.view(Index)
324
+
325
+ def test_prevent_casting(self, simple_index):
326
+ index = simple_index
327
+ result = index.astype("O")
328
+ assert result.dtype == np.object_
329
+
330
+
331
+ class TestIntNumericIndex:
332
+ @pytest.fixture(params=[np.int64, np.int32, np.int16, np.int8])
333
+ def dtype(self, request):
334
+ return request.param
335
+
336
+ def test_constructor_from_list_no_dtype(self):
337
+ index = Index([1, 2, 3])
338
+ assert index.dtype == np.int64
339
+
340
+ def test_constructor(self, dtype):
341
+ index_cls = Index
342
+
343
+ # scalar raise Exception
344
+ msg = (
345
+ rf"{index_cls.__name__}\(\.\.\.\) must be called with a collection of some "
346
+ "kind, 5 was passed"
347
+ )
348
+ with pytest.raises(TypeError, match=msg):
349
+ index_cls(5)
350
+
351
+ # copy
352
+ # pass list, coerce fine
353
+ index = index_cls([-5, 0, 1, 2], dtype=dtype)
354
+ arr = index.values.copy()
355
+ new_index = index_cls(arr, copy=True)
356
+ tm.assert_index_equal(new_index, index, exact=True)
357
+ val = int(arr[0]) + 3000
358
+
359
+ # this should not change index
360
+ if dtype != np.int8:
361
+ # NEP 50 won't allow assignment that would overflow
362
+ arr[0] = val
363
+ assert new_index[0] != val
364
+
365
+ if dtype == np.int64:
366
+ # pass list, coerce fine
367
+ index = index_cls([-5, 0, 1, 2], dtype=dtype)
368
+ expected = Index([-5, 0, 1, 2], dtype=dtype)
369
+ tm.assert_index_equal(index, expected)
370
+
371
+ # from iterable
372
+ index = index_cls(iter([-5, 0, 1, 2]), dtype=dtype)
373
+ expected = index_cls([-5, 0, 1, 2], dtype=dtype)
374
+ tm.assert_index_equal(index, expected, exact=True)
375
+
376
+ # interpret list-like
377
+ expected = index_cls([5, 0], dtype=dtype)
378
+ for cls in [Index, index_cls]:
379
+ for idx in [
380
+ cls([5, 0], dtype=dtype),
381
+ cls(np.array([5, 0]), dtype=dtype),
382
+ cls(Series([5, 0]), dtype=dtype),
383
+ ]:
384
+ tm.assert_index_equal(idx, expected)
385
+
386
+ def test_constructor_corner(self, dtype):
387
+ index_cls = Index
388
+
389
+ arr = np.array([1, 2, 3, 4], dtype=object)
390
+
391
+ index = index_cls(arr, dtype=dtype)
392
+ assert index.values.dtype == index.dtype
393
+ if dtype == np.int64:
394
+ without_dtype = Index(arr)
395
+ # as of 2.0 we do not infer a dtype when we get an object-dtype
396
+ # ndarray of numbers, matching Series behavior
397
+ assert without_dtype.dtype == object
398
+
399
+ tm.assert_index_equal(index, without_dtype.astype(np.int64))
400
+
401
+ # preventing casting
402
+ arr = np.array([1, "2", 3, "4"], dtype=object)
403
+ msg = "Trying to coerce float values to integers"
404
+ with pytest.raises(ValueError, match=msg):
405
+ index_cls(arr, dtype=dtype)
406
+
407
+ def test_constructor_coercion_signed_to_unsigned(
408
+ self,
409
+ any_unsigned_int_numpy_dtype,
410
+ ):
411
+ # see gh-15832
412
+ msg = "|".join(
413
+ [
414
+ "Trying to coerce negative values to unsigned integers",
415
+ "The elements provided in the data cannot all be casted",
416
+ ]
417
+ )
418
+ with pytest.raises(OverflowError, match=msg):
419
+ Index([-1], dtype=any_unsigned_int_numpy_dtype)
420
+
421
+ def test_constructor_np_signed(self, any_signed_int_numpy_dtype):
422
+ # GH#47475
423
+ scalar = np.dtype(any_signed_int_numpy_dtype).type(1)
424
+ result = Index([scalar])
425
+ expected = Index([1], dtype=any_signed_int_numpy_dtype)
426
+ tm.assert_index_equal(result, expected, exact=True)
427
+
428
+ def test_constructor_np_unsigned(self, any_unsigned_int_numpy_dtype):
429
+ # GH#47475
430
+ scalar = np.dtype(any_unsigned_int_numpy_dtype).type(1)
431
+ result = Index([scalar])
432
+ expected = Index([1], dtype=any_unsigned_int_numpy_dtype)
433
+ tm.assert_index_equal(result, expected, exact=True)
434
+
435
+ def test_coerce_list(self):
436
+ # coerce things
437
+ arr = Index([1, 2, 3, 4])
438
+ assert isinstance(arr, Index)
439
+
440
+ # but not if explicit dtype passed
441
+ arr = Index([1, 2, 3, 4], dtype=object)
442
+ assert type(arr) is Index
443
+
444
+
445
+ class TestFloat16Index:
446
+ # float 16 indexes not supported
447
+ # GH 49535
448
+ def test_constructor(self):
449
+ index_cls = Index
450
+ dtype = np.float16
451
+
452
+ msg = "float16 indexes are not supported"
453
+
454
+ # explicit construction
455
+ with pytest.raises(NotImplementedError, match=msg):
456
+ index_cls([1, 2, 3, 4, 5], dtype=dtype)
457
+
458
+ with pytest.raises(NotImplementedError, match=msg):
459
+ index_cls(np.array([1, 2, 3, 4, 5]), dtype=dtype)
460
+
461
+ with pytest.raises(NotImplementedError, match=msg):
462
+ index_cls([1.0, 2, 3, 4, 5], dtype=dtype)
463
+
464
+ with pytest.raises(NotImplementedError, match=msg):
465
+ index_cls(np.array([1.0, 2, 3, 4, 5]), dtype=dtype)
466
+
467
+ with pytest.raises(NotImplementedError, match=msg):
468
+ index_cls([1.0, 2, 3, 4, 5], dtype=dtype)
469
+
470
+ with pytest.raises(NotImplementedError, match=msg):
471
+ index_cls(np.array([1.0, 2, 3, 4, 5]), dtype=dtype)
472
+
473
+ # nan handling
474
+ with pytest.raises(NotImplementedError, match=msg):
475
+ index_cls([np.nan, np.nan], dtype=dtype)
476
+
477
+ with pytest.raises(NotImplementedError, match=msg):
478
+ index_cls(np.array([np.nan]), dtype=dtype)
479
+
480
+
481
+ @pytest.mark.parametrize(
482
+ "box",
483
+ [list, lambda x: np.array(x, dtype=object), lambda x: Index(x, dtype=object)],
484
+ )
485
+ def test_uint_index_does_not_convert_to_float64(box):
486
+ # https://github.com/pandas-dev/pandas/issues/28279
487
+ # https://github.com/pandas-dev/pandas/issues/28023
488
+ series = Series(
489
+ [0, 1, 2, 3, 4, 5],
490
+ index=[
491
+ 7606741985629028552,
492
+ 17876870360202815256,
493
+ 17876870360202815256,
494
+ 13106359306506049338,
495
+ 8991270399732411471,
496
+ 8991270399732411472,
497
+ ],
498
+ )
499
+
500
+ result = series.loc[box([7606741985629028552, 17876870360202815256])]
501
+
502
+ expected = Index(
503
+ [7606741985629028552, 17876870360202815256, 17876870360202815256],
504
+ dtype="uint64",
505
+ )
506
+ tm.assert_index_equal(result.index, expected)
507
+
508
+ tm.assert_equal(result, series.iloc[:3])
509
+
510
+
511
+ def test_float64_index_equals():
512
+ # https://github.com/pandas-dev/pandas/issues/35217
513
+ float_index = Index([1.0, 2, 3])
514
+ string_index = Index(["1", "2", "3"])
515
+
516
+ result = float_index.equals(string_index)
517
+ assert result is False
518
+
519
+ result = string_index.equals(float_index)
520
+ assert result is False
521
+
522
+
523
+ def test_map_dtype_inference_unsigned_to_signed():
524
+ # GH#44609 cases where we don't retain dtype
525
+ idx = Index([1, 2, 3], dtype=np.uint64)
526
+ result = idx.map(lambda x: -x)
527
+ expected = Index([-1, -2, -3], dtype=np.int64)
528
+ tm.assert_index_equal(result, expected)
529
+
530
+
531
+ def test_map_dtype_inference_overflows():
532
+ # GH#44609 case where we have to upcast
533
+ idx = Index(np.array([1, 2, 3], dtype=np.int8))
534
+ result = idx.map(lambda x: x * 1000)
535
+ # TODO: we could plausibly try to infer down to int16 here
536
+ expected = Index([1000, 2000, 3000], dtype=np.int64)
537
+ tm.assert_index_equal(result, expected)
538
+
539
+
540
+ def test_view_to_datetimelike():
541
+ # GH#55710
542
+ idx = Index([1, 2, 3])
543
+ res = idx.view("m8[s]")
544
+ expected = pd.TimedeltaIndex(idx.values.view("m8[s]"))
545
+ tm.assert_index_equal(res, expected)
546
+
547
+ res2 = idx.view("m8[D]")
548
+ expected2 = idx.values.view("m8[D]")
549
+ tm.assert_numpy_array_equal(res2, expected2)
550
+
551
+ res3 = idx.view("M8[h]")
552
+ expected3 = idx.values.view("M8[h]")
553
+ tm.assert_numpy_array_equal(res3, expected3)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_setops.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import (
2
+ datetime,
3
+ timedelta,
4
+ )
5
+
6
+ import numpy as np
7
+ import pytest
8
+
9
+ import pandas._testing as tm
10
+ from pandas.core.indexes.api import (
11
+ Index,
12
+ RangeIndex,
13
+ )
14
+
15
+
16
+ @pytest.fixture
17
+ def index_large():
18
+ # large values used in TestUInt64Index where no compat needed with int64/float64
19
+ large = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25]
20
+ return Index(large, dtype=np.uint64)
21
+
22
+
23
+ class TestSetOps:
24
+ @pytest.mark.parametrize("dtype", ["f8", "u8", "i8"])
25
+ def test_union_non_numeric(self, dtype):
26
+ # corner case, non-numeric
27
+ index = Index(np.arange(5, dtype=dtype), dtype=dtype)
28
+ assert index.dtype == dtype
29
+
30
+ other = Index([datetime.now() + timedelta(i) for i in range(4)], dtype=object)
31
+ result = index.union(other)
32
+ expected = Index(np.concatenate((index, other)))
33
+ tm.assert_index_equal(result, expected)
34
+
35
+ result = other.union(index)
36
+ expected = Index(np.concatenate((other, index)))
37
+ tm.assert_index_equal(result, expected)
38
+
39
+ def test_intersection(self):
40
+ index = Index(range(5), dtype=np.int64)
41
+
42
+ other = Index([1, 2, 3, 4, 5])
43
+ result = index.intersection(other)
44
+ expected = Index(np.sort(np.intersect1d(index.values, other.values)))
45
+ tm.assert_index_equal(result, expected)
46
+
47
+ result = other.intersection(index)
48
+ expected = Index(
49
+ np.sort(np.asarray(np.intersect1d(index.values, other.values)))
50
+ )
51
+ tm.assert_index_equal(result, expected)
52
+
53
+ @pytest.mark.parametrize("dtype", ["int64", "uint64"])
54
+ def test_int_float_union_dtype(self, dtype):
55
+ # https://github.com/pandas-dev/pandas/issues/26778
56
+ # [u]int | float -> float
57
+ index = Index([0, 2, 3], dtype=dtype)
58
+ other = Index([0.5, 1.5], dtype=np.float64)
59
+ expected = Index([0.0, 0.5, 1.5, 2.0, 3.0], dtype=np.float64)
60
+ result = index.union(other)
61
+ tm.assert_index_equal(result, expected)
62
+
63
+ result = other.union(index)
64
+ tm.assert_index_equal(result, expected)
65
+
66
+ def test_range_float_union_dtype(self):
67
+ # https://github.com/pandas-dev/pandas/issues/26778
68
+ index = RangeIndex(start=0, stop=3)
69
+ other = Index([0.5, 1.5], dtype=np.float64)
70
+ result = index.union(other)
71
+ expected = Index([0.0, 0.5, 1, 1.5, 2.0], dtype=np.float64)
72
+ tm.assert_index_equal(result, expected)
73
+
74
+ result = other.union(index)
75
+ tm.assert_index_equal(result, expected)
76
+
77
+ def test_range_uint64_union_dtype(self):
78
+ # https://github.com/pandas-dev/pandas/issues/26778
79
+ index = RangeIndex(start=0, stop=3)
80
+ other = Index([0, 10], dtype=np.uint64)
81
+ result = index.union(other)
82
+ expected = Index([0, 1, 2, 10], dtype=object)
83
+ tm.assert_index_equal(result, expected)
84
+
85
+ result = other.union(index)
86
+ tm.assert_index_equal(result, expected)
87
+
88
+ def test_float64_index_difference(self):
89
+ # https://github.com/pandas-dev/pandas/issues/35217
90
+ float_index = Index([1.0, 2, 3])
91
+ string_index = Index(["1", "2", "3"])
92
+
93
+ result = float_index.difference(string_index)
94
+ tm.assert_index_equal(result, float_index)
95
+
96
+ result = string_index.difference(float_index)
97
+ tm.assert_index_equal(result, string_index)
98
+
99
+ def test_intersection_uint64_outside_int64_range(self, index_large):
100
+ other = Index([2**63, 2**63 + 5, 2**63 + 10, 2**63 + 15, 2**63 + 20])
101
+ result = index_large.intersection(other)
102
+ expected = Index(np.sort(np.intersect1d(index_large.values, other.values)))
103
+ tm.assert_index_equal(result, expected)
104
+
105
+ result = other.intersection(index_large)
106
+ expected = Index(
107
+ np.sort(np.asarray(np.intersect1d(index_large.values, other.values)))
108
+ )
109
+ tm.assert_index_equal(result, expected)
110
+
111
+ @pytest.mark.parametrize(
112
+ "index2,keeps_name",
113
+ [
114
+ (Index([4, 7, 6, 5, 3], name="index"), True),
115
+ (Index([4, 7, 6, 5, 3], name="other"), False),
116
+ ],
117
+ )
118
+ def test_intersection_monotonic(self, index2, keeps_name, sort):
119
+ index1 = Index([5, 3, 2, 4, 1], name="index")
120
+ expected = Index([5, 3, 4])
121
+
122
+ if keeps_name:
123
+ expected.name = "index"
124
+
125
+ result = index1.intersection(index2, sort=sort)
126
+ if sort is None:
127
+ expected = expected.sort_values()
128
+ tm.assert_index_equal(result, expected)
129
+
130
+ def test_symmetric_difference(self, sort):
131
+ # smoke
132
+ index1 = Index([5, 2, 3, 4], name="index1")
133
+ index2 = Index([2, 3, 4, 1])
134
+ result = index1.symmetric_difference(index2, sort=sort)
135
+ expected = Index([5, 1])
136
+ if sort is not None:
137
+ tm.assert_index_equal(result, expected)
138
+ else:
139
+ tm.assert_index_equal(result, expected.sort_values())
140
+ assert result.name is None
141
+ if sort is None:
142
+ expected = expected.sort_values()
143
+ tm.assert_index_equal(result, expected)
144
+
145
+
146
+ class TestSetOpsSort:
147
+ @pytest.mark.parametrize("slice_", [slice(None), slice(0)])
148
+ def test_union_sort_other_special(self, slice_):
149
+ # https://github.com/pandas-dev/pandas/issues/24959
150
+
151
+ idx = Index([1, 0, 2])
152
+ # default, sort=None
153
+ other = idx[slice_]
154
+ tm.assert_index_equal(idx.union(other), idx)
155
+ tm.assert_index_equal(other.union(idx), idx)
156
+
157
+ # sort=False
158
+ tm.assert_index_equal(idx.union(other, sort=False), idx)
159
+
160
+ @pytest.mark.parametrize("slice_", [slice(None), slice(0)])
161
+ def test_union_sort_special_true(self, slice_):
162
+ idx = Index([1, 0, 2])
163
+ # default, sort=None
164
+ other = idx[slice_]
165
+
166
+ result = idx.union(other, sort=True)
167
+ expected = Index([0, 1, 2])
168
+ tm.assert_index_equal(result, expected)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_any_index.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests that can be parametrized over _any_ Index object.
3
+ """
4
+ import re
5
+
6
+ import numpy as np
7
+ import pytest
8
+
9
+ from pandas.errors import InvalidIndexError
10
+
11
+ import pandas._testing as tm
12
+
13
+
14
+ def test_boolean_context_compat(index):
15
+ # GH#7897
16
+ with pytest.raises(ValueError, match="The truth value of a"):
17
+ if index:
18
+ pass
19
+
20
+ with pytest.raises(ValueError, match="The truth value of a"):
21
+ bool(index)
22
+
23
+
24
+ def test_sort(index):
25
+ msg = "cannot sort an Index object in-place, use sort_values instead"
26
+ with pytest.raises(TypeError, match=msg):
27
+ index.sort()
28
+
29
+
30
+ def test_hash_error(index):
31
+ with pytest.raises(TypeError, match=f"unhashable type: '{type(index).__name__}'"):
32
+ hash(index)
33
+
34
+
35
+ def test_mutability(index):
36
+ if not len(index):
37
+ pytest.skip("Test doesn't make sense for empty index")
38
+ msg = "Index does not support mutable operations"
39
+ with pytest.raises(TypeError, match=msg):
40
+ index[0] = index[0]
41
+
42
+
43
+ @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
44
+ def test_map_identity_mapping(index, request):
45
+ # GH#12766
46
+
47
+ result = index.map(lambda x: x)
48
+ if index.dtype == object and result.dtype == bool:
49
+ assert (index == result).all()
50
+ # TODO: could work that into the 'exact="equiv"'?
51
+ return # FIXME: doesn't belong in this file anymore!
52
+ tm.assert_index_equal(result, index, exact="equiv")
53
+
54
+
55
+ def test_wrong_number_names(index):
56
+ names = index.nlevels * ["apple", "banana", "carrot"]
57
+ with pytest.raises(ValueError, match="^Length"):
58
+ index.names = names
59
+
60
+
61
+ def test_view_preserves_name(index):
62
+ assert index.view().name == index.name
63
+
64
+
65
+ def test_ravel(index):
66
+ # GH#19956 ravel returning ndarray is deprecated, in 2.0 returns a view on self
67
+ res = index.ravel()
68
+ tm.assert_index_equal(res, index)
69
+
70
+
71
+ class TestConversion:
72
+ def test_to_series(self, index):
73
+ # assert that we are creating a copy of the index
74
+
75
+ ser = index.to_series()
76
+ assert ser.values is not index.values
77
+ assert ser.index is not index
78
+ assert ser.name == index.name
79
+
80
+ def test_to_series_with_arguments(self, index):
81
+ # GH#18699
82
+
83
+ # index kwarg
84
+ ser = index.to_series(index=index)
85
+
86
+ assert ser.values is not index.values
87
+ assert ser.index is index
88
+ assert ser.name == index.name
89
+
90
+ # name kwarg
91
+ ser = index.to_series(name="__test")
92
+
93
+ assert ser.values is not index.values
94
+ assert ser.index is not index
95
+ assert ser.name != index.name
96
+
97
+ def test_tolist_matches_list(self, index):
98
+ assert index.tolist() == list(index)
99
+
100
+
101
+ class TestRoundTrips:
102
+ def test_pickle_roundtrip(self, index):
103
+ result = tm.round_trip_pickle(index)
104
+ tm.assert_index_equal(result, index, exact=True)
105
+ if result.nlevels > 1:
106
+ # GH#8367 round-trip with timezone
107
+ assert index.equal_levels(result)
108
+
109
+ def test_pickle_preserves_name(self, index):
110
+ original_name, index.name = index.name, "foo"
111
+ unpickled = tm.round_trip_pickle(index)
112
+ assert index.equals(unpickled)
113
+ index.name = original_name
114
+
115
+
116
+ class TestIndexing:
117
+ def test_get_loc_listlike_raises_invalid_index_error(self, index):
118
+ # and never TypeError
119
+ key = np.array([0, 1], dtype=np.intp)
120
+
121
+ with pytest.raises(InvalidIndexError, match=r"\[0 1\]"):
122
+ index.get_loc(key)
123
+
124
+ with pytest.raises(InvalidIndexError, match=r"\[False True\]"):
125
+ index.get_loc(key.astype(bool))
126
+
127
+ def test_getitem_ellipsis(self, index):
128
+ # GH#21282
129
+ result = index[...]
130
+ assert result.equals(index)
131
+ assert result is not index
132
+
133
+ def test_slice_keeps_name(self, index):
134
+ assert index.name == index[1:].name
135
+
136
+ @pytest.mark.parametrize("item", [101, "no_int", 2.5])
137
+ def test_getitem_error(self, index, item):
138
+ msg = "|".join(
139
+ [
140
+ r"index 101 is out of bounds for axis 0 with size [\d]+",
141
+ re.escape(
142
+ "only integers, slices (`:`), ellipsis (`...`), "
143
+ "numpy.newaxis (`None`) and integer or boolean arrays "
144
+ "are valid indices"
145
+ ),
146
+ "index out of bounds", # string[pyarrow]
147
+ ]
148
+ )
149
+ with pytest.raises(IndexError, match=msg):
150
+ index[item]
151
+
152
+
153
+ class TestRendering:
154
+ def test_str(self, index):
155
+ # test the string repr
156
+ index.name = "foo"
157
+ assert "'foo'" in str(index)
158
+ assert type(index).__name__ in str(index)
159
+
160
+
161
+ class TestReductions:
162
+ def test_argmax_axis_invalid(self, index):
163
+ # GH#23081
164
+ msg = r"`axis` must be fewer than the number of dimensions \(1\)"
165
+ with pytest.raises(ValueError, match=msg):
166
+ index.argmax(axis=1)
167
+ with pytest.raises(ValueError, match=msg):
168
+ index.argmin(axis=2)
169
+ with pytest.raises(ValueError, match=msg):
170
+ index.min(axis=-2)
171
+ with pytest.raises(ValueError, match=msg):
172
+ index.max(axis=-3)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_base.py ADDED
@@ -0,0 +1,1737 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import defaultdict
2
+ from datetime import datetime
3
+ from functools import partial
4
+ import math
5
+ import operator
6
+ import re
7
+
8
+ import numpy as np
9
+ import pytest
10
+
11
+ from pandas.compat import IS64
12
+ from pandas.errors import InvalidIndexError
13
+ import pandas.util._test_decorators as td
14
+
15
+ from pandas.core.dtypes.common import (
16
+ is_any_real_numeric_dtype,
17
+ is_numeric_dtype,
18
+ is_object_dtype,
19
+ )
20
+
21
+ import pandas as pd
22
+ from pandas import (
23
+ CategoricalIndex,
24
+ DataFrame,
25
+ DatetimeIndex,
26
+ IntervalIndex,
27
+ PeriodIndex,
28
+ RangeIndex,
29
+ Series,
30
+ TimedeltaIndex,
31
+ date_range,
32
+ period_range,
33
+ timedelta_range,
34
+ )
35
+ import pandas._testing as tm
36
+ from pandas.core.indexes.api import (
37
+ Index,
38
+ MultiIndex,
39
+ _get_combined_index,
40
+ ensure_index,
41
+ ensure_index_from_sequences,
42
+ )
43
+
44
+
45
+ class TestIndex:
46
+ @pytest.fixture
47
+ def simple_index(self) -> Index:
48
+ return Index(list("abcde"))
49
+
50
+ def test_can_hold_identifiers(self, simple_index):
51
+ index = simple_index
52
+ key = index[0]
53
+ assert index._can_hold_identifiers_and_holds_name(key) is True
54
+
55
+ @pytest.mark.parametrize("index", ["datetime"], indirect=True)
56
+ def test_new_axis(self, index):
57
+ # TODO: a bunch of scattered tests check this deprecation is enforced.
58
+ # de-duplicate/centralize them.
59
+ with pytest.raises(ValueError, match="Multi-dimensional indexing"):
60
+ # GH#30588 multi-dimensional indexing deprecated
61
+ index[None, :]
62
+
63
+ def test_constructor_regular(self, index):
64
+ tm.assert_contains_all(index, index)
65
+
66
+ @pytest.mark.parametrize("index", ["string"], indirect=True)
67
+ def test_constructor_casting(self, index):
68
+ # casting
69
+ arr = np.array(index)
70
+ new_index = Index(arr)
71
+ tm.assert_contains_all(arr, new_index)
72
+ tm.assert_index_equal(index, new_index)
73
+
74
+ def test_constructor_copy(self, using_infer_string):
75
+ index = Index(list("abc"), name="name")
76
+ arr = np.array(index)
77
+ new_index = Index(arr, copy=True, name="name")
78
+ assert isinstance(new_index, Index)
79
+ assert new_index.name == "name"
80
+ if using_infer_string:
81
+ tm.assert_extension_array_equal(
82
+ new_index.values, pd.array(arr, dtype="string[pyarrow_numpy]")
83
+ )
84
+ else:
85
+ tm.assert_numpy_array_equal(arr, new_index.values)
86
+ arr[0] = "SOMEBIGLONGSTRING"
87
+ assert new_index[0] != "SOMEBIGLONGSTRING"
88
+
89
+ @pytest.mark.parametrize("cast_as_obj", [True, False])
90
+ @pytest.mark.parametrize(
91
+ "index",
92
+ [
93
+ date_range(
94
+ "2015-01-01 10:00",
95
+ freq="D",
96
+ periods=3,
97
+ tz="US/Eastern",
98
+ name="Green Eggs & Ham",
99
+ ), # DTI with tz
100
+ date_range("2015-01-01 10:00", freq="D", periods=3), # DTI no tz
101
+ timedelta_range("1 days", freq="D", periods=3), # td
102
+ period_range("2015-01-01", freq="D", periods=3), # period
103
+ ],
104
+ )
105
+ def test_constructor_from_index_dtlike(self, cast_as_obj, index):
106
+ if cast_as_obj:
107
+ with tm.assert_produces_warning(FutureWarning, match="Dtype inference"):
108
+ result = Index(index.astype(object))
109
+ else:
110
+ result = Index(index)
111
+
112
+ tm.assert_index_equal(result, index)
113
+
114
+ if isinstance(index, DatetimeIndex):
115
+ assert result.tz == index.tz
116
+ if cast_as_obj:
117
+ # GH#23524 check that Index(dti, dtype=object) does not
118
+ # incorrectly raise ValueError, and that nanoseconds are not
119
+ # dropped
120
+ index += pd.Timedelta(nanoseconds=50)
121
+ result = Index(index, dtype=object)
122
+ assert result.dtype == np.object_
123
+ assert list(result) == list(index)
124
+
125
+ @pytest.mark.parametrize(
126
+ "index,has_tz",
127
+ [
128
+ (
129
+ date_range("2015-01-01 10:00", freq="D", periods=3, tz="US/Eastern"),
130
+ True,
131
+ ), # datetimetz
132
+ (timedelta_range("1 days", freq="D", periods=3), False), # td
133
+ (period_range("2015-01-01", freq="D", periods=3), False), # period
134
+ ],
135
+ )
136
+ def test_constructor_from_series_dtlike(self, index, has_tz):
137
+ result = Index(Series(index))
138
+ tm.assert_index_equal(result, index)
139
+
140
+ if has_tz:
141
+ assert result.tz == index.tz
142
+
143
+ def test_constructor_from_series_freq(self):
144
+ # GH 6273
145
+ # create from a series, passing a freq
146
+ dts = ["1-1-1990", "2-1-1990", "3-1-1990", "4-1-1990", "5-1-1990"]
147
+ expected = DatetimeIndex(dts, freq="MS")
148
+
149
+ s = Series(pd.to_datetime(dts))
150
+ result = DatetimeIndex(s, freq="MS")
151
+
152
+ tm.assert_index_equal(result, expected)
153
+
154
+ def test_constructor_from_frame_series_freq(self, using_infer_string):
155
+ # GH 6273
156
+ # create from a series, passing a freq
157
+ dts = ["1-1-1990", "2-1-1990", "3-1-1990", "4-1-1990", "5-1-1990"]
158
+ expected = DatetimeIndex(dts, freq="MS")
159
+
160
+ df = DataFrame(np.random.default_rng(2).random((5, 3)))
161
+ df["date"] = dts
162
+ result = DatetimeIndex(df["date"], freq="MS")
163
+ dtype = object if not using_infer_string else "string"
164
+ assert df["date"].dtype == dtype
165
+ expected.name = "date"
166
+ tm.assert_index_equal(result, expected)
167
+
168
+ expected = Series(dts, name="date")
169
+ tm.assert_series_equal(df["date"], expected)
170
+
171
+ # GH 6274
172
+ # infer freq of same
173
+ if not using_infer_string:
174
+ # Doesn't work with arrow strings
175
+ freq = pd.infer_freq(df["date"])
176
+ assert freq == "MS"
177
+
178
+ def test_constructor_int_dtype_nan(self):
179
+ # see gh-15187
180
+ data = [np.nan]
181
+ expected = Index(data, dtype=np.float64)
182
+ result = Index(data, dtype="float")
183
+ tm.assert_index_equal(result, expected)
184
+
185
+ @pytest.mark.parametrize(
186
+ "klass,dtype,na_val",
187
+ [
188
+ (Index, np.float64, np.nan),
189
+ (DatetimeIndex, "datetime64[ns]", pd.NaT),
190
+ ],
191
+ )
192
+ def test_index_ctor_infer_nan_nat(self, klass, dtype, na_val):
193
+ # GH 13467
194
+ na_list = [na_val, na_val]
195
+ expected = klass(na_list)
196
+ assert expected.dtype == dtype
197
+
198
+ result = Index(na_list)
199
+ tm.assert_index_equal(result, expected)
200
+
201
+ result = Index(np.array(na_list))
202
+ tm.assert_index_equal(result, expected)
203
+
204
+ @pytest.mark.parametrize(
205
+ "vals,dtype",
206
+ [
207
+ ([1, 2, 3, 4, 5], "int"),
208
+ ([1.1, np.nan, 2.2, 3.0], "float"),
209
+ (["A", "B", "C", np.nan], "obj"),
210
+ ],
211
+ )
212
+ def test_constructor_simple_new(self, vals, dtype):
213
+ index = Index(vals, name=dtype)
214
+ result = index._simple_new(index.values, dtype)
215
+ tm.assert_index_equal(result, index)
216
+
217
+ @pytest.mark.parametrize("attr", ["values", "asi8"])
218
+ @pytest.mark.parametrize("klass", [Index, DatetimeIndex])
219
+ def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, klass):
220
+ # Test constructing with a datetimetz dtype
221
+ # .values produces numpy datetimes, so these are considered naive
222
+ # .asi8 produces integers, so these are considered epoch timestamps
223
+ # ^the above will be true in a later version. Right now we `.view`
224
+ # the i8 values as NS_DTYPE, effectively treating them as wall times.
225
+ index = date_range("2011-01-01", periods=5)
226
+ arg = getattr(index, attr)
227
+ index = index.tz_localize(tz_naive_fixture)
228
+ dtype = index.dtype
229
+
230
+ # As of 2.0 astype raises on dt64.astype(dt64tz)
231
+ err = tz_naive_fixture is not None
232
+ msg = "Cannot use .astype to convert from timezone-naive dtype to"
233
+
234
+ if attr == "asi8":
235
+ result = DatetimeIndex(arg).tz_localize(tz_naive_fixture)
236
+ tm.assert_index_equal(result, index)
237
+ elif klass is Index:
238
+ with pytest.raises(TypeError, match="unexpected keyword"):
239
+ klass(arg, tz=tz_naive_fixture)
240
+ else:
241
+ result = klass(arg, tz=tz_naive_fixture)
242
+ tm.assert_index_equal(result, index)
243
+
244
+ if attr == "asi8":
245
+ if err:
246
+ with pytest.raises(TypeError, match=msg):
247
+ DatetimeIndex(arg).astype(dtype)
248
+ else:
249
+ result = DatetimeIndex(arg).astype(dtype)
250
+ tm.assert_index_equal(result, index)
251
+ else:
252
+ result = klass(arg, dtype=dtype)
253
+ tm.assert_index_equal(result, index)
254
+
255
+ if attr == "asi8":
256
+ result = DatetimeIndex(list(arg)).tz_localize(tz_naive_fixture)
257
+ tm.assert_index_equal(result, index)
258
+ elif klass is Index:
259
+ with pytest.raises(TypeError, match="unexpected keyword"):
260
+ klass(arg, tz=tz_naive_fixture)
261
+ else:
262
+ result = klass(list(arg), tz=tz_naive_fixture)
263
+ tm.assert_index_equal(result, index)
264
+
265
+ if attr == "asi8":
266
+ if err:
267
+ with pytest.raises(TypeError, match=msg):
268
+ DatetimeIndex(list(arg)).astype(dtype)
269
+ else:
270
+ result = DatetimeIndex(list(arg)).astype(dtype)
271
+ tm.assert_index_equal(result, index)
272
+ else:
273
+ result = klass(list(arg), dtype=dtype)
274
+ tm.assert_index_equal(result, index)
275
+
276
+ @pytest.mark.parametrize("attr", ["values", "asi8"])
277
+ @pytest.mark.parametrize("klass", [Index, TimedeltaIndex])
278
+ def test_constructor_dtypes_timedelta(self, attr, klass):
279
+ index = timedelta_range("1 days", periods=5)
280
+ index = index._with_freq(None) # won't be preserved by constructors
281
+ dtype = index.dtype
282
+
283
+ values = getattr(index, attr)
284
+
285
+ result = klass(values, dtype=dtype)
286
+ tm.assert_index_equal(result, index)
287
+
288
+ result = klass(list(values), dtype=dtype)
289
+ tm.assert_index_equal(result, index)
290
+
291
+ @pytest.mark.parametrize("value", [[], iter([]), (_ for _ in [])])
292
+ @pytest.mark.parametrize(
293
+ "klass",
294
+ [
295
+ Index,
296
+ CategoricalIndex,
297
+ DatetimeIndex,
298
+ TimedeltaIndex,
299
+ ],
300
+ )
301
+ def test_constructor_empty(self, value, klass):
302
+ empty = klass(value)
303
+ assert isinstance(empty, klass)
304
+ assert not len(empty)
305
+
306
+ @pytest.mark.parametrize(
307
+ "empty,klass",
308
+ [
309
+ (PeriodIndex([], freq="D"), PeriodIndex),
310
+ (PeriodIndex(iter([]), freq="D"), PeriodIndex),
311
+ (PeriodIndex((_ for _ in []), freq="D"), PeriodIndex),
312
+ (RangeIndex(step=1), RangeIndex),
313
+ (MultiIndex(levels=[[1, 2], ["blue", "red"]], codes=[[], []]), MultiIndex),
314
+ ],
315
+ )
316
+ def test_constructor_empty_special(self, empty, klass):
317
+ assert isinstance(empty, klass)
318
+ assert not len(empty)
319
+
320
+ @pytest.mark.parametrize(
321
+ "index",
322
+ [
323
+ "datetime",
324
+ "float64",
325
+ "float32",
326
+ "int64",
327
+ "int32",
328
+ "period",
329
+ "range",
330
+ "repeats",
331
+ "timedelta",
332
+ "tuples",
333
+ "uint64",
334
+ "uint32",
335
+ ],
336
+ indirect=True,
337
+ )
338
+ def test_view_with_args(self, index):
339
+ index.view("i8")
340
+
341
+ @pytest.mark.parametrize(
342
+ "index",
343
+ [
344
+ "string",
345
+ pytest.param("categorical", marks=pytest.mark.xfail(reason="gh-25464")),
346
+ "bool-object",
347
+ "bool-dtype",
348
+ "empty",
349
+ ],
350
+ indirect=True,
351
+ )
352
+ def test_view_with_args_object_array_raises(self, index):
353
+ if index.dtype == bool:
354
+ msg = "When changing to a larger dtype"
355
+ with pytest.raises(ValueError, match=msg):
356
+ index.view("i8")
357
+ elif index.dtype == "string":
358
+ with pytest.raises(NotImplementedError, match="i8"):
359
+ index.view("i8")
360
+ else:
361
+ msg = (
362
+ "Cannot change data-type for array of references|"
363
+ "Cannot change data-type for object array|"
364
+ )
365
+ with pytest.raises(TypeError, match=msg):
366
+ index.view("i8")
367
+
368
+ @pytest.mark.parametrize(
369
+ "index",
370
+ ["int64", "int32", "range"],
371
+ indirect=True,
372
+ )
373
+ def test_astype(self, index):
374
+ casted = index.astype("i8")
375
+
376
+ # it works!
377
+ casted.get_loc(5)
378
+
379
+ # pass on name
380
+ index.name = "foobar"
381
+ casted = index.astype("i8")
382
+ assert casted.name == "foobar"
383
+
384
+ def test_equals_object(self):
385
+ # same
386
+ assert Index(["a", "b", "c"]).equals(Index(["a", "b", "c"]))
387
+
388
+ @pytest.mark.parametrize(
389
+ "comp", [Index(["a", "b"]), Index(["a", "b", "d"]), ["a", "b", "c"]]
390
+ )
391
+ def test_not_equals_object(self, comp):
392
+ assert not Index(["a", "b", "c"]).equals(comp)
393
+
394
+ def test_identical(self):
395
+ # index
396
+ i1 = Index(["a", "b", "c"])
397
+ i2 = Index(["a", "b", "c"])
398
+
399
+ assert i1.identical(i2)
400
+
401
+ i1 = i1.rename("foo")
402
+ assert i1.equals(i2)
403
+ assert not i1.identical(i2)
404
+
405
+ i2 = i2.rename("foo")
406
+ assert i1.identical(i2)
407
+
408
+ i3 = Index([("a", "a"), ("a", "b"), ("b", "a")])
409
+ i4 = Index([("a", "a"), ("a", "b"), ("b", "a")], tupleize_cols=False)
410
+ assert not i3.identical(i4)
411
+
412
+ def test_is_(self):
413
+ ind = Index(range(10))
414
+ assert ind.is_(ind)
415
+ assert ind.is_(ind.view().view().view().view())
416
+ assert not ind.is_(Index(range(10)))
417
+ assert not ind.is_(ind.copy())
418
+ assert not ind.is_(ind.copy(deep=False))
419
+ assert not ind.is_(ind[:])
420
+ assert not ind.is_(np.array(range(10)))
421
+
422
+ # quasi-implementation dependent
423
+ assert ind.is_(ind.view())
424
+ ind2 = ind.view()
425
+ ind2.name = "bob"
426
+ assert ind.is_(ind2)
427
+ assert ind2.is_(ind)
428
+ # doesn't matter if Indices are *actually* views of underlying data,
429
+ assert not ind.is_(Index(ind.values))
430
+ arr = np.array(range(1, 11))
431
+ ind1 = Index(arr, copy=False)
432
+ ind2 = Index(arr, copy=False)
433
+ assert not ind1.is_(ind2)
434
+
435
+ def test_asof_numeric_vs_bool_raises(self):
436
+ left = Index([1, 2, 3])
437
+ right = Index([True, False], dtype=object)
438
+
439
+ msg = "Cannot compare dtypes int64 and bool"
440
+ with pytest.raises(TypeError, match=msg):
441
+ left.asof(right[0])
442
+ # TODO: should right.asof(left[0]) also raise?
443
+
444
+ with pytest.raises(InvalidIndexError, match=re.escape(str(right))):
445
+ left.asof(right)
446
+
447
+ with pytest.raises(InvalidIndexError, match=re.escape(str(left))):
448
+ right.asof(left)
449
+
450
+ @pytest.mark.parametrize("index", ["string"], indirect=True)
451
+ def test_booleanindex(self, index):
452
+ bool_index = np.ones(len(index), dtype=bool)
453
+ bool_index[5:30:2] = False
454
+
455
+ sub_index = index[bool_index]
456
+
457
+ for i, val in enumerate(sub_index):
458
+ assert sub_index.get_loc(val) == i
459
+
460
+ sub_index = index[list(bool_index)]
461
+ for i, val in enumerate(sub_index):
462
+ assert sub_index.get_loc(val) == i
463
+
464
+ def test_fancy(self, simple_index):
465
+ index = simple_index
466
+ sl = index[[1, 2, 3]]
467
+ for i in sl:
468
+ assert i == sl[sl.get_loc(i)]
469
+
470
+ @pytest.mark.parametrize(
471
+ "index",
472
+ ["string", "int64", "int32", "uint64", "uint32", "float64", "float32"],
473
+ indirect=True,
474
+ )
475
+ @pytest.mark.parametrize("dtype", [int, np.bool_])
476
+ def test_empty_fancy(self, index, dtype, request, using_infer_string):
477
+ if dtype is np.bool_ and using_infer_string and index.dtype == "string":
478
+ request.applymarker(pytest.mark.xfail(reason="numpy behavior is buggy"))
479
+ empty_arr = np.array([], dtype=dtype)
480
+ empty_index = type(index)([], dtype=index.dtype)
481
+
482
+ assert index[[]].identical(empty_index)
483
+ if dtype == np.bool_:
484
+ with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
485
+ assert index[empty_arr].identical(empty_index)
486
+ else:
487
+ assert index[empty_arr].identical(empty_index)
488
+
489
+ @pytest.mark.parametrize(
490
+ "index",
491
+ ["string", "int64", "int32", "uint64", "uint32", "float64", "float32"],
492
+ indirect=True,
493
+ )
494
+ def test_empty_fancy_raises(self, index):
495
+ # DatetimeIndex is excluded, because it overrides getitem and should
496
+ # be tested separately.
497
+ empty_farr = np.array([], dtype=np.float64)
498
+ empty_index = type(index)([], dtype=index.dtype)
499
+
500
+ assert index[[]].identical(empty_index)
501
+ # np.ndarray only accepts ndarray of int & bool dtypes, so should Index
502
+ msg = r"arrays used as indices must be of integer"
503
+ with pytest.raises(IndexError, match=msg):
504
+ index[empty_farr]
505
+
506
+ def test_union_dt_as_obj(self, simple_index):
507
+ # TODO: Replace with fixturesult
508
+ index = simple_index
509
+ date_index = date_range("2019-01-01", periods=10)
510
+ first_cat = index.union(date_index)
511
+ second_cat = index.union(index)
512
+
513
+ appended = Index(np.append(index, date_index.astype("O")))
514
+
515
+ tm.assert_index_equal(first_cat, appended)
516
+ tm.assert_index_equal(second_cat, index)
517
+ tm.assert_contains_all(index, first_cat)
518
+ tm.assert_contains_all(index, second_cat)
519
+ tm.assert_contains_all(date_index, first_cat)
520
+
521
+ def test_map_with_tuples(self):
522
+ # GH 12766
523
+
524
+ # Test that returning a single tuple from an Index
525
+ # returns an Index.
526
+ index = Index(np.arange(3), dtype=np.int64)
527
+ result = index.map(lambda x: (x,))
528
+ expected = Index([(i,) for i in index])
529
+ tm.assert_index_equal(result, expected)
530
+
531
+ # Test that returning a tuple from a map of a single index
532
+ # returns a MultiIndex object.
533
+ result = index.map(lambda x: (x, x == 1))
534
+ expected = MultiIndex.from_tuples([(i, i == 1) for i in index])
535
+ tm.assert_index_equal(result, expected)
536
+
537
+ def test_map_with_tuples_mi(self):
538
+ # Test that returning a single object from a MultiIndex
539
+ # returns an Index.
540
+ first_level = ["foo", "bar", "baz"]
541
+ multi_index = MultiIndex.from_tuples(zip(first_level, [1, 2, 3]))
542
+ reduced_index = multi_index.map(lambda x: x[0])
543
+ tm.assert_index_equal(reduced_index, Index(first_level))
544
+
545
+ @pytest.mark.parametrize(
546
+ "index",
547
+ [
548
+ date_range("2020-01-01", freq="D", periods=10),
549
+ period_range("2020-01-01", freq="D", periods=10),
550
+ timedelta_range("1 day", periods=10),
551
+ ],
552
+ )
553
+ def test_map_tseries_indices_return_index(self, index):
554
+ expected = Index([1] * 10)
555
+ result = index.map(lambda x: 1)
556
+ tm.assert_index_equal(expected, result)
557
+
558
+ def test_map_tseries_indices_accsr_return_index(self):
559
+ date_index = DatetimeIndex(
560
+ date_range("2020-01-01", periods=24, freq="h"), name="hourly"
561
+ )
562
+ result = date_index.map(lambda x: x.hour)
563
+ expected = Index(np.arange(24, dtype="int64"), name="hourly")
564
+ tm.assert_index_equal(result, expected, exact=True)
565
+
566
+ @pytest.mark.parametrize(
567
+ "mapper",
568
+ [
569
+ lambda values, index: {i: e for e, i in zip(values, index)},
570
+ lambda values, index: Series(values, index),
571
+ ],
572
+ )
573
+ def test_map_dictlike_simple(self, mapper):
574
+ # GH 12756
575
+ expected = Index(["foo", "bar", "baz"])
576
+ index = Index(np.arange(3), dtype=np.int64)
577
+ result = index.map(mapper(expected.values, index))
578
+ tm.assert_index_equal(result, expected)
579
+
580
+ @pytest.mark.parametrize(
581
+ "mapper",
582
+ [
583
+ lambda values, index: {i: e for e, i in zip(values, index)},
584
+ lambda values, index: Series(values, index),
585
+ ],
586
+ )
587
+ @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
588
+ def test_map_dictlike(self, index, mapper, request):
589
+ # GH 12756
590
+ if isinstance(index, CategoricalIndex):
591
+ pytest.skip("Tested in test_categorical")
592
+ elif not index.is_unique:
593
+ pytest.skip("Cannot map duplicated index")
594
+
595
+ rng = np.arange(len(index), 0, -1, dtype=np.int64)
596
+
597
+ if index.empty:
598
+ # to match proper result coercion for uints
599
+ expected = Index([])
600
+ elif is_numeric_dtype(index.dtype):
601
+ expected = index._constructor(rng, dtype=index.dtype)
602
+ elif type(index) is Index and index.dtype != object:
603
+ # i.e. EA-backed, for now just Nullable
604
+ expected = Index(rng, dtype=index.dtype)
605
+ else:
606
+ expected = Index(rng)
607
+
608
+ result = index.map(mapper(expected, index))
609
+ tm.assert_index_equal(result, expected)
610
+
611
+ @pytest.mark.parametrize(
612
+ "mapper",
613
+ [Series(["foo", 2.0, "baz"], index=[0, 2, -1]), {0: "foo", 2: 2.0, -1: "baz"}],
614
+ )
615
+ def test_map_with_non_function_missing_values(self, mapper):
616
+ # GH 12756
617
+ expected = Index([2.0, np.nan, "foo"])
618
+ result = Index([2, 1, 0]).map(mapper)
619
+
620
+ tm.assert_index_equal(expected, result)
621
+
622
+ def test_map_na_exclusion(self):
623
+ index = Index([1.5, np.nan, 3, np.nan, 5])
624
+
625
+ result = index.map(lambda x: x * 2, na_action="ignore")
626
+ expected = index * 2
627
+ tm.assert_index_equal(result, expected)
628
+
629
+ def test_map_defaultdict(self):
630
+ index = Index([1, 2, 3])
631
+ default_dict = defaultdict(lambda: "blank")
632
+ default_dict[1] = "stuff"
633
+ result = index.map(default_dict)
634
+ expected = Index(["stuff", "blank", "blank"])
635
+ tm.assert_index_equal(result, expected)
636
+
637
+ @pytest.mark.parametrize("name,expected", [("foo", "foo"), ("bar", None)])
638
+ def test_append_empty_preserve_name(self, name, expected):
639
+ left = Index([], name="foo")
640
+ right = Index([1, 2, 3], name=name)
641
+
642
+ msg = "The behavior of array concatenation with empty entries is deprecated"
643
+ with tm.assert_produces_warning(FutureWarning, match=msg):
644
+ result = left.append(right)
645
+ assert result.name == expected
646
+
647
+ @pytest.mark.parametrize(
648
+ "index, expected",
649
+ [
650
+ ("string", False),
651
+ ("bool-object", False),
652
+ ("bool-dtype", False),
653
+ ("categorical", False),
654
+ ("int64", True),
655
+ ("int32", True),
656
+ ("uint64", True),
657
+ ("uint32", True),
658
+ ("datetime", False),
659
+ ("float64", True),
660
+ ("float32", True),
661
+ ],
662
+ indirect=["index"],
663
+ )
664
+ def test_is_numeric(self, index, expected):
665
+ assert is_any_real_numeric_dtype(index) is expected
666
+
667
+ @pytest.mark.parametrize(
668
+ "index, expected",
669
+ [
670
+ ("string", True),
671
+ ("bool-object", True),
672
+ ("bool-dtype", False),
673
+ ("categorical", False),
674
+ ("int64", False),
675
+ ("int32", False),
676
+ ("uint64", False),
677
+ ("uint32", False),
678
+ ("datetime", False),
679
+ ("float64", False),
680
+ ("float32", False),
681
+ ],
682
+ indirect=["index"],
683
+ )
684
+ def test_is_object(self, index, expected, using_infer_string):
685
+ if using_infer_string and index.dtype == "string" and expected:
686
+ expected = False
687
+ assert is_object_dtype(index) is expected
688
+
689
+ def test_summary(self, index):
690
+ index._summary()
691
+
692
+ def test_format_bug(self):
693
+ # GH 14626
694
+ # windows has different precision on datetime.datetime.now (it doesn't
695
+ # include us since the default for Timestamp shows these but Index
696
+ # formatting does not we are skipping)
697
+ now = datetime.now()
698
+ msg = r"Index\.format is deprecated"
699
+
700
+ if not str(now).endswith("000"):
701
+ index = Index([now])
702
+ with tm.assert_produces_warning(FutureWarning, match=msg):
703
+ formatted = index.format()
704
+ expected = [str(index[0])]
705
+ assert formatted == expected
706
+
707
+ with tm.assert_produces_warning(FutureWarning, match=msg):
708
+ Index([]).format()
709
+
710
+ @pytest.mark.parametrize("vals", [[1, 2.0 + 3.0j, 4.0], ["a", "b", "c"]])
711
+ def test_format_missing(self, vals, nulls_fixture):
712
+ # 2845
713
+ vals = list(vals) # Copy for each iteration
714
+ vals.append(nulls_fixture)
715
+ index = Index(vals, dtype=object)
716
+ # TODO: case with complex dtype?
717
+
718
+ msg = r"Index\.format is deprecated"
719
+ with tm.assert_produces_warning(FutureWarning, match=msg):
720
+ formatted = index.format()
721
+ null_repr = "NaN" if isinstance(nulls_fixture, float) else str(nulls_fixture)
722
+ expected = [str(index[0]), str(index[1]), str(index[2]), null_repr]
723
+
724
+ assert formatted == expected
725
+ assert index[3] is nulls_fixture
726
+
727
+ @pytest.mark.parametrize("op", ["any", "all"])
728
+ def test_logical_compat(self, op, simple_index):
729
+ index = simple_index
730
+ left = getattr(index, op)()
731
+ assert left == getattr(index.values, op)()
732
+ right = getattr(index.to_series(), op)()
733
+ # left might not match right exactly in e.g. string cases where the
734
+ # because we use np.any/all instead of .any/all
735
+ assert bool(left) == bool(right)
736
+
737
+ @pytest.mark.parametrize(
738
+ "index", ["string", "int64", "int32", "float64", "float32"], indirect=True
739
+ )
740
+ def test_drop_by_str_label(self, index):
741
+ n = len(index)
742
+ drop = index[list(range(5, 10))]
743
+ dropped = index.drop(drop)
744
+
745
+ expected = index[list(range(5)) + list(range(10, n))]
746
+ tm.assert_index_equal(dropped, expected)
747
+
748
+ dropped = index.drop(index[0])
749
+ expected = index[1:]
750
+ tm.assert_index_equal(dropped, expected)
751
+
752
+ @pytest.mark.parametrize(
753
+ "index", ["string", "int64", "int32", "float64", "float32"], indirect=True
754
+ )
755
+ @pytest.mark.parametrize("keys", [["foo", "bar"], ["1", "bar"]])
756
+ def test_drop_by_str_label_raises_missing_keys(self, index, keys):
757
+ with pytest.raises(KeyError, match=""):
758
+ index.drop(keys)
759
+
760
+ @pytest.mark.parametrize(
761
+ "index", ["string", "int64", "int32", "float64", "float32"], indirect=True
762
+ )
763
+ def test_drop_by_str_label_errors_ignore(self, index):
764
+ n = len(index)
765
+ drop = index[list(range(5, 10))]
766
+ mixed = drop.tolist() + ["foo"]
767
+ dropped = index.drop(mixed, errors="ignore")
768
+
769
+ expected = index[list(range(5)) + list(range(10, n))]
770
+ tm.assert_index_equal(dropped, expected)
771
+
772
+ dropped = index.drop(["foo", "bar"], errors="ignore")
773
+ expected = index[list(range(n))]
774
+ tm.assert_index_equal(dropped, expected)
775
+
776
+ def test_drop_by_numeric_label_loc(self):
777
+ # TODO: Parametrize numeric and str tests after self.strIndex fixture
778
+ index = Index([1, 2, 3])
779
+ dropped = index.drop(1)
780
+ expected = Index([2, 3])
781
+
782
+ tm.assert_index_equal(dropped, expected)
783
+
784
+ def test_drop_by_numeric_label_raises_missing_keys(self):
785
+ index = Index([1, 2, 3])
786
+ with pytest.raises(KeyError, match=""):
787
+ index.drop([3, 4])
788
+
789
+ @pytest.mark.parametrize(
790
+ "key,expected", [(4, Index([1, 2, 3])), ([3, 4, 5], Index([1, 2]))]
791
+ )
792
+ def test_drop_by_numeric_label_errors_ignore(self, key, expected):
793
+ index = Index([1, 2, 3])
794
+ dropped = index.drop(key, errors="ignore")
795
+
796
+ tm.assert_index_equal(dropped, expected)
797
+
798
+ @pytest.mark.parametrize(
799
+ "values",
800
+ [["a", "b", ("c", "d")], ["a", ("c", "d"), "b"], [("c", "d"), "a", "b"]],
801
+ )
802
+ @pytest.mark.parametrize("to_drop", [[("c", "d"), "a"], ["a", ("c", "d")]])
803
+ def test_drop_tuple(self, values, to_drop):
804
+ # GH 18304
805
+ index = Index(values)
806
+ expected = Index(["b"], dtype=object)
807
+
808
+ result = index.drop(to_drop)
809
+ tm.assert_index_equal(result, expected)
810
+
811
+ removed = index.drop(to_drop[0])
812
+ for drop_me in to_drop[1], [to_drop[1]]:
813
+ result = removed.drop(drop_me)
814
+ tm.assert_index_equal(result, expected)
815
+
816
+ removed = index.drop(to_drop[1])
817
+ msg = rf"\"\[{re.escape(to_drop[1].__repr__())}\] not found in axis\""
818
+ for drop_me in to_drop[1], [to_drop[1]]:
819
+ with pytest.raises(KeyError, match=msg):
820
+ removed.drop(drop_me)
821
+
822
+ @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
823
+ def test_drop_with_duplicates_in_index(self, index):
824
+ # GH38051
825
+ if len(index) == 0 or isinstance(index, MultiIndex):
826
+ pytest.skip("Test doesn't make sense for empty MultiIndex")
827
+ if isinstance(index, IntervalIndex) and not IS64:
828
+ pytest.skip("Cannot test IntervalIndex with int64 dtype on 32 bit platform")
829
+ index = index.unique().repeat(2)
830
+ expected = index[2:]
831
+ result = index.drop(index[0])
832
+ tm.assert_index_equal(result, expected)
833
+
834
+ @pytest.mark.parametrize(
835
+ "attr",
836
+ [
837
+ "is_monotonic_increasing",
838
+ "is_monotonic_decreasing",
839
+ "_is_strictly_monotonic_increasing",
840
+ "_is_strictly_monotonic_decreasing",
841
+ ],
842
+ )
843
+ def test_is_monotonic_incomparable(self, attr):
844
+ index = Index([5, datetime.now(), 7])
845
+ assert not getattr(index, attr)
846
+
847
+ @pytest.mark.parametrize("values", [["foo", "bar", "quux"], {"foo", "bar", "quux"}])
848
+ @pytest.mark.parametrize(
849
+ "index,expected",
850
+ [
851
+ (Index(["qux", "baz", "foo", "bar"]), np.array([False, False, True, True])),
852
+ (Index([]), np.array([], dtype=bool)), # empty
853
+ ],
854
+ )
855
+ def test_isin(self, values, index, expected):
856
+ result = index.isin(values)
857
+ tm.assert_numpy_array_equal(result, expected)
858
+
859
+ def test_isin_nan_common_object(
860
+ self, nulls_fixture, nulls_fixture2, using_infer_string
861
+ ):
862
+ # Test cartesian product of null fixtures and ensure that we don't
863
+ # mangle the various types (save a corner case with PyPy)
864
+ idx = Index(["a", nulls_fixture])
865
+
866
+ # all nans are the same
867
+ if (
868
+ isinstance(nulls_fixture, float)
869
+ and isinstance(nulls_fixture2, float)
870
+ and math.isnan(nulls_fixture)
871
+ and math.isnan(nulls_fixture2)
872
+ ):
873
+ tm.assert_numpy_array_equal(
874
+ idx.isin([nulls_fixture2]),
875
+ np.array([False, True]),
876
+ )
877
+
878
+ elif nulls_fixture is nulls_fixture2: # should preserve NA type
879
+ tm.assert_numpy_array_equal(
880
+ idx.isin([nulls_fixture2]),
881
+ np.array([False, True]),
882
+ )
883
+
884
+ elif using_infer_string and idx.dtype == "string":
885
+ tm.assert_numpy_array_equal(
886
+ idx.isin([nulls_fixture2]),
887
+ np.array([False, True]),
888
+ )
889
+
890
+ else:
891
+ tm.assert_numpy_array_equal(
892
+ idx.isin([nulls_fixture2]),
893
+ np.array([False, False]),
894
+ )
895
+
896
+ def test_isin_nan_common_float64(self, nulls_fixture, float_numpy_dtype):
897
+ dtype = float_numpy_dtype
898
+
899
+ if nulls_fixture is pd.NaT or nulls_fixture is pd.NA:
900
+ # Check 1) that we cannot construct a float64 Index with this value
901
+ # and 2) that with an NaN we do not have .isin(nulls_fixture)
902
+ msg = (
903
+ r"float\(\) argument must be a string or a (real )?number, "
904
+ f"not {repr(type(nulls_fixture).__name__)}"
905
+ )
906
+ with pytest.raises(TypeError, match=msg):
907
+ Index([1.0, nulls_fixture], dtype=dtype)
908
+
909
+ idx = Index([1.0, np.nan], dtype=dtype)
910
+ assert not idx.isin([nulls_fixture]).any()
911
+ return
912
+
913
+ idx = Index([1.0, nulls_fixture], dtype=dtype)
914
+ res = idx.isin([np.nan])
915
+ tm.assert_numpy_array_equal(res, np.array([False, True]))
916
+
917
+ # we cannot compare NaT with NaN
918
+ res = idx.isin([pd.NaT])
919
+ tm.assert_numpy_array_equal(res, np.array([False, False]))
920
+
921
+ @pytest.mark.parametrize("level", [0, -1])
922
+ @pytest.mark.parametrize(
923
+ "index",
924
+ [
925
+ Index(["qux", "baz", "foo", "bar"]),
926
+ Index([1.0, 2.0, 3.0, 4.0], dtype=np.float64),
927
+ ],
928
+ )
929
+ def test_isin_level_kwarg(self, level, index):
930
+ values = index.tolist()[-2:] + ["nonexisting"]
931
+
932
+ expected = np.array([False, False, True, True])
933
+ tm.assert_numpy_array_equal(expected, index.isin(values, level=level))
934
+
935
+ index.name = "foobar"
936
+ tm.assert_numpy_array_equal(expected, index.isin(values, level="foobar"))
937
+
938
+ def test_isin_level_kwarg_bad_level_raises(self, index):
939
+ for level in [10, index.nlevels, -(index.nlevels + 1)]:
940
+ with pytest.raises(IndexError, match="Too many levels"):
941
+ index.isin([], level=level)
942
+
943
+ @pytest.mark.parametrize("label", [1.0, "foobar", "xyzzy", np.nan])
944
+ def test_isin_level_kwarg_bad_label_raises(self, label, index):
945
+ if isinstance(index, MultiIndex):
946
+ index = index.rename(["foo", "bar"] + index.names[2:])
947
+ msg = f"'Level {label} not found'"
948
+ else:
949
+ index = index.rename("foo")
950
+ msg = rf"Requested level \({label}\) does not match index name \(foo\)"
951
+ with pytest.raises(KeyError, match=msg):
952
+ index.isin([], level=label)
953
+
954
+ @pytest.mark.parametrize("empty", [[], Series(dtype=object), np.array([])])
955
+ def test_isin_empty(self, empty):
956
+ # see gh-16991
957
+ index = Index(["a", "b"])
958
+ expected = np.array([False, False])
959
+
960
+ result = index.isin(empty)
961
+ tm.assert_numpy_array_equal(expected, result)
962
+
963
+ @td.skip_if_no("pyarrow")
964
+ def test_isin_arrow_string_null(self):
965
+ # GH#55821
966
+ index = Index(["a", "b"], dtype="string[pyarrow_numpy]")
967
+ result = index.isin([None])
968
+ expected = np.array([False, False])
969
+ tm.assert_numpy_array_equal(result, expected)
970
+
971
+ @pytest.mark.parametrize(
972
+ "values",
973
+ [
974
+ [1, 2, 3, 4],
975
+ [1.0, 2.0, 3.0, 4.0],
976
+ [True, True, True, True],
977
+ ["foo", "bar", "baz", "qux"],
978
+ date_range("2018-01-01", freq="D", periods=4),
979
+ ],
980
+ )
981
+ def test_boolean_cmp(self, values):
982
+ index = Index(values)
983
+ result = index == values
984
+ expected = np.array([True, True, True, True], dtype=bool)
985
+
986
+ tm.assert_numpy_array_equal(result, expected)
987
+
988
+ @pytest.mark.parametrize("index", ["string"], indirect=True)
989
+ @pytest.mark.parametrize("name,level", [(None, 0), ("a", "a")])
990
+ def test_get_level_values(self, index, name, level):
991
+ expected = index.copy()
992
+ if name:
993
+ expected.name = name
994
+
995
+ result = expected.get_level_values(level)
996
+ tm.assert_index_equal(result, expected)
997
+
998
+ def test_slice_keep_name(self):
999
+ index = Index(["a", "b"], name="asdf")
1000
+ assert index.name == index[1:].name
1001
+
1002
+ @pytest.mark.parametrize(
1003
+ "index",
1004
+ [
1005
+ "string",
1006
+ "datetime",
1007
+ "int64",
1008
+ "int32",
1009
+ "uint64",
1010
+ "uint32",
1011
+ "float64",
1012
+ "float32",
1013
+ ],
1014
+ indirect=True,
1015
+ )
1016
+ def test_join_self(self, index, join_type):
1017
+ result = index.join(index, how=join_type)
1018
+ expected = index
1019
+ if join_type == "outer":
1020
+ expected = expected.sort_values()
1021
+ tm.assert_index_equal(result, expected)
1022
+
1023
+ @pytest.mark.parametrize("method", ["strip", "rstrip", "lstrip"])
1024
+ def test_str_attribute(self, method):
1025
+ # GH9068
1026
+ index = Index([" jack", "jill ", " jesse ", "frank"])
1027
+ expected = Index([getattr(str, method)(x) for x in index.values])
1028
+
1029
+ result = getattr(index.str, method)()
1030
+ tm.assert_index_equal(result, expected)
1031
+
1032
+ @pytest.mark.parametrize(
1033
+ "index",
1034
+ [
1035
+ Index(range(5)),
1036
+ date_range("2020-01-01", periods=10),
1037
+ MultiIndex.from_tuples([("foo", "1"), ("bar", "3")]),
1038
+ period_range(start="2000", end="2010", freq="Y"),
1039
+ ],
1040
+ )
1041
+ def test_str_attribute_raises(self, index):
1042
+ with pytest.raises(AttributeError, match="only use .str accessor"):
1043
+ index.str.repeat(2)
1044
+
1045
+ @pytest.mark.parametrize(
1046
+ "expand,expected",
1047
+ [
1048
+ (None, Index([["a", "b", "c"], ["d", "e"], ["f"]])),
1049
+ (False, Index([["a", "b", "c"], ["d", "e"], ["f"]])),
1050
+ (
1051
+ True,
1052
+ MultiIndex.from_tuples(
1053
+ [("a", "b", "c"), ("d", "e", np.nan), ("f", np.nan, np.nan)]
1054
+ ),
1055
+ ),
1056
+ ],
1057
+ )
1058
+ def test_str_split(self, expand, expected):
1059
+ index = Index(["a b c", "d e", "f"])
1060
+ if expand is not None:
1061
+ result = index.str.split(expand=expand)
1062
+ else:
1063
+ result = index.str.split()
1064
+
1065
+ tm.assert_index_equal(result, expected)
1066
+
1067
+ def test_str_bool_return(self):
1068
+ # test boolean case, should return np.array instead of boolean Index
1069
+ index = Index(["a1", "a2", "b1", "b2"])
1070
+ result = index.str.startswith("a")
1071
+ expected = np.array([True, True, False, False])
1072
+
1073
+ tm.assert_numpy_array_equal(result, expected)
1074
+ assert isinstance(result, np.ndarray)
1075
+
1076
+ def test_str_bool_series_indexing(self):
1077
+ index = Index(["a1", "a2", "b1", "b2"])
1078
+ s = Series(range(4), index=index)
1079
+
1080
+ result = s[s.index.str.startswith("a")]
1081
+ expected = Series(range(2), index=["a1", "a2"])
1082
+ tm.assert_series_equal(result, expected)
1083
+
1084
+ @pytest.mark.parametrize(
1085
+ "index,expected", [(Index(list("abcd")), True), (Index(range(4)), False)]
1086
+ )
1087
+ def test_tab_completion(self, index, expected):
1088
+ # GH 9910
1089
+ result = "str" in dir(index)
1090
+ assert result == expected
1091
+
1092
+ def test_indexing_doesnt_change_class(self):
1093
+ index = Index([1, 2, 3, "a", "b", "c"])
1094
+
1095
+ assert index[1:3].identical(Index([2, 3], dtype=np.object_))
1096
+ assert index[[0, 1]].identical(Index([1, 2], dtype=np.object_))
1097
+
1098
+ def test_outer_join_sort(self):
1099
+ left_index = Index(np.random.default_rng(2).permutation(15))
1100
+ right_index = date_range("2020-01-01", periods=10)
1101
+
1102
+ with tm.assert_produces_warning(RuntimeWarning):
1103
+ result = left_index.join(right_index, how="outer")
1104
+
1105
+ with tm.assert_produces_warning(RuntimeWarning):
1106
+ expected = left_index.astype(object).union(right_index.astype(object))
1107
+
1108
+ tm.assert_index_equal(result, expected)
1109
+
1110
+ def test_take_fill_value(self):
1111
+ # GH 12631
1112
+ index = Index(list("ABC"), name="xxx")
1113
+ result = index.take(np.array([1, 0, -1]))
1114
+ expected = Index(list("BAC"), name="xxx")
1115
+ tm.assert_index_equal(result, expected)
1116
+
1117
+ # fill_value
1118
+ result = index.take(np.array([1, 0, -1]), fill_value=True)
1119
+ expected = Index(["B", "A", np.nan], name="xxx")
1120
+ tm.assert_index_equal(result, expected)
1121
+
1122
+ # allow_fill=False
1123
+ result = index.take(np.array([1, 0, -1]), allow_fill=False, fill_value=True)
1124
+ expected = Index(["B", "A", "C"], name="xxx")
1125
+ tm.assert_index_equal(result, expected)
1126
+
1127
+ def test_take_fill_value_none_raises(self):
1128
+ index = Index(list("ABC"), name="xxx")
1129
+ msg = (
1130
+ "When allow_fill=True and fill_value is not None, "
1131
+ "all indices must be >= -1"
1132
+ )
1133
+
1134
+ with pytest.raises(ValueError, match=msg):
1135
+ index.take(np.array([1, 0, -2]), fill_value=True)
1136
+ with pytest.raises(ValueError, match=msg):
1137
+ index.take(np.array([1, 0, -5]), fill_value=True)
1138
+
1139
+ def test_take_bad_bounds_raises(self):
1140
+ index = Index(list("ABC"), name="xxx")
1141
+ with pytest.raises(IndexError, match="out of bounds"):
1142
+ index.take(np.array([1, -5]))
1143
+
1144
+ @pytest.mark.parametrize("name", [None, "foobar"])
1145
+ @pytest.mark.parametrize(
1146
+ "labels",
1147
+ [
1148
+ [],
1149
+ np.array([]),
1150
+ ["A", "B", "C"],
1151
+ ["C", "B", "A"],
1152
+ np.array(["A", "B", "C"]),
1153
+ np.array(["C", "B", "A"]),
1154
+ # Must preserve name even if dtype changes
1155
+ date_range("20130101", periods=3).values,
1156
+ date_range("20130101", periods=3).tolist(),
1157
+ ],
1158
+ )
1159
+ def test_reindex_preserves_name_if_target_is_list_or_ndarray(self, name, labels):
1160
+ # GH6552
1161
+ index = Index([0, 1, 2])
1162
+ index.name = name
1163
+ assert index.reindex(labels)[0].name == name
1164
+
1165
+ @pytest.mark.parametrize("labels", [[], np.array([]), np.array([], dtype=np.int64)])
1166
+ def test_reindex_preserves_type_if_target_is_empty_list_or_array(self, labels):
1167
+ # GH7774
1168
+ index = Index(list("abc"))
1169
+ assert index.reindex(labels)[0].dtype.type == index.dtype.type
1170
+
1171
+ @pytest.mark.parametrize(
1172
+ "labels,dtype",
1173
+ [
1174
+ (DatetimeIndex([]), np.datetime64),
1175
+ ],
1176
+ )
1177
+ def test_reindex_doesnt_preserve_type_if_target_is_empty_index(self, labels, dtype):
1178
+ # GH7774
1179
+ index = Index(list("abc"))
1180
+ assert index.reindex(labels)[0].dtype.type == dtype
1181
+
1182
+ def test_reindex_doesnt_preserve_type_if_target_is_empty_index_numeric(
1183
+ self, any_real_numpy_dtype
1184
+ ):
1185
+ # GH7774
1186
+ dtype = any_real_numpy_dtype
1187
+ index = Index(list("abc"))
1188
+ labels = Index([], dtype=dtype)
1189
+ assert index.reindex(labels)[0].dtype == dtype
1190
+
1191
+ def test_reindex_no_type_preserve_target_empty_mi(self):
1192
+ index = Index(list("abc"))
1193
+ result = index.reindex(
1194
+ MultiIndex([Index([], np.int64), Index([], np.float64)], [[], []])
1195
+ )[0]
1196
+ assert result.levels[0].dtype.type == np.int64
1197
+ assert result.levels[1].dtype.type == np.float64
1198
+
1199
+ def test_reindex_ignoring_level(self):
1200
+ # GH#35132
1201
+ idx = Index([1, 2, 3], name="x")
1202
+ idx2 = Index([1, 2, 3, 4], name="x")
1203
+ expected = Index([1, 2, 3, 4], name="x")
1204
+ result, _ = idx.reindex(idx2, level="x")
1205
+ tm.assert_index_equal(result, expected)
1206
+
1207
+ def test_groupby(self):
1208
+ index = Index(range(5))
1209
+ result = index.groupby(np.array([1, 1, 2, 2, 2]))
1210
+ expected = {1: Index([0, 1]), 2: Index([2, 3, 4])}
1211
+
1212
+ tm.assert_dict_equal(result, expected)
1213
+
1214
+ @pytest.mark.parametrize(
1215
+ "mi,expected",
1216
+ [
1217
+ (MultiIndex.from_tuples([(1, 2), (4, 5)]), np.array([True, True])),
1218
+ (MultiIndex.from_tuples([(1, 2), (4, 6)]), np.array([True, False])),
1219
+ ],
1220
+ )
1221
+ def test_equals_op_multiindex(self, mi, expected):
1222
+ # GH9785
1223
+ # test comparisons of multiindex
1224
+ df = DataFrame(
1225
+ [3, 6],
1226
+ columns=["c"],
1227
+ index=MultiIndex.from_arrays([[1, 4], [2, 5]], names=["a", "b"]),
1228
+ )
1229
+
1230
+ result = df.index == mi
1231
+ tm.assert_numpy_array_equal(result, expected)
1232
+
1233
+ def test_equals_op_multiindex_identify(self):
1234
+ df = DataFrame(
1235
+ [3, 6],
1236
+ columns=["c"],
1237
+ index=MultiIndex.from_arrays([[1, 4], [2, 5]], names=["a", "b"]),
1238
+ )
1239
+
1240
+ result = df.index == df.index
1241
+ expected = np.array([True, True])
1242
+ tm.assert_numpy_array_equal(result, expected)
1243
+
1244
+ @pytest.mark.parametrize(
1245
+ "index",
1246
+ [
1247
+ MultiIndex.from_tuples([(1, 2), (4, 5), (8, 9)]),
1248
+ Index(["foo", "bar", "baz"]),
1249
+ ],
1250
+ )
1251
+ def test_equals_op_mismatched_multiindex_raises(self, index):
1252
+ df = DataFrame(
1253
+ [3, 6],
1254
+ columns=["c"],
1255
+ index=MultiIndex.from_arrays([[1, 4], [2, 5]], names=["a", "b"]),
1256
+ )
1257
+
1258
+ with pytest.raises(ValueError, match="Lengths must match"):
1259
+ df.index == index
1260
+
1261
+ def test_equals_op_index_vs_mi_same_length(self, using_infer_string):
1262
+ mi = MultiIndex.from_tuples([(1, 2), (4, 5), (8, 9)])
1263
+ index = Index(["foo", "bar", "baz"])
1264
+
1265
+ result = mi == index
1266
+ expected = np.array([False, False, False])
1267
+ tm.assert_numpy_array_equal(result, expected)
1268
+
1269
+ @pytest.mark.parametrize(
1270
+ "dt_conv, arg",
1271
+ [
1272
+ (pd.to_datetime, ["2000-01-01", "2000-01-02"]),
1273
+ (pd.to_timedelta, ["01:02:03", "01:02:04"]),
1274
+ ],
1275
+ )
1276
+ def test_dt_conversion_preserves_name(self, dt_conv, arg):
1277
+ # GH 10875
1278
+ index = Index(arg, name="label")
1279
+ assert index.name == dt_conv(index).name
1280
+
1281
+ def test_cached_properties_not_settable(self):
1282
+ index = Index([1, 2, 3])
1283
+ with pytest.raises(AttributeError, match="Can't set attribute"):
1284
+ index.is_unique = False
1285
+
1286
+ def test_tab_complete_warning(self, ip):
1287
+ # https://github.com/pandas-dev/pandas/issues/16409
1288
+ pytest.importorskip("IPython", minversion="6.0.0")
1289
+ from IPython.core.completer import provisionalcompleter
1290
+
1291
+ code = "import pandas as pd; idx = pd.Index([1, 2])"
1292
+ ip.run_cell(code)
1293
+
1294
+ # GH 31324 newer jedi version raises Deprecation warning;
1295
+ # appears resolved 2021-02-02
1296
+ with tm.assert_produces_warning(None, raise_on_extra_warnings=False):
1297
+ with provisionalcompleter("ignore"):
1298
+ list(ip.Completer.completions("idx.", 4))
1299
+
1300
+ def test_contains_method_removed(self, index):
1301
+ # GH#30103 method removed for all types except IntervalIndex
1302
+ if isinstance(index, IntervalIndex):
1303
+ index.contains(1)
1304
+ else:
1305
+ msg = f"'{type(index).__name__}' object has no attribute 'contains'"
1306
+ with pytest.raises(AttributeError, match=msg):
1307
+ index.contains(1)
1308
+
1309
+ def test_sortlevel(self):
1310
+ index = Index([5, 4, 3, 2, 1])
1311
+ with pytest.raises(Exception, match="ascending must be a single bool value or"):
1312
+ index.sortlevel(ascending="True")
1313
+
1314
+ with pytest.raises(
1315
+ Exception, match="ascending must be a list of bool values of length 1"
1316
+ ):
1317
+ index.sortlevel(ascending=[True, True])
1318
+
1319
+ with pytest.raises(Exception, match="ascending must be a bool value"):
1320
+ index.sortlevel(ascending=["True"])
1321
+
1322
+ expected = Index([1, 2, 3, 4, 5])
1323
+ result = index.sortlevel(ascending=[True])
1324
+ tm.assert_index_equal(result[0], expected)
1325
+
1326
+ expected = Index([1, 2, 3, 4, 5])
1327
+ result = index.sortlevel(ascending=True)
1328
+ tm.assert_index_equal(result[0], expected)
1329
+
1330
+ expected = Index([5, 4, 3, 2, 1])
1331
+ result = index.sortlevel(ascending=False)
1332
+ tm.assert_index_equal(result[0], expected)
1333
+
1334
+ def test_sortlevel_na_position(self):
1335
+ # GH#51612
1336
+ idx = Index([1, np.nan])
1337
+ result = idx.sortlevel(na_position="first")[0]
1338
+ expected = Index([np.nan, 1])
1339
+ tm.assert_index_equal(result, expected)
1340
+
1341
+ @pytest.mark.parametrize(
1342
+ "periods, expected_results",
1343
+ [
1344
+ (1, [np.nan, 10, 10, 10, 10]),
1345
+ (2, [np.nan, np.nan, 20, 20, 20]),
1346
+ (3, [np.nan, np.nan, np.nan, 30, 30]),
1347
+ ],
1348
+ )
1349
+ def test_index_diff(self, periods, expected_results):
1350
+ # GH#19708
1351
+ idx = Index([10, 20, 30, 40, 50])
1352
+ result = idx.diff(periods)
1353
+ expected = Index(expected_results)
1354
+
1355
+ tm.assert_index_equal(result, expected)
1356
+
1357
+ @pytest.mark.parametrize(
1358
+ "decimals, expected_results",
1359
+ [
1360
+ (0, [1.0, 2.0, 3.0]),
1361
+ (1, [1.2, 2.3, 3.5]),
1362
+ (2, [1.23, 2.35, 3.46]),
1363
+ ],
1364
+ )
1365
+ def test_index_round(self, decimals, expected_results):
1366
+ # GH#19708
1367
+ idx = Index([1.234, 2.345, 3.456])
1368
+ result = idx.round(decimals)
1369
+ expected = Index(expected_results)
1370
+
1371
+ tm.assert_index_equal(result, expected)
1372
+
1373
+
1374
+ class TestMixedIntIndex:
1375
+ # Mostly the tests from common.py for which the results differ
1376
+ # in py2 and py3 because ints and strings are uncomparable in py3
1377
+ # (GH 13514)
1378
+ @pytest.fixture
1379
+ def simple_index(self) -> Index:
1380
+ return Index([0, "a", 1, "b", 2, "c"])
1381
+
1382
+ def test_argsort(self, simple_index):
1383
+ index = simple_index
1384
+ with pytest.raises(TypeError, match="'>|<' not supported"):
1385
+ index.argsort()
1386
+
1387
+ def test_numpy_argsort(self, simple_index):
1388
+ index = simple_index
1389
+ with pytest.raises(TypeError, match="'>|<' not supported"):
1390
+ np.argsort(index)
1391
+
1392
+ def test_copy_name(self, simple_index):
1393
+ # Check that "name" argument passed at initialization is honoured
1394
+ # GH12309
1395
+ index = simple_index
1396
+
1397
+ first = type(index)(index, copy=True, name="mario")
1398
+ second = type(first)(first, copy=False)
1399
+
1400
+ # Even though "copy=False", we want a new object.
1401
+ assert first is not second
1402
+ tm.assert_index_equal(first, second)
1403
+
1404
+ assert first.name == "mario"
1405
+ assert second.name == "mario"
1406
+
1407
+ s1 = Series(2, index=first)
1408
+ s2 = Series(3, index=second[:-1])
1409
+
1410
+ s3 = s1 * s2
1411
+
1412
+ assert s3.index.name == "mario"
1413
+
1414
+ def test_copy_name2(self):
1415
+ # Check that adding a "name" parameter to the copy is honored
1416
+ # GH14302
1417
+ index = Index([1, 2], name="MyName")
1418
+ index1 = index.copy()
1419
+
1420
+ tm.assert_index_equal(index, index1)
1421
+
1422
+ index2 = index.copy(name="NewName")
1423
+ tm.assert_index_equal(index, index2, check_names=False)
1424
+ assert index.name == "MyName"
1425
+ assert index2.name == "NewName"
1426
+
1427
+ def test_unique_na(self):
1428
+ idx = Index([2, np.nan, 2, 1], name="my_index")
1429
+ expected = Index([2, np.nan, 1], name="my_index")
1430
+ result = idx.unique()
1431
+ tm.assert_index_equal(result, expected)
1432
+
1433
+ def test_logical_compat(self, simple_index):
1434
+ index = simple_index
1435
+ assert index.all() == index.values.all()
1436
+ assert index.any() == index.values.any()
1437
+
1438
+ @pytest.mark.parametrize("how", ["any", "all"])
1439
+ @pytest.mark.parametrize("dtype", [None, object, "category"])
1440
+ @pytest.mark.parametrize(
1441
+ "vals,expected",
1442
+ [
1443
+ ([1, 2, 3], [1, 2, 3]),
1444
+ ([1.0, 2.0, 3.0], [1.0, 2.0, 3.0]),
1445
+ ([1.0, 2.0, np.nan, 3.0], [1.0, 2.0, 3.0]),
1446
+ (["A", "B", "C"], ["A", "B", "C"]),
1447
+ (["A", np.nan, "B", "C"], ["A", "B", "C"]),
1448
+ ],
1449
+ )
1450
+ def test_dropna(self, how, dtype, vals, expected):
1451
+ # GH 6194
1452
+ index = Index(vals, dtype=dtype)
1453
+ result = index.dropna(how=how)
1454
+ expected = Index(expected, dtype=dtype)
1455
+ tm.assert_index_equal(result, expected)
1456
+
1457
+ @pytest.mark.parametrize("how", ["any", "all"])
1458
+ @pytest.mark.parametrize(
1459
+ "index,expected",
1460
+ [
1461
+ (
1462
+ DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"]),
1463
+ DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"]),
1464
+ ),
1465
+ (
1466
+ DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03", pd.NaT]),
1467
+ DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"]),
1468
+ ),
1469
+ (
1470
+ TimedeltaIndex(["1 days", "2 days", "3 days"]),
1471
+ TimedeltaIndex(["1 days", "2 days", "3 days"]),
1472
+ ),
1473
+ (
1474
+ TimedeltaIndex([pd.NaT, "1 days", "2 days", "3 days", pd.NaT]),
1475
+ TimedeltaIndex(["1 days", "2 days", "3 days"]),
1476
+ ),
1477
+ (
1478
+ PeriodIndex(["2012-02", "2012-04", "2012-05"], freq="M"),
1479
+ PeriodIndex(["2012-02", "2012-04", "2012-05"], freq="M"),
1480
+ ),
1481
+ (
1482
+ PeriodIndex(["2012-02", "2012-04", "NaT", "2012-05"], freq="M"),
1483
+ PeriodIndex(["2012-02", "2012-04", "2012-05"], freq="M"),
1484
+ ),
1485
+ ],
1486
+ )
1487
+ def test_dropna_dt_like(self, how, index, expected):
1488
+ result = index.dropna(how=how)
1489
+ tm.assert_index_equal(result, expected)
1490
+
1491
+ def test_dropna_invalid_how_raises(self):
1492
+ msg = "invalid how option: xxx"
1493
+ with pytest.raises(ValueError, match=msg):
1494
+ Index([1, 2, 3]).dropna(how="xxx")
1495
+
1496
+ @pytest.mark.parametrize(
1497
+ "index",
1498
+ [
1499
+ Index([np.nan]),
1500
+ Index([np.nan, 1]),
1501
+ Index([1, 2, np.nan]),
1502
+ Index(["a", "b", np.nan]),
1503
+ pd.to_datetime(["NaT"]),
1504
+ pd.to_datetime(["NaT", "2000-01-01"]),
1505
+ pd.to_datetime(["2000-01-01", "NaT", "2000-01-02"]),
1506
+ pd.to_timedelta(["1 day", "NaT"]),
1507
+ ],
1508
+ )
1509
+ def test_is_monotonic_na(self, index):
1510
+ assert index.is_monotonic_increasing is False
1511
+ assert index.is_monotonic_decreasing is False
1512
+ assert index._is_strictly_monotonic_increasing is False
1513
+ assert index._is_strictly_monotonic_decreasing is False
1514
+
1515
+ @pytest.mark.parametrize("dtype", ["f8", "m8[ns]", "M8[us]"])
1516
+ @pytest.mark.parametrize("unique_first", [True, False])
1517
+ def test_is_monotonic_unique_na(self, dtype, unique_first):
1518
+ # GH 55755
1519
+ index = Index([None, 1, 1], dtype=dtype)
1520
+ if unique_first:
1521
+ assert index.is_unique is False
1522
+ assert index.is_monotonic_increasing is False
1523
+ assert index.is_monotonic_decreasing is False
1524
+ else:
1525
+ assert index.is_monotonic_increasing is False
1526
+ assert index.is_monotonic_decreasing is False
1527
+ assert index.is_unique is False
1528
+
1529
+ def test_int_name_format(self, frame_or_series):
1530
+ index = Index(["a", "b", "c"], name=0)
1531
+ result = frame_or_series(list(range(3)), index=index)
1532
+ assert "0" in repr(result)
1533
+
1534
+ def test_str_to_bytes_raises(self):
1535
+ # GH 26447
1536
+ index = Index([str(x) for x in range(10)])
1537
+ msg = "^'str' object cannot be interpreted as an integer$"
1538
+ with pytest.raises(TypeError, match=msg):
1539
+ bytes(index)
1540
+
1541
+ @pytest.mark.filterwarnings("ignore:elementwise comparison failed:FutureWarning")
1542
+ def test_index_with_tuple_bool(self):
1543
+ # GH34123
1544
+ # TODO: also this op right now produces FutureWarning from numpy
1545
+ # https://github.com/numpy/numpy/issues/11521
1546
+ idx = Index([("a", "b"), ("b", "c"), ("c", "a")])
1547
+ result = idx == ("c", "a")
1548
+ expected = np.array([False, False, True])
1549
+ tm.assert_numpy_array_equal(result, expected)
1550
+
1551
+
1552
+ class TestIndexUtils:
1553
+ @pytest.mark.parametrize(
1554
+ "data, names, expected",
1555
+ [
1556
+ ([[1, 2, 3]], None, Index([1, 2, 3])),
1557
+ ([[1, 2, 3]], ["name"], Index([1, 2, 3], name="name")),
1558
+ (
1559
+ [["a", "a"], ["c", "d"]],
1560
+ None,
1561
+ MultiIndex([["a"], ["c", "d"]], [[0, 0], [0, 1]]),
1562
+ ),
1563
+ (
1564
+ [["a", "a"], ["c", "d"]],
1565
+ ["L1", "L2"],
1566
+ MultiIndex([["a"], ["c", "d"]], [[0, 0], [0, 1]], names=["L1", "L2"]),
1567
+ ),
1568
+ ],
1569
+ )
1570
+ def test_ensure_index_from_sequences(self, data, names, expected):
1571
+ result = ensure_index_from_sequences(data, names)
1572
+ tm.assert_index_equal(result, expected)
1573
+
1574
+ def test_ensure_index_mixed_closed_intervals(self):
1575
+ # GH27172
1576
+ intervals = [
1577
+ pd.Interval(0, 1, closed="left"),
1578
+ pd.Interval(1, 2, closed="right"),
1579
+ pd.Interval(2, 3, closed="neither"),
1580
+ pd.Interval(3, 4, closed="both"),
1581
+ ]
1582
+ result = ensure_index(intervals)
1583
+ expected = Index(intervals, dtype=object)
1584
+ tm.assert_index_equal(result, expected)
1585
+
1586
+ def test_ensure_index_uint64(self):
1587
+ # with both 0 and a large-uint64, np.array will infer to float64
1588
+ # https://github.com/numpy/numpy/issues/19146
1589
+ # but a more accurate choice would be uint64
1590
+ values = [0, np.iinfo(np.uint64).max]
1591
+
1592
+ result = ensure_index(values)
1593
+ assert list(result) == values
1594
+
1595
+ expected = Index(values, dtype="uint64")
1596
+ tm.assert_index_equal(result, expected)
1597
+
1598
+ def test_get_combined_index(self):
1599
+ result = _get_combined_index([])
1600
+ expected = Index([])
1601
+ tm.assert_index_equal(result, expected)
1602
+
1603
+
1604
+ @pytest.mark.parametrize(
1605
+ "opname",
1606
+ [
1607
+ "eq",
1608
+ "ne",
1609
+ "le",
1610
+ "lt",
1611
+ "ge",
1612
+ "gt",
1613
+ "add",
1614
+ "radd",
1615
+ "sub",
1616
+ "rsub",
1617
+ "mul",
1618
+ "rmul",
1619
+ "truediv",
1620
+ "rtruediv",
1621
+ "floordiv",
1622
+ "rfloordiv",
1623
+ "pow",
1624
+ "rpow",
1625
+ "mod",
1626
+ "divmod",
1627
+ ],
1628
+ )
1629
+ def test_generated_op_names(opname, index):
1630
+ opname = f"__{opname}__"
1631
+ method = getattr(index, opname)
1632
+ assert method.__name__ == opname
1633
+
1634
+
1635
+ @pytest.mark.parametrize(
1636
+ "klass",
1637
+ [
1638
+ partial(CategoricalIndex, data=[1]),
1639
+ partial(DatetimeIndex, data=["2020-01-01"]),
1640
+ partial(PeriodIndex, data=["2020-01-01"]),
1641
+ partial(TimedeltaIndex, data=["1 day"]),
1642
+ partial(RangeIndex, data=range(1)),
1643
+ partial(IntervalIndex, data=[pd.Interval(0, 1)]),
1644
+ partial(Index, data=["a"], dtype=object),
1645
+ partial(MultiIndex, levels=[1], codes=[0]),
1646
+ ],
1647
+ )
1648
+ def test_index_subclass_constructor_wrong_kwargs(klass):
1649
+ # GH #19348
1650
+ with pytest.raises(TypeError, match="unexpected keyword argument"):
1651
+ klass(foo="bar")
1652
+
1653
+
1654
+ def test_deprecated_fastpath():
1655
+ msg = "[Uu]nexpected keyword argument"
1656
+ with pytest.raises(TypeError, match=msg):
1657
+ Index(np.array(["a", "b"], dtype=object), name="test", fastpath=True)
1658
+
1659
+ with pytest.raises(TypeError, match=msg):
1660
+ Index(np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True)
1661
+
1662
+ with pytest.raises(TypeError, match=msg):
1663
+ RangeIndex(0, 5, 2, name="test", fastpath=True)
1664
+
1665
+ with pytest.raises(TypeError, match=msg):
1666
+ CategoricalIndex(["a", "b", "c"], name="test", fastpath=True)
1667
+
1668
+
1669
+ def test_shape_of_invalid_index():
1670
+ # Pre-2.0, it was possible to create "invalid" index objects backed by
1671
+ # a multi-dimensional array (see https://github.com/pandas-dev/pandas/issues/27125
1672
+ # about this). However, as long as this is not solved in general,this test ensures
1673
+ # that the returned shape is consistent with this underlying array for
1674
+ # compat with matplotlib (see https://github.com/pandas-dev/pandas/issues/27775)
1675
+ idx = Index([0, 1, 2, 3])
1676
+ with pytest.raises(ValueError, match="Multi-dimensional indexing"):
1677
+ # GH#30588 multi-dimensional indexing deprecated
1678
+ idx[:, None]
1679
+
1680
+
1681
+ @pytest.mark.parametrize("dtype", [None, np.int64, np.uint64, np.float64])
1682
+ def test_validate_1d_input(dtype):
1683
+ # GH#27125 check that we do not have >1-dimensional input
1684
+ msg = "Index data must be 1-dimensional"
1685
+
1686
+ arr = np.arange(8).reshape(2, 2, 2)
1687
+ with pytest.raises(ValueError, match=msg):
1688
+ Index(arr, dtype=dtype)
1689
+
1690
+ df = DataFrame(arr.reshape(4, 2))
1691
+ with pytest.raises(ValueError, match=msg):
1692
+ Index(df, dtype=dtype)
1693
+
1694
+ # GH#13601 trying to assign a multi-dimensional array to an index is not allowed
1695
+ ser = Series(0, range(4))
1696
+ with pytest.raises(ValueError, match=msg):
1697
+ ser.index = np.array([[2, 3]] * 4, dtype=dtype)
1698
+
1699
+
1700
+ @pytest.mark.parametrize(
1701
+ "klass, extra_kwargs",
1702
+ [
1703
+ [Index, {}],
1704
+ *[[lambda x: Index(x, dtype=dtyp), {}] for dtyp in tm.ALL_REAL_NUMPY_DTYPES],
1705
+ [DatetimeIndex, {}],
1706
+ [TimedeltaIndex, {}],
1707
+ [PeriodIndex, {"freq": "Y"}],
1708
+ ],
1709
+ )
1710
+ def test_construct_from_memoryview(klass, extra_kwargs):
1711
+ # GH 13120
1712
+ result = klass(memoryview(np.arange(2000, 2005)), **extra_kwargs)
1713
+ expected = klass(list(range(2000, 2005)), **extra_kwargs)
1714
+ tm.assert_index_equal(result, expected, exact=True)
1715
+
1716
+
1717
+ @pytest.mark.parametrize("op", [operator.lt, operator.gt])
1718
+ def test_nan_comparison_same_object(op):
1719
+ # GH#47105
1720
+ idx = Index([np.nan])
1721
+ expected = np.array([False])
1722
+
1723
+ result = op(idx, idx)
1724
+ tm.assert_numpy_array_equal(result, expected)
1725
+
1726
+ result = op(idx, idx.copy())
1727
+ tm.assert_numpy_array_equal(result, expected)
1728
+
1729
+
1730
+ @td.skip_if_no("pyarrow")
1731
+ def test_is_monotonic_pyarrow_list_type():
1732
+ # GH 57333
1733
+ import pyarrow as pa
1734
+
1735
+ idx = Index([[1], [2, 3]], dtype=pd.ArrowDtype(pa.list_(pa.int64())))
1736
+ assert not idx.is_monotonic_increasing
1737
+ assert not idx.is_monotonic_decreasing
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_frozen.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ import pytest
4
+
5
+ from pandas.core.indexes.frozen import FrozenList
6
+
7
+
8
+ @pytest.fixture
9
+ def lst():
10
+ return [1, 2, 3, 4, 5]
11
+
12
+
13
+ @pytest.fixture
14
+ def container(lst):
15
+ return FrozenList(lst)
16
+
17
+
18
+ @pytest.fixture
19
+ def unicode_container():
20
+ return FrozenList(["\u05d0", "\u05d1", "c"])
21
+
22
+
23
+ class TestFrozenList:
24
+ def check_mutable_error(self, *args, **kwargs):
25
+ # Pass whatever function you normally would to pytest.raises
26
+ # (after the Exception kind).
27
+ mutable_regex = re.compile("does not support mutable operations")
28
+ msg = "'(_s)?re.(SRE_)?Pattern' object is not callable"
29
+ with pytest.raises(TypeError, match=msg):
30
+ mutable_regex(*args, **kwargs)
31
+
32
+ def test_no_mutable_funcs(self, container):
33
+ def setitem():
34
+ container[0] = 5
35
+
36
+ self.check_mutable_error(setitem)
37
+
38
+ def setslice():
39
+ container[1:2] = 3
40
+
41
+ self.check_mutable_error(setslice)
42
+
43
+ def delitem():
44
+ del container[0]
45
+
46
+ self.check_mutable_error(delitem)
47
+
48
+ def delslice():
49
+ del container[0:3]
50
+
51
+ self.check_mutable_error(delslice)
52
+
53
+ mutable_methods = ("extend", "pop", "remove", "insert")
54
+
55
+ for meth in mutable_methods:
56
+ self.check_mutable_error(getattr(container, meth))
57
+
58
+ def test_slicing_maintains_type(self, container, lst):
59
+ result = container[1:2]
60
+ expected = lst[1:2]
61
+ self.check_result(result, expected)
62
+
63
+ def check_result(self, result, expected):
64
+ assert isinstance(result, FrozenList)
65
+ assert result == expected
66
+
67
+ def test_string_methods_dont_fail(self, container):
68
+ repr(container)
69
+ str(container)
70
+ bytes(container)
71
+
72
+ def test_tricky_container(self, unicode_container):
73
+ repr(unicode_container)
74
+ str(unicode_container)
75
+
76
+ def test_add(self, container, lst):
77
+ result = container + (1, 2, 3)
78
+ expected = FrozenList(lst + [1, 2, 3])
79
+ self.check_result(result, expected)
80
+
81
+ result = (1, 2, 3) + container
82
+ expected = FrozenList([1, 2, 3] + lst)
83
+ self.check_result(result, expected)
84
+
85
+ def test_iadd(self, container, lst):
86
+ q = r = container
87
+
88
+ q += [5]
89
+ self.check_result(q, lst + [5])
90
+
91
+ # Other shouldn't be mutated.
92
+ self.check_result(r, lst)
93
+
94
+ def test_union(self, container, lst):
95
+ result = container.union((1, 2, 3))
96
+ expected = FrozenList(lst + [1, 2, 3])
97
+ self.check_result(result, expected)
98
+
99
+ def test_difference(self, container):
100
+ result = container.difference([2])
101
+ expected = FrozenList([1, 3, 4, 5])
102
+ self.check_result(result, expected)
103
+
104
+ def test_difference_dupe(self):
105
+ result = FrozenList([1, 2, 3, 2]).difference([2])
106
+ expected = FrozenList([1, 3])
107
+ self.check_result(result, expected)
108
+
109
+ def test_tricky_container_to_bytes_raises(self, unicode_container):
110
+ # GH 26447
111
+ msg = "^'str' object cannot be interpreted as an integer$"
112
+ with pytest.raises(TypeError, match=msg):
113
+ bytes(unicode_container)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_index_new.py ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests for the Index constructor conducting inference.
3
+ """
4
+ from datetime import (
5
+ datetime,
6
+ timedelta,
7
+ timezone,
8
+ )
9
+ from decimal import Decimal
10
+
11
+ import numpy as np
12
+ import pytest
13
+
14
+ from pandas._libs.tslibs.timezones import maybe_get_tz
15
+
16
+ from pandas import (
17
+ NA,
18
+ Categorical,
19
+ CategoricalIndex,
20
+ DatetimeIndex,
21
+ Index,
22
+ IntervalIndex,
23
+ MultiIndex,
24
+ NaT,
25
+ PeriodIndex,
26
+ Series,
27
+ TimedeltaIndex,
28
+ Timestamp,
29
+ array,
30
+ date_range,
31
+ period_range,
32
+ timedelta_range,
33
+ )
34
+ import pandas._testing as tm
35
+
36
+
37
+ class TestIndexConstructorInference:
38
+ def test_object_all_bools(self):
39
+ # GH#49594 match Series behavior on ndarray[object] of all bools
40
+ arr = np.array([True, False], dtype=object)
41
+ res = Index(arr)
42
+ assert res.dtype == object
43
+
44
+ # since the point is matching Series behavior, let's double check
45
+ assert Series(arr).dtype == object
46
+
47
+ def test_object_all_complex(self):
48
+ # GH#49594 match Series behavior on ndarray[object] of all complex
49
+ arr = np.array([complex(1), complex(2)], dtype=object)
50
+ res = Index(arr)
51
+ assert res.dtype == object
52
+
53
+ # since the point is matching Series behavior, let's double check
54
+ assert Series(arr).dtype == object
55
+
56
+ @pytest.mark.parametrize("val", [NaT, None, np.nan, float("nan")])
57
+ def test_infer_nat(self, val):
58
+ # GH#49340 all NaT/None/nan and at least 1 NaT -> datetime64[ns],
59
+ # matching Series behavior
60
+ values = [NaT, val]
61
+
62
+ idx = Index(values)
63
+ assert idx.dtype == "datetime64[ns]" and idx.isna().all()
64
+
65
+ idx = Index(values[::-1])
66
+ assert idx.dtype == "datetime64[ns]" and idx.isna().all()
67
+
68
+ idx = Index(np.array(values, dtype=object))
69
+ assert idx.dtype == "datetime64[ns]" and idx.isna().all()
70
+
71
+ idx = Index(np.array(values, dtype=object)[::-1])
72
+ assert idx.dtype == "datetime64[ns]" and idx.isna().all()
73
+
74
+ @pytest.mark.parametrize("na_value", [None, np.nan])
75
+ @pytest.mark.parametrize("vtype", [list, tuple, iter])
76
+ def test_construction_list_tuples_nan(self, na_value, vtype):
77
+ # GH#18505 : valid tuples containing NaN
78
+ values = [(1, "two"), (3.0, na_value)]
79
+ result = Index(vtype(values))
80
+ expected = MultiIndex.from_tuples(values)
81
+ tm.assert_index_equal(result, expected)
82
+
83
+ @pytest.mark.parametrize(
84
+ "dtype",
85
+ [int, "int64", "int32", "int16", "int8", "uint64", "uint32", "uint16", "uint8"],
86
+ )
87
+ def test_constructor_int_dtype_float(self, dtype):
88
+ # GH#18400
89
+ expected = Index([0, 1, 2, 3], dtype=dtype)
90
+ result = Index([0.0, 1.0, 2.0, 3.0], dtype=dtype)
91
+ tm.assert_index_equal(result, expected)
92
+
93
+ @pytest.mark.parametrize("cast_index", [True, False])
94
+ @pytest.mark.parametrize(
95
+ "vals", [[True, False, True], np.array([True, False, True], dtype=bool)]
96
+ )
97
+ def test_constructor_dtypes_to_object(self, cast_index, vals):
98
+ if cast_index:
99
+ index = Index(vals, dtype=bool)
100
+ else:
101
+ index = Index(vals)
102
+
103
+ assert type(index) is Index
104
+ assert index.dtype == bool
105
+
106
+ def test_constructor_categorical_to_object(self):
107
+ # GH#32167 Categorical data and dtype=object should return object-dtype
108
+ ci = CategoricalIndex(range(5))
109
+ result = Index(ci, dtype=object)
110
+ assert not isinstance(result, CategoricalIndex)
111
+
112
+ def test_constructor_infer_periodindex(self):
113
+ xp = period_range("2012-1-1", freq="M", periods=3)
114
+ rs = Index(xp)
115
+ tm.assert_index_equal(rs, xp)
116
+ assert isinstance(rs, PeriodIndex)
117
+
118
+ def test_from_list_of_periods(self):
119
+ rng = period_range("1/1/2000", periods=20, freq="D")
120
+ periods = list(rng)
121
+
122
+ result = Index(periods)
123
+ assert isinstance(result, PeriodIndex)
124
+
125
+ @pytest.mark.parametrize("pos", [0, 1])
126
+ @pytest.mark.parametrize(
127
+ "klass,dtype,ctor",
128
+ [
129
+ (DatetimeIndex, "datetime64[ns]", np.datetime64("nat")),
130
+ (TimedeltaIndex, "timedelta64[ns]", np.timedelta64("nat")),
131
+ ],
132
+ )
133
+ def test_constructor_infer_nat_dt_like(
134
+ self, pos, klass, dtype, ctor, nulls_fixture, request
135
+ ):
136
+ if isinstance(nulls_fixture, Decimal):
137
+ # We dont cast these to datetime64/timedelta64
138
+ pytest.skip(
139
+ f"We don't cast {type(nulls_fixture).__name__} to "
140
+ "datetime64/timedelta64"
141
+ )
142
+
143
+ expected = klass([NaT, NaT])
144
+ assert expected.dtype == dtype
145
+ data = [ctor]
146
+ data.insert(pos, nulls_fixture)
147
+
148
+ warn = None
149
+ if nulls_fixture is NA:
150
+ expected = Index([NA, NaT])
151
+ mark = pytest.mark.xfail(reason="Broken with np.NaT ctor; see GH 31884")
152
+ request.applymarker(mark)
153
+ # GH#35942 numpy will emit a DeprecationWarning within the
154
+ # assert_index_equal calls. Since we can't do anything
155
+ # about it until GH#31884 is fixed, we suppress that warning.
156
+ warn = DeprecationWarning
157
+
158
+ result = Index(data)
159
+
160
+ with tm.assert_produces_warning(warn):
161
+ tm.assert_index_equal(result, expected)
162
+
163
+ result = Index(np.array(data, dtype=object))
164
+
165
+ with tm.assert_produces_warning(warn):
166
+ tm.assert_index_equal(result, expected)
167
+
168
+ @pytest.mark.parametrize("swap_objs", [True, False])
169
+ def test_constructor_mixed_nat_objs_infers_object(self, swap_objs):
170
+ # mixed np.datetime64/timedelta64 nat results in object
171
+ data = [np.datetime64("nat"), np.timedelta64("nat")]
172
+ if swap_objs:
173
+ data = data[::-1]
174
+
175
+ expected = Index(data, dtype=object)
176
+ tm.assert_index_equal(Index(data), expected)
177
+ tm.assert_index_equal(Index(np.array(data, dtype=object)), expected)
178
+
179
+ @pytest.mark.parametrize("swap_objs", [True, False])
180
+ def test_constructor_datetime_and_datetime64(self, swap_objs):
181
+ data = [Timestamp(2021, 6, 8, 9, 42), np.datetime64("now")]
182
+ if swap_objs:
183
+ data = data[::-1]
184
+ expected = DatetimeIndex(data)
185
+
186
+ tm.assert_index_equal(Index(data), expected)
187
+ tm.assert_index_equal(Index(np.array(data, dtype=object)), expected)
188
+
189
+ def test_constructor_datetimes_mixed_tzs(self):
190
+ # https://github.com/pandas-dev/pandas/pull/55793/files#r1383719998
191
+ tz = maybe_get_tz("US/Central")
192
+ dt1 = datetime(2020, 1, 1, tzinfo=tz)
193
+ dt2 = datetime(2020, 1, 1, tzinfo=timezone.utc)
194
+ result = Index([dt1, dt2])
195
+ expected = Index([dt1, dt2], dtype=object)
196
+ tm.assert_index_equal(result, expected)
197
+
198
+
199
+ class TestDtypeEnforced:
200
+ # check we don't silently ignore the dtype keyword
201
+
202
+ def test_constructor_object_dtype_with_ea_data(self, any_numeric_ea_dtype):
203
+ # GH#45206
204
+ arr = array([0], dtype=any_numeric_ea_dtype)
205
+
206
+ idx = Index(arr, dtype=object)
207
+ assert idx.dtype == object
208
+
209
+ @pytest.mark.parametrize("dtype", [object, "float64", "uint64", "category"])
210
+ def test_constructor_range_values_mismatched_dtype(self, dtype):
211
+ rng = Index(range(5))
212
+
213
+ result = Index(rng, dtype=dtype)
214
+ assert result.dtype == dtype
215
+
216
+ result = Index(range(5), dtype=dtype)
217
+ assert result.dtype == dtype
218
+
219
+ @pytest.mark.parametrize("dtype", [object, "float64", "uint64", "category"])
220
+ def test_constructor_categorical_values_mismatched_non_ea_dtype(self, dtype):
221
+ cat = Categorical([1, 2, 3])
222
+
223
+ result = Index(cat, dtype=dtype)
224
+ assert result.dtype == dtype
225
+
226
+ def test_constructor_categorical_values_mismatched_dtype(self):
227
+ dti = date_range("2016-01-01", periods=3)
228
+ cat = Categorical(dti)
229
+ result = Index(cat, dti.dtype)
230
+ tm.assert_index_equal(result, dti)
231
+
232
+ dti2 = dti.tz_localize("Asia/Tokyo")
233
+ cat2 = Categorical(dti2)
234
+ result = Index(cat2, dti2.dtype)
235
+ tm.assert_index_equal(result, dti2)
236
+
237
+ ii = IntervalIndex.from_breaks(range(5))
238
+ cat3 = Categorical(ii)
239
+ result = Index(cat3, dtype=ii.dtype)
240
+ tm.assert_index_equal(result, ii)
241
+
242
+ def test_constructor_ea_values_mismatched_categorical_dtype(self):
243
+ dti = date_range("2016-01-01", periods=3)
244
+ result = Index(dti, dtype="category")
245
+ expected = CategoricalIndex(dti)
246
+ tm.assert_index_equal(result, expected)
247
+
248
+ dti2 = date_range("2016-01-01", periods=3, tz="US/Pacific")
249
+ result = Index(dti2, dtype="category")
250
+ expected = CategoricalIndex(dti2)
251
+ tm.assert_index_equal(result, expected)
252
+
253
+ def test_constructor_period_values_mismatched_dtype(self):
254
+ pi = period_range("2016-01-01", periods=3, freq="D")
255
+ result = Index(pi, dtype="category")
256
+ expected = CategoricalIndex(pi)
257
+ tm.assert_index_equal(result, expected)
258
+
259
+ def test_constructor_timedelta64_values_mismatched_dtype(self):
260
+ # check we don't silently ignore the dtype keyword
261
+ tdi = timedelta_range("4 Days", periods=5)
262
+ result = Index(tdi, dtype="category")
263
+ expected = CategoricalIndex(tdi)
264
+ tm.assert_index_equal(result, expected)
265
+
266
+ def test_constructor_interval_values_mismatched_dtype(self):
267
+ dti = date_range("2016-01-01", periods=3)
268
+ ii = IntervalIndex.from_breaks(dti)
269
+ result = Index(ii, dtype="category")
270
+ expected = CategoricalIndex(ii)
271
+ tm.assert_index_equal(result, expected)
272
+
273
+ def test_constructor_datetime64_values_mismatched_period_dtype(self):
274
+ dti = date_range("2016-01-01", periods=3)
275
+ result = Index(dti, dtype="Period[D]")
276
+ expected = dti.to_period("D")
277
+ tm.assert_index_equal(result, expected)
278
+
279
+ @pytest.mark.parametrize("dtype", ["int64", "uint64"])
280
+ def test_constructor_int_dtype_nan_raises(self, dtype):
281
+ # see GH#15187
282
+ data = [np.nan]
283
+ msg = "cannot convert"
284
+ with pytest.raises(ValueError, match=msg):
285
+ Index(data, dtype=dtype)
286
+
287
+ @pytest.mark.parametrize(
288
+ "vals",
289
+ [
290
+ [1, 2, 3],
291
+ np.array([1, 2, 3]),
292
+ np.array([1, 2, 3], dtype=int),
293
+ # below should coerce
294
+ [1.0, 2.0, 3.0],
295
+ np.array([1.0, 2.0, 3.0], dtype=float),
296
+ ],
297
+ )
298
+ def test_constructor_dtypes_to_int(self, vals, any_int_numpy_dtype):
299
+ dtype = any_int_numpy_dtype
300
+ index = Index(vals, dtype=dtype)
301
+ assert index.dtype == dtype
302
+
303
+ @pytest.mark.parametrize(
304
+ "vals",
305
+ [
306
+ [1, 2, 3],
307
+ [1.0, 2.0, 3.0],
308
+ np.array([1.0, 2.0, 3.0]),
309
+ np.array([1, 2, 3], dtype=int),
310
+ np.array([1.0, 2.0, 3.0], dtype=float),
311
+ ],
312
+ )
313
+ def test_constructor_dtypes_to_float(self, vals, float_numpy_dtype):
314
+ dtype = float_numpy_dtype
315
+ index = Index(vals, dtype=dtype)
316
+ assert index.dtype == dtype
317
+
318
+ @pytest.mark.parametrize(
319
+ "vals",
320
+ [
321
+ [1, 2, 3],
322
+ np.array([1, 2, 3], dtype=int),
323
+ np.array(["2011-01-01", "2011-01-02"], dtype="datetime64[ns]"),
324
+ [datetime(2011, 1, 1), datetime(2011, 1, 2)],
325
+ ],
326
+ )
327
+ def test_constructor_dtypes_to_categorical(self, vals):
328
+ index = Index(vals, dtype="category")
329
+ assert isinstance(index, CategoricalIndex)
330
+
331
+ @pytest.mark.parametrize("cast_index", [True, False])
332
+ @pytest.mark.parametrize(
333
+ "vals",
334
+ [
335
+ Index(np.array([np.datetime64("2011-01-01"), np.datetime64("2011-01-02")])),
336
+ Index([datetime(2011, 1, 1), datetime(2011, 1, 2)]),
337
+ ],
338
+ )
339
+ def test_constructor_dtypes_to_datetime(self, cast_index, vals):
340
+ if cast_index:
341
+ index = Index(vals, dtype=object)
342
+ assert isinstance(index, Index)
343
+ assert index.dtype == object
344
+ else:
345
+ index = Index(vals)
346
+ assert isinstance(index, DatetimeIndex)
347
+
348
+ @pytest.mark.parametrize("cast_index", [True, False])
349
+ @pytest.mark.parametrize(
350
+ "vals",
351
+ [
352
+ np.array([np.timedelta64(1, "D"), np.timedelta64(1, "D")]),
353
+ [timedelta(1), timedelta(1)],
354
+ ],
355
+ )
356
+ def test_constructor_dtypes_to_timedelta(self, cast_index, vals):
357
+ if cast_index:
358
+ index = Index(vals, dtype=object)
359
+ assert isinstance(index, Index)
360
+ assert index.dtype == object
361
+ else:
362
+ index = Index(vals)
363
+ assert isinstance(index, TimedeltaIndex)
364
+
365
+ def test_pass_timedeltaindex_to_index(self):
366
+ rng = timedelta_range("1 days", "10 days")
367
+ idx = Index(rng, dtype=object)
368
+
369
+ expected = Index(rng.to_pytimedelta(), dtype=object)
370
+
371
+ tm.assert_numpy_array_equal(idx.values, expected.values)
372
+
373
+ def test_pass_datetimeindex_to_index(self):
374
+ # GH#1396
375
+ rng = date_range("1/1/2000", "3/1/2000")
376
+ idx = Index(rng, dtype=object)
377
+
378
+ expected = Index(rng.to_pydatetime(), dtype=object)
379
+
380
+ tm.assert_numpy_array_equal(idx.values, expected.values)
381
+
382
+
383
+ class TestIndexConstructorUnwrapping:
384
+ # Test passing different arraylike values to pd.Index
385
+
386
+ @pytest.mark.parametrize("klass", [Index, DatetimeIndex])
387
+ def test_constructor_from_series_dt64(self, klass):
388
+ stamps = [Timestamp("20110101"), Timestamp("20120101"), Timestamp("20130101")]
389
+ expected = DatetimeIndex(stamps)
390
+ ser = Series(stamps)
391
+ result = klass(ser)
392
+ tm.assert_index_equal(result, expected)
393
+
394
+ def test_constructor_no_pandas_array(self):
395
+ ser = Series([1, 2, 3])
396
+ result = Index(ser.array)
397
+ expected = Index([1, 2, 3])
398
+ tm.assert_index_equal(result, expected)
399
+
400
+ @pytest.mark.parametrize(
401
+ "array",
402
+ [
403
+ np.arange(5),
404
+ np.array(["a", "b", "c"]),
405
+ date_range("2000-01-01", periods=3).values,
406
+ ],
407
+ )
408
+ def test_constructor_ndarray_like(self, array):
409
+ # GH#5460#issuecomment-44474502
410
+ # it should be possible to convert any object that satisfies the numpy
411
+ # ndarray interface directly into an Index
412
+ class ArrayLike:
413
+ def __init__(self, array) -> None:
414
+ self.array = array
415
+
416
+ def __array__(self, dtype=None, copy=None) -> np.ndarray:
417
+ return self.array
418
+
419
+ expected = Index(array)
420
+ result = Index(ArrayLike(array))
421
+ tm.assert_index_equal(result, expected)
422
+
423
+
424
+ class TestIndexConstructionErrors:
425
+ def test_constructor_overflow_int64(self):
426
+ # see GH#15832
427
+ msg = (
428
+ "The elements provided in the data cannot "
429
+ "all be casted to the dtype int64"
430
+ )
431
+ with pytest.raises(OverflowError, match=msg):
432
+ Index([np.iinfo(np.uint64).max - 1], dtype="int64")
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_numpy_compat.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ CategoricalIndex,
6
+ DatetimeIndex,
7
+ Index,
8
+ PeriodIndex,
9
+ TimedeltaIndex,
10
+ isna,
11
+ )
12
+ import pandas._testing as tm
13
+ from pandas.api.types import (
14
+ is_complex_dtype,
15
+ is_numeric_dtype,
16
+ )
17
+ from pandas.core.arrays import BooleanArray
18
+ from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
19
+
20
+
21
+ def test_numpy_ufuncs_out(index):
22
+ result = index == index
23
+
24
+ out = np.empty(index.shape, dtype=bool)
25
+ np.equal(index, index, out=out)
26
+ tm.assert_numpy_array_equal(out, result)
27
+
28
+ if not index._is_multi:
29
+ # same thing on the ExtensionArray
30
+ out = np.empty(index.shape, dtype=bool)
31
+ np.equal(index.array, index.array, out=out)
32
+ tm.assert_numpy_array_equal(out, result)
33
+
34
+
35
+ @pytest.mark.parametrize(
36
+ "func",
37
+ [
38
+ np.exp,
39
+ np.exp2,
40
+ np.expm1,
41
+ np.log,
42
+ np.log2,
43
+ np.log10,
44
+ np.log1p,
45
+ np.sqrt,
46
+ np.sin,
47
+ np.cos,
48
+ np.tan,
49
+ np.arcsin,
50
+ np.arccos,
51
+ np.arctan,
52
+ np.sinh,
53
+ np.cosh,
54
+ np.tanh,
55
+ np.arcsinh,
56
+ np.arccosh,
57
+ np.arctanh,
58
+ np.deg2rad,
59
+ np.rad2deg,
60
+ ],
61
+ ids=lambda x: x.__name__,
62
+ )
63
+ def test_numpy_ufuncs_basic(index, func):
64
+ # test ufuncs of numpy, see:
65
+ # https://numpy.org/doc/stable/reference/ufuncs.html
66
+
67
+ if isinstance(index, DatetimeIndexOpsMixin):
68
+ with tm.external_error_raised((TypeError, AttributeError)):
69
+ with np.errstate(all="ignore"):
70
+ func(index)
71
+ elif is_numeric_dtype(index) and not (
72
+ is_complex_dtype(index) and func in [np.deg2rad, np.rad2deg]
73
+ ):
74
+ # coerces to float (e.g. np.sin)
75
+ with np.errstate(all="ignore"):
76
+ result = func(index)
77
+ arr_result = func(index.values)
78
+ if arr_result.dtype == np.float16:
79
+ arr_result = arr_result.astype(np.float32)
80
+ exp = Index(arr_result, name=index.name)
81
+
82
+ tm.assert_index_equal(result, exp)
83
+ if isinstance(index.dtype, np.dtype) and is_numeric_dtype(index):
84
+ if is_complex_dtype(index):
85
+ assert result.dtype == index.dtype
86
+ elif index.dtype in ["bool", "int8", "uint8"]:
87
+ assert result.dtype in ["float16", "float32"]
88
+ elif index.dtype in ["int16", "uint16", "float32"]:
89
+ assert result.dtype == "float32"
90
+ else:
91
+ assert result.dtype == "float64"
92
+ else:
93
+ # e.g. np.exp with Int64 -> Float64
94
+ assert type(result) is Index
95
+ # raise AttributeError or TypeError
96
+ elif len(index) == 0:
97
+ pass
98
+ else:
99
+ with tm.external_error_raised((TypeError, AttributeError)):
100
+ with np.errstate(all="ignore"):
101
+ func(index)
102
+
103
+
104
+ @pytest.mark.parametrize(
105
+ "func", [np.isfinite, np.isinf, np.isnan, np.signbit], ids=lambda x: x.__name__
106
+ )
107
+ def test_numpy_ufuncs_other(index, func):
108
+ # test ufuncs of numpy, see:
109
+ # https://numpy.org/doc/stable/reference/ufuncs.html
110
+ if isinstance(index, (DatetimeIndex, TimedeltaIndex)):
111
+ if func in (np.isfinite, np.isinf, np.isnan):
112
+ # numpy 1.18 changed isinf and isnan to not raise on dt64/td64
113
+ result = func(index)
114
+ assert isinstance(result, np.ndarray)
115
+
116
+ out = np.empty(index.shape, dtype=bool)
117
+ func(index, out=out)
118
+ tm.assert_numpy_array_equal(out, result)
119
+ else:
120
+ with tm.external_error_raised(TypeError):
121
+ func(index)
122
+
123
+ elif isinstance(index, PeriodIndex):
124
+ with tm.external_error_raised(TypeError):
125
+ func(index)
126
+
127
+ elif is_numeric_dtype(index) and not (
128
+ is_complex_dtype(index) and func is np.signbit
129
+ ):
130
+ # Results in bool array
131
+ result = func(index)
132
+ if not isinstance(index.dtype, np.dtype):
133
+ # e.g. Int64 we expect to get BooleanArray back
134
+ assert isinstance(result, BooleanArray)
135
+ else:
136
+ assert isinstance(result, np.ndarray)
137
+
138
+ out = np.empty(index.shape, dtype=bool)
139
+ func(index, out=out)
140
+
141
+ if not isinstance(index.dtype, np.dtype):
142
+ tm.assert_numpy_array_equal(out, result._data)
143
+ else:
144
+ tm.assert_numpy_array_equal(out, result)
145
+
146
+ elif len(index) == 0:
147
+ pass
148
+ else:
149
+ with tm.external_error_raised(TypeError):
150
+ func(index)
151
+
152
+
153
+ @pytest.mark.parametrize("func", [np.maximum, np.minimum])
154
+ def test_numpy_ufuncs_reductions(index, func, request):
155
+ # TODO: overlap with tests.series.test_ufunc.test_reductions
156
+ if len(index) == 0:
157
+ pytest.skip("Test doesn't make sense for empty index.")
158
+
159
+ if isinstance(index, CategoricalIndex) and index.dtype.ordered is False:
160
+ with pytest.raises(TypeError, match="is not ordered for"):
161
+ func.reduce(index)
162
+ return
163
+ else:
164
+ result = func.reduce(index)
165
+
166
+ if func is np.maximum:
167
+ expected = index.max(skipna=False)
168
+ else:
169
+ expected = index.min(skipna=False)
170
+ # TODO: do we have cases both with and without NAs?
171
+
172
+ assert type(result) is type(expected)
173
+ if isna(result):
174
+ assert isna(expected)
175
+ else:
176
+ assert result == expected
177
+
178
+
179
+ @pytest.mark.parametrize("func", [np.bitwise_and, np.bitwise_or, np.bitwise_xor])
180
+ def test_numpy_ufuncs_bitwise(func):
181
+ # https://github.com/pandas-dev/pandas/issues/46769
182
+ idx1 = Index([1, 2, 3, 4], dtype="int64")
183
+ idx2 = Index([3, 4, 5, 6], dtype="int64")
184
+
185
+ with tm.assert_produces_warning(None):
186
+ result = func(idx1, idx2)
187
+
188
+ expected = Index(func(idx1.values, idx2.values))
189
+ tm.assert_index_equal(result, expected)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/test_subclass.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests involving custom Index subclasses
3
+ """
4
+ import numpy as np
5
+
6
+ from pandas import (
7
+ DataFrame,
8
+ Index,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class CustomIndex(Index):
14
+ def __new__(cls, data, name=None):
15
+ # assert that this index class cannot hold strings
16
+ if any(isinstance(val, str) for val in data):
17
+ raise TypeError("CustomIndex cannot hold strings")
18
+
19
+ if name is None and hasattr(data, "name"):
20
+ name = data.name
21
+ data = np.array(data, dtype="O")
22
+
23
+ return cls._simple_new(data, name)
24
+
25
+
26
+ def test_insert_fallback_to_base_index():
27
+ # https://github.com/pandas-dev/pandas/issues/47071
28
+
29
+ idx = CustomIndex([1, 2, 3])
30
+ result = idx.insert(0, "string")
31
+ expected = Index(["string", 1, 2, 3], dtype=object)
32
+ tm.assert_index_equal(result, expected)
33
+
34
+ df = DataFrame(
35
+ np.random.default_rng(2).standard_normal((2, 3)),
36
+ columns=idx,
37
+ index=Index([1, 2], name="string"),
38
+ )
39
+ result = df.reset_index()
40
+ tm.assert_index_equal(result.columns, expected)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/__init__.py ADDED
File without changes
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_join.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from pandas import (
4
+ DataFrame,
5
+ Index,
6
+ Timedelta,
7
+ timedelta_range,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ class TestJoin:
13
+ def test_append_join_nondatetimeindex(self):
14
+ rng = timedelta_range("1 days", periods=10)
15
+ idx = Index(["a", "b", "c", "d"])
16
+
17
+ result = rng.append(idx)
18
+ assert isinstance(result[0], Timedelta)
19
+
20
+ # it works
21
+ rng.join(idx, how="outer")
22
+
23
+ def test_join_self(self, join_type):
24
+ index = timedelta_range("1 day", periods=10)
25
+ joined = index.join(index, how=join_type)
26
+ tm.assert_index_equal(index, joined)
27
+
28
+ def test_does_not_convert_mixed_integer(self):
29
+ df = DataFrame(np.ones((5, 5)), columns=timedelta_range("1 day", periods=5))
30
+
31
+ cols = df.columns.join(df.index, how="outer")
32
+ joined = cols.join(df.columns)
33
+ assert cols.dtype == np.dtype("O")
34
+ assert cols.dtype == joined.dtype
35
+ tm.assert_index_equal(cols, joined)
36
+
37
+ def test_join_preserves_freq(self):
38
+ # GH#32157
39
+ tdi = timedelta_range("1 day", periods=10)
40
+ result = tdi[:5].join(tdi[5:], how="outer")
41
+ assert result.freq == tdi.freq
42
+ tm.assert_index_equal(result, tdi)
43
+
44
+ result = tdi[:5].join(tdi[6:], how="outer")
45
+ assert result.freq is None
46
+ expected = tdi.delete(5)
47
+ tm.assert_index_equal(result, expected)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_ops.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pandas import (
2
+ TimedeltaIndex,
3
+ timedelta_range,
4
+ )
5
+ import pandas._testing as tm
6
+
7
+
8
+ class TestTimedeltaIndexOps:
9
+ def test_infer_freq(self, freq_sample):
10
+ # GH#11018
11
+ idx = timedelta_range("1", freq=freq_sample, periods=10)
12
+ result = TimedeltaIndex(idx.asi8, freq="infer")
13
+ tm.assert_index_equal(idx, result)
14
+ assert result.freq == freq_sample
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_setops.py ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Index,
7
+ TimedeltaIndex,
8
+ timedelta_range,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+ from pandas.tseries.offsets import Hour
13
+
14
+
15
+ class TestTimedeltaIndex:
16
+ def test_union(self):
17
+ i1 = timedelta_range("1day", periods=5)
18
+ i2 = timedelta_range("3day", periods=5)
19
+ result = i1.union(i2)
20
+ expected = timedelta_range("1day", periods=7)
21
+ tm.assert_index_equal(result, expected)
22
+
23
+ i1 = Index(np.arange(0, 20, 2, dtype=np.int64))
24
+ i2 = timedelta_range(start="1 day", periods=10, freq="D")
25
+ i1.union(i2) # Works
26
+ i2.union(i1) # Fails with "AttributeError: can't set attribute"
27
+
28
+ def test_union_sort_false(self):
29
+ tdi = timedelta_range("1day", periods=5)
30
+
31
+ left = tdi[3:]
32
+ right = tdi[:3]
33
+
34
+ # Check that we are testing the desired code path
35
+ assert left._can_fast_union(right)
36
+
37
+ result = left.union(right)
38
+ tm.assert_index_equal(result, tdi)
39
+
40
+ result = left.union(right, sort=False)
41
+ expected = TimedeltaIndex(["4 Days", "5 Days", "1 Days", "2 Day", "3 Days"])
42
+ tm.assert_index_equal(result, expected)
43
+
44
+ def test_union_coverage(self):
45
+ idx = TimedeltaIndex(["3d", "1d", "2d"])
46
+ ordered = TimedeltaIndex(idx.sort_values(), freq="infer")
47
+ result = ordered.union(idx)
48
+ tm.assert_index_equal(result, ordered)
49
+
50
+ result = ordered[:0].union(ordered)
51
+ tm.assert_index_equal(result, ordered)
52
+ assert result.freq == ordered.freq
53
+
54
+ def test_union_bug_1730(self):
55
+ rng_a = timedelta_range("1 day", periods=4, freq="3h")
56
+ rng_b = timedelta_range("1 day", periods=4, freq="4h")
57
+
58
+ result = rng_a.union(rng_b)
59
+ exp = TimedeltaIndex(sorted(set(rng_a) | set(rng_b)))
60
+ tm.assert_index_equal(result, exp)
61
+
62
+ def test_union_bug_1745(self):
63
+ left = TimedeltaIndex(["1 day 15:19:49.695000"])
64
+ right = TimedeltaIndex(
65
+ ["2 day 13:04:21.322000", "1 day 15:27:24.873000", "1 day 15:31:05.350000"]
66
+ )
67
+
68
+ result = left.union(right)
69
+ exp = TimedeltaIndex(sorted(set(left) | set(right)))
70
+ tm.assert_index_equal(result, exp)
71
+
72
+ def test_union_bug_4564(self):
73
+ left = timedelta_range("1 day", "30d")
74
+ right = left + pd.offsets.Minute(15)
75
+
76
+ result = left.union(right)
77
+ exp = TimedeltaIndex(sorted(set(left) | set(right)))
78
+ tm.assert_index_equal(result, exp)
79
+
80
+ def test_union_freq_infer(self):
81
+ # When taking the union of two TimedeltaIndexes, we infer
82
+ # a freq even if the arguments don't have freq. This matches
83
+ # DatetimeIndex behavior.
84
+ tdi = timedelta_range("1 Day", periods=5)
85
+ left = tdi[[0, 1, 3, 4]]
86
+ right = tdi[[2, 3, 1]]
87
+
88
+ assert left.freq is None
89
+ assert right.freq is None
90
+
91
+ result = left.union(right)
92
+ tm.assert_index_equal(result, tdi)
93
+ assert result.freq == "D"
94
+
95
+ def test_intersection_bug_1708(self):
96
+ index_1 = timedelta_range("1 day", periods=4, freq="h")
97
+ index_2 = index_1 + pd.offsets.Hour(5)
98
+
99
+ result = index_1.intersection(index_2)
100
+ assert len(result) == 0
101
+
102
+ index_1 = timedelta_range("1 day", periods=4, freq="h")
103
+ index_2 = index_1 + pd.offsets.Hour(1)
104
+
105
+ result = index_1.intersection(index_2)
106
+ expected = timedelta_range("1 day 01:00:00", periods=3, freq="h")
107
+ tm.assert_index_equal(result, expected)
108
+ assert result.freq == expected.freq
109
+
110
+ def test_intersection_equal(self, sort):
111
+ # GH 24471 Test intersection outcome given the sort keyword
112
+ # for equal indices intersection should return the original index
113
+ first = timedelta_range("1 day", periods=4, freq="h")
114
+ second = timedelta_range("1 day", periods=4, freq="h")
115
+ intersect = first.intersection(second, sort=sort)
116
+ if sort is None:
117
+ tm.assert_index_equal(intersect, second.sort_values())
118
+ tm.assert_index_equal(intersect, second)
119
+
120
+ # Corner cases
121
+ inter = first.intersection(first, sort=sort)
122
+ assert inter is first
123
+
124
+ @pytest.mark.parametrize("period_1, period_2", [(0, 4), (4, 0)])
125
+ def test_intersection_zero_length(self, period_1, period_2, sort):
126
+ # GH 24471 test for non overlap the intersection should be zero length
127
+ index_1 = timedelta_range("1 day", periods=period_1, freq="h")
128
+ index_2 = timedelta_range("1 day", periods=period_2, freq="h")
129
+ expected = timedelta_range("1 day", periods=0, freq="h")
130
+ result = index_1.intersection(index_2, sort=sort)
131
+ tm.assert_index_equal(result, expected)
132
+
133
+ def test_zero_length_input_index(self, sort):
134
+ # GH 24966 test for 0-len intersections are copied
135
+ index_1 = timedelta_range("1 day", periods=0, freq="h")
136
+ index_2 = timedelta_range("1 day", periods=3, freq="h")
137
+ result = index_1.intersection(index_2, sort=sort)
138
+ assert index_1 is not result
139
+ assert index_2 is not result
140
+ tm.assert_copy(result, index_1)
141
+
142
+ @pytest.mark.parametrize(
143
+ "rng, expected",
144
+ # if target has the same name, it is preserved
145
+ [
146
+ (
147
+ timedelta_range("1 day", periods=5, freq="h", name="idx"),
148
+ timedelta_range("1 day", periods=4, freq="h", name="idx"),
149
+ ),
150
+ # if target name is different, it will be reset
151
+ (
152
+ timedelta_range("1 day", periods=5, freq="h", name="other"),
153
+ timedelta_range("1 day", periods=4, freq="h", name=None),
154
+ ),
155
+ # if no overlap exists return empty index
156
+ (
157
+ timedelta_range("1 day", periods=10, freq="h", name="idx")[5:],
158
+ TimedeltaIndex([], freq="h", name="idx"),
159
+ ),
160
+ ],
161
+ )
162
+ def test_intersection(self, rng, expected, sort):
163
+ # GH 4690 (with tz)
164
+ base = timedelta_range("1 day", periods=4, freq="h", name="idx")
165
+ result = base.intersection(rng, sort=sort)
166
+ if sort is None:
167
+ expected = expected.sort_values()
168
+ tm.assert_index_equal(result, expected)
169
+ assert result.name == expected.name
170
+ assert result.freq == expected.freq
171
+
172
+ @pytest.mark.parametrize(
173
+ "rng, expected",
174
+ # part intersection works
175
+ [
176
+ (
177
+ TimedeltaIndex(["5 hour", "2 hour", "4 hour", "9 hour"], name="idx"),
178
+ TimedeltaIndex(["2 hour", "4 hour"], name="idx"),
179
+ ),
180
+ # reordered part intersection
181
+ (
182
+ TimedeltaIndex(["2 hour", "5 hour", "5 hour", "1 hour"], name="other"),
183
+ TimedeltaIndex(["1 hour", "2 hour"], name=None),
184
+ ),
185
+ # reversed index
186
+ (
187
+ TimedeltaIndex(["1 hour", "2 hour", "4 hour", "3 hour"], name="idx")[
188
+ ::-1
189
+ ],
190
+ TimedeltaIndex(["1 hour", "2 hour", "4 hour", "3 hour"], name="idx"),
191
+ ),
192
+ ],
193
+ )
194
+ def test_intersection_non_monotonic(self, rng, expected, sort):
195
+ # 24471 non-monotonic
196
+ base = TimedeltaIndex(["1 hour", "2 hour", "4 hour", "3 hour"], name="idx")
197
+ result = base.intersection(rng, sort=sort)
198
+ if sort is None:
199
+ expected = expected.sort_values()
200
+ tm.assert_index_equal(result, expected)
201
+ assert result.name == expected.name
202
+
203
+ # if reversed order, frequency is still the same
204
+ if all(base == rng[::-1]) and sort is None:
205
+ assert isinstance(result.freq, Hour)
206
+ else:
207
+ assert result.freq is None
208
+
209
+
210
+ class TestTimedeltaIndexDifference:
211
+ def test_difference_freq(self, sort):
212
+ # GH14323: Difference of TimedeltaIndex should not preserve frequency
213
+
214
+ index = timedelta_range("0 days", "5 days", freq="D")
215
+
216
+ other = timedelta_range("1 days", "4 days", freq="D")
217
+ expected = TimedeltaIndex(["0 days", "5 days"], freq=None)
218
+ idx_diff = index.difference(other, sort)
219
+ tm.assert_index_equal(idx_diff, expected)
220
+ tm.assert_attr_equal("freq", idx_diff, expected)
221
+
222
+ # preserve frequency when the difference is a contiguous
223
+ # subset of the original range
224
+ other = timedelta_range("2 days", "5 days", freq="D")
225
+ idx_diff = index.difference(other, sort)
226
+ expected = TimedeltaIndex(["0 days", "1 days"], freq="D")
227
+ tm.assert_index_equal(idx_diff, expected)
228
+ tm.assert_attr_equal("freq", idx_diff, expected)
229
+
230
+ def test_difference_sort(self, sort):
231
+ index = TimedeltaIndex(
232
+ ["5 days", "3 days", "2 days", "4 days", "1 days", "0 days"]
233
+ )
234
+
235
+ other = timedelta_range("1 days", "4 days", freq="D")
236
+ idx_diff = index.difference(other, sort)
237
+
238
+ expected = TimedeltaIndex(["5 days", "0 days"], freq=None)
239
+
240
+ if sort is None:
241
+ expected = expected.sort_values()
242
+
243
+ tm.assert_index_equal(idx_diff, expected)
244
+ tm.assert_attr_equal("freq", idx_diff, expected)
245
+
246
+ other = timedelta_range("2 days", "5 days", freq="D")
247
+ idx_diff = index.difference(other, sort)
248
+ expected = TimedeltaIndex(["1 days", "0 days"], freq=None)
249
+
250
+ if sort is None:
251
+ expected = expected.sort_values()
252
+
253
+ tm.assert_index_equal(idx_diff, expected)
254
+ tm.assert_attr_equal("freq", idx_diff, expected)
mplug_owl2/lib/python3.10/site-packages/pandas/tests/indexes/timedeltas/test_timedelta.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Index,
6
+ Series,
7
+ Timedelta,
8
+ timedelta_range,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestTimedeltaIndex:
14
+ def test_misc_coverage(self):
15
+ rng = timedelta_range("1 day", periods=5)
16
+ result = rng.groupby(rng.days)
17
+ assert isinstance(next(iter(result.values()))[0], Timedelta)
18
+
19
+ def test_map(self):
20
+ # test_map_dictlike generally tests
21
+
22
+ rng = timedelta_range("1 day", periods=10)
23
+
24
+ f = lambda x: x.days
25
+ result = rng.map(f)
26
+ exp = Index([f(x) for x in rng], dtype=np.int64)
27
+ tm.assert_index_equal(result, exp)
28
+
29
+ def test_fields(self):
30
+ rng = timedelta_range("1 days, 10:11:12.100123456", periods=2, freq="s")
31
+ tm.assert_index_equal(rng.days, Index([1, 1], dtype=np.int64))
32
+ tm.assert_index_equal(
33
+ rng.seconds,
34
+ Index([10 * 3600 + 11 * 60 + 12, 10 * 3600 + 11 * 60 + 13], dtype=np.int32),
35
+ )
36
+ tm.assert_index_equal(
37
+ rng.microseconds,
38
+ Index([100 * 1000 + 123, 100 * 1000 + 123], dtype=np.int32),
39
+ )
40
+ tm.assert_index_equal(rng.nanoseconds, Index([456, 456], dtype=np.int32))
41
+
42
+ msg = "'TimedeltaIndex' object has no attribute '{}'"
43
+ with pytest.raises(AttributeError, match=msg.format("hours")):
44
+ rng.hours
45
+ with pytest.raises(AttributeError, match=msg.format("minutes")):
46
+ rng.minutes
47
+ with pytest.raises(AttributeError, match=msg.format("milliseconds")):
48
+ rng.milliseconds
49
+
50
+ # with nat
51
+ s = Series(rng)
52
+ s[1] = np.nan
53
+
54
+ tm.assert_series_equal(s.dt.days, Series([1, np.nan], index=[0, 1]))
55
+ tm.assert_series_equal(
56
+ s.dt.seconds, Series([10 * 3600 + 11 * 60 + 12, np.nan], index=[0, 1])
57
+ )
58
+
59
+ # preserve name (GH15589)
60
+ rng.name = "name"
61
+ assert rng.days.name == "name"
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/BUILD_SHARED_LIBS.rst ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BUILD_SHARED_LIBS
2
+ -----------------
3
+
4
+ Tell :command:`add_library` to default to ``SHARED`` libraries,
5
+ instead of ``STATIC`` libraries, when called with no explicit library type.
6
+
7
+ Calls to :command:`add_library` without any explicit library type check
8
+ the current ``BUILD_SHARED_LIBS`` variable value. If it is true, then the
9
+ default library type is ``SHARED``. Otherwise, the default is ``STATIC``.
10
+
11
+ For example, the code:
12
+
13
+ .. code-block:: cmake
14
+
15
+ add_library(example ${sources})
16
+
17
+ behaves as if written
18
+
19
+ .. code-block:: cmake
20
+
21
+ if(BUILD_SHARED_LIBS)
22
+ add_library(example SHARED ${sources})
23
+ else()
24
+ add_library(example STATIC ${sources})
25
+ endif()
26
+
27
+ CMake does not define ``BUILD_SHARED_LIBS`` by default, but projects
28
+ often create a cache entry for it using the :command:`option` command:
29
+
30
+ .. code-block:: cmake
31
+
32
+ option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
33
+
34
+ This provides a switch that users can control, e.g., with :option:`cmake -D`.
35
+ If adding such an option to the project, do so in the top level
36
+ ``CMakeLists.txt`` file, before any :command:`add_library` calls.
37
+ Note that if bringing external dependencies directly into the build, such as
38
+ with :module:`FetchContent` or a direct call to :command:`add_subdirectory`,
39
+ and one of those dependencies has such a call to
40
+ :command:`option(BUILD_SHARED_LIBS ...) <option>`, the top level project must
41
+ also call :command:`option(BUILD_SHARED_LIBS ...) <option>` before bringing in
42
+ its dependencies. Failure to do so can lead to different behavior between the
43
+ first and subsequent CMake runs.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_ANDROID_JAVA_SOURCE_DIR.rst ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ CMAKE_ANDROID_JAVA_SOURCE_DIR
2
+ -----------------------------
3
+
4
+ .. versionadded:: 3.4
5
+
6
+ Default value for the :prop_tgt:`ANDROID_JAVA_SOURCE_DIR` target property.
7
+ See that target property for additional information.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_ANDROID_NDK_DEPRECATED_HEADERS.rst ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_ANDROID_NDK_DEPRECATED_HEADERS
2
+ ------------------------------------
3
+
4
+ .. versionadded:: 3.9
5
+
6
+ When :ref:`Cross Compiling for Android with the NDK`, this variable
7
+ may be set to specify whether to use the deprecated per-api-level
8
+ headers instead of the unified headers.
9
+
10
+ If not specified, the default will be *false* if using a NDK version
11
+ that provides the unified headers and *true* otherwise.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_AUTOMOC_COMPILER_PREDEFINES.rst ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_AUTOMOC_COMPILER_PREDEFINES
2
+ ---------------------------------
3
+
4
+ .. versionadded:: 3.10
5
+
6
+ This variable is used to initialize the :prop_tgt:`AUTOMOC_COMPILER_PREDEFINES`
7
+ property on all the targets. See that target property for additional
8
+ information.
9
+
10
+ By default it is ON.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_AUTOMOC_PATH_PREFIX.rst ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_AUTOMOC_PATH_PREFIX
2
+ -------------------------
3
+
4
+ .. versionadded:: 3.16
5
+
6
+ Whether to generate the ``-p`` path prefix option for ``moc`` on
7
+ :prop_tgt:`AUTOMOC` enabled Qt targets.
8
+
9
+ This variable is used to initialize the :prop_tgt:`AUTOMOC_PATH_PREFIX`
10
+ property on all the targets. See that target property for additional
11
+ information.
12
+
13
+ The default value is ``OFF``.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_COMPILER_2005.rst ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ CMAKE_COMPILER_2005
2
+ -------------------
3
+
4
+ Using the Visual Studio 2005 compiler from Microsoft
5
+
6
+ Set to true when using the Visual Studio 2005 compiler from Microsoft.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_COMPILE_WARNING_AS_ERROR.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_COMPILE_WARNING_AS_ERROR
2
+ ------------------------------
3
+
4
+ .. versionadded:: 3.24
5
+
6
+ Specify whether to treat warnings on compile as errors.
7
+
8
+ This variable is used to initialize the
9
+ :prop_tgt:`COMPILE_WARNING_AS_ERROR` property on all the targets.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_CUDA_STANDARD_REQUIRED.rst ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_CUDA_STANDARD_REQUIRED
2
+ ----------------------------
3
+
4
+ .. versionadded:: 3.8
5
+
6
+ Default value for :prop_tgt:`CUDA_STANDARD_REQUIRED` target property if set
7
+ when a target is created.
8
+
9
+ See the :manual:`cmake-compile-features(7)` manual for information on
10
+ compile features and a list of supported compilers.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_CXX_EXTENSIONS.rst ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_CXX_EXTENSIONS
2
+ --------------------
3
+
4
+ .. versionadded:: 3.1
5
+
6
+ Default value for :prop_tgt:`CXX_EXTENSIONS` target property if set when a
7
+ target is created.
8
+
9
+ See the :manual:`cmake-compile-features(7)` manual for information on
10
+ compile features and a list of supported compilers.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_CXX_STANDARD_REQUIRED
2
+ ---------------------------
3
+
4
+ .. versionadded:: 3.1
5
+
6
+ Default value for :prop_tgt:`CXX_STANDARD_REQUIRED` target property if set when
7
+ a target is created.
8
+
9
+ See the :manual:`cmake-compile-features(7)` manual for information on
10
+ compile features and a list of supported compilers.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.rst ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_DISABLE_FIND_PACKAGE_<PackageName>
2
+ ----------------------------------------
3
+
4
+ Variable for disabling :command:`find_package` calls.
5
+
6
+ Every non-``REQUIRED`` :command:`find_package` call in a project can be
7
+ disabled by setting the variable
8
+ ``CMAKE_DISABLE_FIND_PACKAGE_<PackageName>`` to ``TRUE``.
9
+ This can be used to build a project without an optional package,
10
+ although that package is installed.
11
+
12
+ This switch should be used during the initial CMake run. Otherwise if
13
+ the package has already been found in a previous CMake run, the
14
+ variables which have been stored in the cache will still be there. In
15
+ that case it is recommended to remove the cache variables for this
16
+ package from the cache using the cache editor or :option:`cmake -U`.
17
+
18
+ Note that this variable can lead to inconsistent results within the project.
19
+ Consider the case where a dependency is requested via :command:`find_package`
20
+ from two different places within the project. If the first call does not
21
+ have the ``REQUIRED`` keyword, it will not find the dependency when
22
+ ``CMAKE_DISABLE_FIND_PACKAGE_<PackageName>`` is set to true for that
23
+ dependency. The project will proceed under the assumption that the dependency
24
+ isn't available. If the second call elsewhere in the project *does* have the
25
+ ``REQUIRED`` keyword, it can succeed. Two different parts of the same project
26
+ have then seen opposite results for the same dependency.
27
+
28
+ See also the :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_EDIT_COMMAND.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_EDIT_COMMAND
2
+ ------------------
3
+
4
+ Full path to :manual:`cmake-gui(1)` or :manual:`ccmake(1)`. Defined only for
5
+ :ref:`Makefile Generators` and :ref:`Ninja Generators` when not using any
6
+ :ref:`Extra Generators`.
7
+
8
+ This is the full path to the CMake executable that can graphically
9
+ edit the cache. For example, :manual:`cmake-gui(1)` or :manual:`ccmake(1)`.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_EXPORT_BUILD_DATABASE
2
+ ---------------------------
3
+
4
+ .. versionadded:: 3.31
5
+
6
+ .. note ::
7
+
8
+ This variable is meaningful only when experimental support for build
9
+ databases has been enabled by the
10
+ ``CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE`` gate.
11
+
12
+ Enable/Disable output of module compile commands during the build.
13
+
14
+ If enabled, generates a ``build_database.json`` file containing the
15
+ information necessary to compile a target's C++ module sources with any
16
+ tooling. The format of the JSON file looks like:
17
+
18
+ .. code-block:: javascript
19
+
20
+ {
21
+ "version": 1,
22
+ "revision": 0,
23
+ "sets": [
24
+ {
25
+ "family-name" : "export_build_database",
26
+ "name" : "export_build_database@Debug",
27
+ "translation-units" : [
28
+ {
29
+ "arguments": [
30
+ "/path/to/compiler",
31
+ "...",
32
+ ],
33
+ "baseline-arguments" :
34
+ [
35
+ "...",
36
+ ],
37
+ "local-arguments" :
38
+ [
39
+ "...",
40
+ ],
41
+ "object": "CMakeFiles/target.dir/source.cxx.o",
42
+ "private": true,
43
+ "provides": {
44
+ "importable": "path/to/bmi"
45
+ },
46
+ "requires" : [],
47
+ "source": "path/to/source.cxx",
48
+ "work-directory": "/path/to/working/directory"
49
+ }
50
+ ],
51
+ "visible-sets" : []
52
+ }
53
+ ]
54
+ }
55
+
56
+ This is initialized by the :envvar:`CMAKE_EXPORT_BUILD_DATABASE` environment
57
+ variable, and initializes the :prop_tgt:`EXPORT_BUILD_DATABASE` target
58
+ property for all targets.
59
+
60
+ .. note::
61
+ This option is implemented only by the :ref:`Ninja Generators`. It is
62
+ ignored on other generators.
63
+
64
+ When supported and enabled, numerous targets are created in order to make it
65
+ possible to build a file containing just the commands that are needed for the
66
+ tool in question.
67
+
68
+ ``cmake_build_database-<CONFIG>``
69
+ Writes ``build_database_<CONFIG>.json``. Writes a build database for the
70
+ entire build for the given configuration and all languages. Not available if
71
+ the configuration name is the empty string.
72
+
73
+ ``cmake_build_database-<LANG>-<CONFIG>``
74
+ Writes ``build_database_<LANG>_<CONFIG>.json``. Writes build database for
75
+ the entire build for the given configuration and language. Not available if
76
+ the configuration name is the empty string.
77
+
78
+ ``cmake_build_database-<LANG>``
79
+ Writes ``build_database_<LANG>.json``. Writes build database for the entire
80
+ build for the given language and all configurations. In a multi-config
81
+ generator, other build configuration database may be assumed to exist.
82
+
83
+ ``cmake_build_database``
84
+ Writes to ``build_database.json``. Writes build database for all languages
85
+ and configurations. In a multi-config generator, other build configuration
86
+ database may be assumed to exist.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_EXPORT_FIND_PACKAGE_NAME.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ CMAKE_EXPORT_FIND_PACKAGE_NAME
2
+ ------------------------------
3
+
4
+ .. note::
5
+
6
+ Experimental. Gated by ``CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES``.
7
+
8
+ Initializes the value of :prop_tgt:`EXPORT_FIND_PACKAGE_NAME`.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_FIND_APPBUNDLE.rst ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_FIND_APPBUNDLE
2
+ --------------------
3
+
4
+ .. versionadded:: 3.4
5
+
6
+ This variable affects how ``find_*`` commands choose between
7
+ macOS Application Bundles and unix-style package components.
8
+
9
+ On Darwin or systems supporting macOS Application Bundles, the
10
+ ``CMAKE_FIND_APPBUNDLE`` variable can be set to empty or
11
+ one of the following:
12
+
13
+ ``FIRST``
14
+ Try to find application bundles before standard programs.
15
+ This is the default on Darwin.
16
+
17
+ ``LAST``
18
+ Try to find application bundles after standard programs.
19
+
20
+ ``ONLY``
21
+ Only try to find application bundles.
22
+
23
+ ``NEVER``
24
+ Never try to find application bundles.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_FIND_LIBRARY_SUFFIXES
2
+ ---------------------------
3
+
4
+ Suffixes to append when looking for libraries.
5
+
6
+ This specifies what suffixes to add to library names when the
7
+ :command:`find_library` command looks for libraries. On Windows systems this
8
+ is typically ``.lib`` and, depending on the compiler, ``.dll.lib``, ``.dll.a``,
9
+ ``.a`` (e.g. rustc, GCC, or Clang), so when it tries to find the ``foo``
10
+ library, it will look for ``[<prefix>]foo[.dll].lib`` and/or
11
+ ``[<prefix>]foo[.dll].a``, depending on the compiler used and the ``<prefix>``
12
+ specified in the :variable:`CMAKE_FIND_LIBRARY_PREFIXES`.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_FIND_PACKAGE_REDIRECTS_DIR.rst ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_FIND_PACKAGE_REDIRECTS_DIR
2
+ --------------------------------
3
+
4
+ .. versionadded:: 3.24
5
+
6
+ This read-only variable specifies a directory that the :command:`find_package`
7
+ command will check first before searching anywhere else for a module or config
8
+ package file. A config package file in this directory will always be found in
9
+ preference to any other Find module file or config package file.
10
+
11
+ The primary purpose of this variable is to facilitate integration between
12
+ :command:`find_package` and :command:`FetchContent_MakeAvailable`. The latter
13
+ command may create files in the ``CMAKE_FIND_PACKAGE_REDIRECTS_DIR`` directory
14
+ when it populates a dependency. This allows subsequent calls to
15
+ :command:`find_package` for the same dependency to reuse the populated
16
+ contents instead of trying to satisfy the dependency from somewhere external
17
+ to the build. Projects may also want to write files into this directory in
18
+ some situations (see :ref:`FetchContent-find_package-integration-examples`
19
+ for examples).
20
+
21
+ The directory that ``CMAKE_FIND_PACKAGE_REDIRECTS_DIR`` points to will always
22
+ be erased and recreated empty at the start of every CMake run. Any files
23
+ written into this directory during the CMake run will be lost the next time
24
+ CMake configures the project.
25
+
26
+ ``CMAKE_FIND_PACKAGE_REDIRECTS_DIR`` is only set in CMake project mode.
27
+ It is not set when CMake is run in script mode
28
+ (i.e. :option:`cmake -P`).
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HIP_PLATFORM.rst ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_HIP_PLATFORM
2
+ ------------------
3
+
4
+ .. versionadded:: 3.28
5
+
6
+ GPU platform for which HIP language sources are to be compiled.
7
+
8
+ The value must be one of:
9
+
10
+ ``amd``
11
+ AMD GPUs
12
+
13
+ ``nvidia``
14
+ NVIDIA GPUs
15
+
16
+ If not specified, a default is computed via ``hipconfig --platform``.
17
+
18
+ :variable:`CMAKE_HIP_ARCHITECTURES` entries are interpreted with
19
+ as architectures of the GPU platform.
20
+
21
+ :variable:`CMAKE_HIP_COMPILER <CMAKE_<LANG>_COMPILER>` must target
22
+ the same GPU platform.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_LINUX.rst ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ CMAKE_HOST_LINUX
2
+ ----------------
3
+
4
+ .. versionadded:: 3.25
5
+
6
+ Set to true when the host system is Linux.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_SYSTEM.rst ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_HOST_SYSTEM
2
+ -----------------
3
+
4
+ Composite Name of OS CMake is being run on.
5
+
6
+ This variable is the composite of :variable:`CMAKE_HOST_SYSTEM_NAME` and
7
+ :variable:`CMAKE_HOST_SYSTEM_VERSION`, e.g.
8
+ ``${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_VERSION}``. If
9
+ :variable:`CMAKE_HOST_SYSTEM_VERSION` is not set, then this variable is
10
+ the same as :variable:`CMAKE_HOST_SYSTEM_NAME`.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_SYSTEM_PROCESSOR.rst ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_HOST_SYSTEM_PROCESSOR
2
+ ---------------------------
3
+
4
+ The name of the CPU CMake is running on.
5
+
6
+ Windows Platforms
7
+ ^^^^^^^^^^^^^^^^^
8
+
9
+ On Windows, this variable is set to the value of the environment variable
10
+ ``PROCESSOR_ARCHITECTURE``.
11
+
12
+ Unix Platforms
13
+ ^^^^^^^^^^^^^^
14
+
15
+ On systems that support ``uname``, this variable is set to the output of:
16
+
17
+ - ``uname -m`` on GNU, Linux, Cygwin, Android, or
18
+ - ``arch`` on OpenBSD, or
19
+ - on other systems,
20
+
21
+ * ``uname -p`` if its exit code is nonzero, or
22
+ * ``uname -m`` otherwise.
23
+
24
+ macOS Platforms
25
+ ^^^^^^^^^^^^^^^
26
+
27
+ The value of ``uname -m`` is used by default.
28
+
29
+ On Apple Silicon hosts, the architecture printed by ``uname -m`` may vary
30
+ based on CMake's own architecture and that of the invoking process tree.
31
+
32
+ .. versionadded:: 3.19.2
33
+
34
+ On Apple Silicon hosts:
35
+
36
+ * The :variable:`CMAKE_APPLE_SILICON_PROCESSOR` variable or
37
+ the :envvar:`CMAKE_APPLE_SILICON_PROCESSOR` environment variable
38
+ may be set to specify the host architecture explicitly.
39
+
40
+ * If :variable:`CMAKE_OSX_ARCHITECTURES` is not set, CMake adds explicit
41
+ flags to tell the compiler to build for the host architecture so the
42
+ toolchain does not have to guess based on the process tree's architecture.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_HOST_WIN32.rst ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ CMAKE_HOST_WIN32
2
+ ----------------
3
+
4
+ ``True`` if the host system is running Windows, including Windows 64-bit and MSYS.
5
+
6
+ Set to ``false`` on Cygwin.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_INCLUDE_DIRECTORIES_BEFORE.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_INCLUDE_DIRECTORIES_BEFORE
2
+ --------------------------------
3
+
4
+ Whether to append or prepend directories by default in
5
+ :command:`include_directories`.
6
+
7
+ This variable affects the default behavior of the :command:`include_directories`
8
+ command. Setting this variable to ``ON`` is equivalent to using the ``BEFORE``
9
+ option in all uses of that command.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_INSTALL_MESSAGE.rst ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_INSTALL_MESSAGE
2
+ ---------------------
3
+
4
+ .. versionadded:: 3.1
5
+
6
+ Specify verbosity of installation script code generated by the
7
+ :command:`install` command (using the :command:`file(INSTALL)` command).
8
+ For paths that are newly installed or updated, installation
9
+ may print lines like::
10
+
11
+ -- Installing: /some/destination/path
12
+
13
+ For paths that are already up to date, installation may print
14
+ lines like::
15
+
16
+ -- Up-to-date: /some/destination/path
17
+
18
+ The ``CMAKE_INSTALL_MESSAGE`` variable may be set to control
19
+ which messages are printed:
20
+
21
+ ``ALWAYS``
22
+ Print both ``Installing`` and ``Up-to-date`` messages.
23
+
24
+ ``LAZY``
25
+ Print ``Installing`` but not ``Up-to-date`` messages.
26
+
27
+ ``NEVER``
28
+ Print neither ``Installing`` nor ``Up-to-date`` messages.
29
+
30
+ Other values have undefined behavior and may not be diagnosed.
31
+
32
+ If this variable is not set, the default behavior is ``ALWAYS``.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.rst ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_INSTALL_RPATH_USE_LINK_PATH
2
+ ---------------------------------
3
+
4
+ Add paths to linker search and installed rpath.
5
+
6
+ ``CMAKE_INSTALL_RPATH_USE_LINK_PATH`` is a boolean that if set to ``True``
7
+ will append to the runtime search path (rpath) of installed binaries
8
+ any directories outside the project that are in the linker search path or
9
+ contain linked library files. The directories are appended after the
10
+ value of the :prop_tgt:`INSTALL_RPATH` target property.
11
+
12
+ This variable is used to initialize the target property
13
+ :prop_tgt:`INSTALL_RPATH_USE_LINK_PATH` for all targets.
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN
2
+ ----------------------------------------
3
+
4
+ The external toolchain for cross-compiling, if supported.
5
+
6
+ Some compiler toolchains do not ship their own auxiliary utilities such as
7
+ archivers and linkers. The compiler driver may support a command-line argument
8
+ to specify the location of such tools.
9
+ ``CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN`` may be set to a path to
10
+ the external toolchain and will be passed to the compiler driver if supported.
11
+
12
+ This variable may only be set in a toolchain file specified by
13
+ the :variable:`CMAKE_TOOLCHAIN_FILE` variable.