Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_common.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_indexing.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_numpy_compat.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_setops.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__init__.py +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/__init__.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_constructors.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_indexing.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_setops.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_constructors.py +80 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_formats.py +163 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_indexing.py +104 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_pickle.py +11 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_reshape.py +95 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.py +266 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_where.py +13 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/__init__.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_astype.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_constructors.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_fillna.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_formats.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_indexing.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_reindex.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_reindex.py +78 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__init__.py +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/__init__.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_drop_duplicates.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_equals.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_indexing.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_is_monotonic.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py +89 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_value_counts.py +103 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__init__.py +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/__init__.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_astype.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_constructors.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_equals.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_formats.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_indexing.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_interval.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_interval_range.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_interval_tree.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_join.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_pickle.cpython-310.pyc +0 -0
- valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_setops.cpython-310.pyc +0 -0
valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-310.pyc
ADDED
|
Binary file (53.3 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_common.cpython-310.pyc
ADDED
|
Binary file (13 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_indexing.cpython-310.pyc
ADDED
|
Binary file (11.6 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_numpy_compat.cpython-310.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/__pycache__/test_setops.cpython-310.pyc
ADDED
|
Binary file (23.2 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__init__.py
ADDED
|
File without changes
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (183 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_constructors.cpython-310.pyc
ADDED
|
Binary file (3.33 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-310.pyc
ADDED
|
Binary file (5.08 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_indexing.cpython-310.pyc
ADDED
|
Binary file (4.32 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-310.pyc
ADDED
|
Binary file (551 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-310.pyc
ADDED
|
Binary file (3.5 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_setops.cpython-310.pyc
ADDED
|
Binary file (8.25 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-310.pyc
ADDED
|
Binary file (805 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_constructors.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from pandas import (
|
| 6 |
+
Index,
|
| 7 |
+
MultiIndex,
|
| 8 |
+
Series,
|
| 9 |
+
)
|
| 10 |
+
import pandas._testing as tm
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestIndexConstructor:
|
| 14 |
+
# Tests for the Index constructor, specifically for cases that do
|
| 15 |
+
# not return a subclass
|
| 16 |
+
|
| 17 |
+
@pytest.mark.parametrize("value", [1, np.int64(1)])
|
| 18 |
+
def test_constructor_corner(self, value):
|
| 19 |
+
# corner case
|
| 20 |
+
msg = (
|
| 21 |
+
r"Index\(\.\.\.\) must be called with a collection of some "
|
| 22 |
+
f"kind, {value} was passed"
|
| 23 |
+
)
|
| 24 |
+
with pytest.raises(TypeError, match=msg):
|
| 25 |
+
Index(value)
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize("index_vals", [[("A", 1), "B"], ["B", ("A", 1)]])
|
| 28 |
+
def test_construction_list_mixed_tuples(self, index_vals):
|
| 29 |
+
# see gh-10697: if we are constructing from a mixed list of tuples,
|
| 30 |
+
# make sure that we are independent of the sorting order.
|
| 31 |
+
index = Index(index_vals)
|
| 32 |
+
assert isinstance(index, Index)
|
| 33 |
+
assert not isinstance(index, MultiIndex)
|
| 34 |
+
|
| 35 |
+
def test_constructor_cast(self):
|
| 36 |
+
msg = "could not convert string to float"
|
| 37 |
+
with pytest.raises(ValueError, match=msg):
|
| 38 |
+
Index(["a", "b", "c"], dtype=float)
|
| 39 |
+
|
| 40 |
+
@pytest.mark.parametrize("tuple_list", [[()], [(), ()]])
|
| 41 |
+
def test_construct_empty_tuples(self, tuple_list):
|
| 42 |
+
# GH #45608
|
| 43 |
+
result = Index(tuple_list)
|
| 44 |
+
expected = MultiIndex.from_tuples(tuple_list)
|
| 45 |
+
|
| 46 |
+
tm.assert_index_equal(result, expected)
|
| 47 |
+
|
| 48 |
+
def test_index_string_inference(self):
|
| 49 |
+
# GH#54430
|
| 50 |
+
pytest.importorskip("pyarrow")
|
| 51 |
+
dtype = "string[pyarrow_numpy]"
|
| 52 |
+
expected = Index(["a", "b"], dtype=dtype)
|
| 53 |
+
with pd.option_context("future.infer_string", True):
|
| 54 |
+
ser = Index(["a", "b"])
|
| 55 |
+
tm.assert_index_equal(ser, expected)
|
| 56 |
+
|
| 57 |
+
expected = Index(["a", 1], dtype="object")
|
| 58 |
+
with pd.option_context("future.infer_string", True):
|
| 59 |
+
ser = Index(["a", 1])
|
| 60 |
+
tm.assert_index_equal(ser, expected)
|
| 61 |
+
|
| 62 |
+
def test_inference_on_pandas_objects(self):
|
| 63 |
+
# GH#56012
|
| 64 |
+
idx = Index([pd.Timestamp("2019-12-31")], dtype=object)
|
| 65 |
+
with tm.assert_produces_warning(FutureWarning, match="Dtype inference"):
|
| 66 |
+
result = Index(idx)
|
| 67 |
+
assert result.dtype != np.object_
|
| 68 |
+
|
| 69 |
+
ser = Series([pd.Timestamp("2019-12-31")], dtype=object)
|
| 70 |
+
|
| 71 |
+
with tm.assert_produces_warning(FutureWarning, match="Dtype inference"):
|
| 72 |
+
result = Index(ser)
|
| 73 |
+
assert result.dtype != np.object_
|
| 74 |
+
|
| 75 |
+
def test_constructor_not_read_only(self):
|
| 76 |
+
# GH#57130
|
| 77 |
+
ser = Series([1, 2], dtype=object)
|
| 78 |
+
with pd.option_context("mode.copy_on_write", True):
|
| 79 |
+
idx = Index(ser)
|
| 80 |
+
assert idx._values.flags.writeable
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_formats.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas._config import using_pyarrow_string_dtype
|
| 5 |
+
import pandas._config.config as cf
|
| 6 |
+
|
| 7 |
+
from pandas import Index
|
| 8 |
+
import pandas._testing as tm
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestIndexRendering:
|
| 12 |
+
def test_repr_is_valid_construction_code(self):
|
| 13 |
+
# for the case of Index, where the repr is traditional rather than
|
| 14 |
+
# stylized
|
| 15 |
+
idx = Index(["a", "b"])
|
| 16 |
+
res = eval(repr(idx))
|
| 17 |
+
tm.assert_index_equal(res, idx)
|
| 18 |
+
|
| 19 |
+
@pytest.mark.xfail(using_pyarrow_string_dtype(), reason="repr different")
|
| 20 |
+
@pytest.mark.parametrize(
|
| 21 |
+
"index,expected",
|
| 22 |
+
[
|
| 23 |
+
# ASCII
|
| 24 |
+
# short
|
| 25 |
+
(
|
| 26 |
+
Index(["a", "bb", "ccc"]),
|
| 27 |
+
"""Index(['a', 'bb', 'ccc'], dtype='object')""",
|
| 28 |
+
),
|
| 29 |
+
# multiple lines
|
| 30 |
+
(
|
| 31 |
+
Index(["a", "bb", "ccc"] * 10),
|
| 32 |
+
"Index(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', "
|
| 33 |
+
"'bb', 'ccc', 'a', 'bb', 'ccc',\n"
|
| 34 |
+
" 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', "
|
| 35 |
+
"'bb', 'ccc', 'a', 'bb', 'ccc',\n"
|
| 36 |
+
" 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],\n"
|
| 37 |
+
" dtype='object')",
|
| 38 |
+
),
|
| 39 |
+
# truncated
|
| 40 |
+
(
|
| 41 |
+
Index(["a", "bb", "ccc"] * 100),
|
| 42 |
+
"Index(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a',\n"
|
| 43 |
+
" ...\n"
|
| 44 |
+
" 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'],\n"
|
| 45 |
+
" dtype='object', length=300)",
|
| 46 |
+
),
|
| 47 |
+
# Non-ASCII
|
| 48 |
+
# short
|
| 49 |
+
(
|
| 50 |
+
Index(["あ", "いい", "ううう"]),
|
| 51 |
+
"""Index(['あ', 'いい', 'ううう'], dtype='object')""",
|
| 52 |
+
),
|
| 53 |
+
# multiple lines
|
| 54 |
+
(
|
| 55 |
+
Index(["あ", "いい", "ううう"] * 10),
|
| 56 |
+
(
|
| 57 |
+
"Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
|
| 58 |
+
"'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n"
|
| 59 |
+
" 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
|
| 60 |
+
"'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n"
|
| 61 |
+
" 'あ', 'いい', 'ううう', 'あ', 'いい', "
|
| 62 |
+
"'ううう'],\n"
|
| 63 |
+
" dtype='object')"
|
| 64 |
+
),
|
| 65 |
+
),
|
| 66 |
+
# truncated
|
| 67 |
+
(
|
| 68 |
+
Index(["あ", "いい", "ううう"] * 100),
|
| 69 |
+
(
|
| 70 |
+
"Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
|
| 71 |
+
"'あ', 'いい', 'ううう', 'あ',\n"
|
| 72 |
+
" ...\n"
|
| 73 |
+
" 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', "
|
| 74 |
+
"'ううう', 'あ', 'いい', 'ううう'],\n"
|
| 75 |
+
" dtype='object', length=300)"
|
| 76 |
+
),
|
| 77 |
+
),
|
| 78 |
+
],
|
| 79 |
+
)
|
| 80 |
+
def test_string_index_repr(self, index, expected):
|
| 81 |
+
result = repr(index)
|
| 82 |
+
assert result == expected
|
| 83 |
+
|
| 84 |
+
@pytest.mark.xfail(using_pyarrow_string_dtype(), reason="repr different")
|
| 85 |
+
@pytest.mark.parametrize(
|
| 86 |
+
"index,expected",
|
| 87 |
+
[
|
| 88 |
+
# short
|
| 89 |
+
(
|
| 90 |
+
Index(["あ", "いい", "ううう"]),
|
| 91 |
+
("Index(['あ', 'いい', 'ううう'], dtype='object')"),
|
| 92 |
+
),
|
| 93 |
+
# multiple lines
|
| 94 |
+
(
|
| 95 |
+
Index(["あ", "いい", "ううう"] * 10),
|
| 96 |
+
(
|
| 97 |
+
"Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
|
| 98 |
+
"'ううう', 'あ', 'いい', 'ううう',\n"
|
| 99 |
+
" 'あ', 'いい', 'ううう', 'あ', 'いい', "
|
| 100 |
+
"'ううう', 'あ', 'いい', 'ううう',\n"
|
| 101 |
+
" 'あ', 'いい', 'ううう', 'あ', 'いい', "
|
| 102 |
+
"'ううう', 'あ', 'いい', 'ううう',\n"
|
| 103 |
+
" 'あ', 'いい', 'ううう'],\n"
|
| 104 |
+
" dtype='object')"
|
| 105 |
+
""
|
| 106 |
+
),
|
| 107 |
+
),
|
| 108 |
+
# truncated
|
| 109 |
+
(
|
| 110 |
+
Index(["あ", "いい", "ううう"] * 100),
|
| 111 |
+
(
|
| 112 |
+
"Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
|
| 113 |
+
"'ううう', 'あ', 'いい', 'ううう',\n"
|
| 114 |
+
" 'あ',\n"
|
| 115 |
+
" ...\n"
|
| 116 |
+
" 'ううう', 'あ', 'いい', 'ううう', 'あ', "
|
| 117 |
+
"'いい', 'ううう', 'あ', 'いい',\n"
|
| 118 |
+
" 'ううう'],\n"
|
| 119 |
+
" dtype='object', length=300)"
|
| 120 |
+
),
|
| 121 |
+
),
|
| 122 |
+
],
|
| 123 |
+
)
|
| 124 |
+
def test_string_index_repr_with_unicode_option(self, index, expected):
|
| 125 |
+
# Enable Unicode option -----------------------------------------
|
| 126 |
+
with cf.option_context("display.unicode.east_asian_width", True):
|
| 127 |
+
result = repr(index)
|
| 128 |
+
assert result == expected
|
| 129 |
+
|
| 130 |
+
def test_repr_summary(self):
|
| 131 |
+
with cf.option_context("display.max_seq_items", 10):
|
| 132 |
+
result = repr(Index(np.arange(1000)))
|
| 133 |
+
assert len(result) < 200
|
| 134 |
+
assert "..." in result
|
| 135 |
+
|
| 136 |
+
def test_summary_bug(self):
|
| 137 |
+
# GH#3869
|
| 138 |
+
ind = Index(["{other}%s", "~:{range}:0"], name="A")
|
| 139 |
+
result = ind._summary()
|
| 140 |
+
# shouldn't be formatted accidentally.
|
| 141 |
+
assert "~:{range}:0" in result
|
| 142 |
+
assert "{other}%s" in result
|
| 143 |
+
|
| 144 |
+
def test_index_repr_bool_nan(self):
|
| 145 |
+
# GH32146
|
| 146 |
+
arr = Index([True, False, np.nan], dtype=object)
|
| 147 |
+
msg = "Index.format is deprecated"
|
| 148 |
+
with tm.assert_produces_warning(FutureWarning, match=msg):
|
| 149 |
+
exp1 = arr.format()
|
| 150 |
+
out1 = ["True", "False", "NaN"]
|
| 151 |
+
assert out1 == exp1
|
| 152 |
+
|
| 153 |
+
exp2 = repr(arr)
|
| 154 |
+
out2 = "Index([True, False, nan], dtype='object')"
|
| 155 |
+
assert out2 == exp2
|
| 156 |
+
|
| 157 |
+
def test_format_different_scalar_lengths(self):
|
| 158 |
+
# GH#35439
|
| 159 |
+
idx = Index(["aaaaaaaaa", "b"])
|
| 160 |
+
expected = ["aaaaaaaaa", "b"]
|
| 161 |
+
msg = r"Index\.format is deprecated"
|
| 162 |
+
with tm.assert_produces_warning(FutureWarning, match=msg):
|
| 163 |
+
assert idx.format() == expected
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_indexing.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas._libs import index as libindex
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from pandas import (
|
| 8 |
+
Index,
|
| 9 |
+
NaT,
|
| 10 |
+
)
|
| 11 |
+
import pandas._testing as tm
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class TestGetSliceBounds:
|
| 15 |
+
@pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)])
|
| 16 |
+
def test_get_slice_bounds_within(self, side, expected):
|
| 17 |
+
index = Index(list("abcdef"))
|
| 18 |
+
result = index.get_slice_bound("e", side=side)
|
| 19 |
+
assert result == expected
|
| 20 |
+
|
| 21 |
+
@pytest.mark.parametrize("side", ["left", "right"])
|
| 22 |
+
@pytest.mark.parametrize(
|
| 23 |
+
"data, bound, expected", [(list("abcdef"), "x", 6), (list("bcdefg"), "a", 0)]
|
| 24 |
+
)
|
| 25 |
+
def test_get_slice_bounds_outside(self, side, expected, data, bound):
|
| 26 |
+
index = Index(data)
|
| 27 |
+
result = index.get_slice_bound(bound, side=side)
|
| 28 |
+
assert result == expected
|
| 29 |
+
|
| 30 |
+
def test_get_slice_bounds_invalid_side(self):
|
| 31 |
+
with pytest.raises(ValueError, match="Invalid value for side kwarg"):
|
| 32 |
+
Index([]).get_slice_bound("a", side="middle")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class TestGetIndexerNonUnique:
|
| 36 |
+
def test_get_indexer_non_unique_dtype_mismatch(self):
|
| 37 |
+
# GH#25459
|
| 38 |
+
indexes, missing = Index(["A", "B"]).get_indexer_non_unique(Index([0]))
|
| 39 |
+
tm.assert_numpy_array_equal(np.array([-1], dtype=np.intp), indexes)
|
| 40 |
+
tm.assert_numpy_array_equal(np.array([0], dtype=np.intp), missing)
|
| 41 |
+
|
| 42 |
+
@pytest.mark.parametrize(
|
| 43 |
+
"idx_values,idx_non_unique",
|
| 44 |
+
[
|
| 45 |
+
([np.nan, 100, 200, 100], [np.nan, 100]),
|
| 46 |
+
([np.nan, 100.0, 200.0, 100.0], [np.nan, 100.0]),
|
| 47 |
+
],
|
| 48 |
+
)
|
| 49 |
+
def test_get_indexer_non_unique_int_index(self, idx_values, idx_non_unique):
|
| 50 |
+
indexes, missing = Index(idx_values).get_indexer_non_unique(Index([np.nan]))
|
| 51 |
+
tm.assert_numpy_array_equal(np.array([0], dtype=np.intp), indexes)
|
| 52 |
+
tm.assert_numpy_array_equal(np.array([], dtype=np.intp), missing)
|
| 53 |
+
|
| 54 |
+
indexes, missing = Index(idx_values).get_indexer_non_unique(
|
| 55 |
+
Index(idx_non_unique)
|
| 56 |
+
)
|
| 57 |
+
tm.assert_numpy_array_equal(np.array([0, 1, 3], dtype=np.intp), indexes)
|
| 58 |
+
tm.assert_numpy_array_equal(np.array([], dtype=np.intp), missing)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class TestGetLoc:
|
| 62 |
+
@pytest.mark.slow # to_flat_index takes a while
|
| 63 |
+
def test_get_loc_tuple_monotonic_above_size_cutoff(self, monkeypatch):
|
| 64 |
+
# Go through the libindex path for which using
|
| 65 |
+
# _bin_search vs ndarray.searchsorted makes a difference
|
| 66 |
+
|
| 67 |
+
with monkeypatch.context():
|
| 68 |
+
monkeypatch.setattr(libindex, "_SIZE_CUTOFF", 100)
|
| 69 |
+
lev = list("ABCD")
|
| 70 |
+
dti = pd.date_range("2016-01-01", periods=10)
|
| 71 |
+
|
| 72 |
+
mi = pd.MultiIndex.from_product([lev, range(5), dti])
|
| 73 |
+
oidx = mi.to_flat_index()
|
| 74 |
+
|
| 75 |
+
loc = len(oidx) // 2
|
| 76 |
+
tup = oidx[loc]
|
| 77 |
+
|
| 78 |
+
res = oidx.get_loc(tup)
|
| 79 |
+
assert res == loc
|
| 80 |
+
|
| 81 |
+
def test_get_loc_nan_object_dtype_nonmonotonic_nonunique(self):
|
| 82 |
+
# case that goes through _maybe_get_bool_indexer
|
| 83 |
+
idx = Index(["foo", np.nan, None, "foo", 1.0, None], dtype=object)
|
| 84 |
+
|
| 85 |
+
# we dont raise KeyError on nan
|
| 86 |
+
res = idx.get_loc(np.nan)
|
| 87 |
+
assert res == 1
|
| 88 |
+
|
| 89 |
+
# we only match on None, not on np.nan
|
| 90 |
+
res = idx.get_loc(None)
|
| 91 |
+
expected = np.array([False, False, True, False, False, True])
|
| 92 |
+
tm.assert_numpy_array_equal(res, expected)
|
| 93 |
+
|
| 94 |
+
# we don't match at all on mismatched NA
|
| 95 |
+
with pytest.raises(KeyError, match="NaT"):
|
| 96 |
+
idx.get_loc(NaT)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def test_getitem_boolean_ea_indexer():
|
| 100 |
+
# GH#45806
|
| 101 |
+
ser = pd.Series([True, False, pd.NA], dtype="boolean")
|
| 102 |
+
result = ser.index[ser]
|
| 103 |
+
expected = Index([0])
|
| 104 |
+
tm.assert_index_equal(result, expected)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_pickle.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pandas import Index
|
| 2 |
+
import pandas._testing as tm
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def test_pickle_preserves_object_dtype():
|
| 6 |
+
# GH#43188, GH#43155 don't infer numeric dtype
|
| 7 |
+
index = Index([1, 2, 3], dtype=object)
|
| 8 |
+
|
| 9 |
+
result = tm.round_trip_pickle(index)
|
| 10 |
+
assert result.dtype == object
|
| 11 |
+
tm.assert_index_equal(index, result)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_reshape.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for ndarray-like method on the base Index class
|
| 3 |
+
"""
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from pandas import Index
|
| 8 |
+
import pandas._testing as tm
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestReshape:
|
| 12 |
+
def test_repeat(self):
|
| 13 |
+
repeats = 2
|
| 14 |
+
index = Index([1, 2, 3])
|
| 15 |
+
expected = Index([1, 1, 2, 2, 3, 3])
|
| 16 |
+
|
| 17 |
+
result = index.repeat(repeats)
|
| 18 |
+
tm.assert_index_equal(result, expected)
|
| 19 |
+
|
| 20 |
+
def test_insert(self):
|
| 21 |
+
# GH 7256
|
| 22 |
+
# validate neg/pos inserts
|
| 23 |
+
result = Index(["b", "c", "d"])
|
| 24 |
+
|
| 25 |
+
# test 0th element
|
| 26 |
+
tm.assert_index_equal(Index(["a", "b", "c", "d"]), result.insert(0, "a"))
|
| 27 |
+
|
| 28 |
+
# test Nth element that follows Python list behavior
|
| 29 |
+
tm.assert_index_equal(Index(["b", "c", "e", "d"]), result.insert(-1, "e"))
|
| 30 |
+
|
| 31 |
+
# test loc +/- neq (0, -1)
|
| 32 |
+
tm.assert_index_equal(result.insert(1, "z"), result.insert(-2, "z"))
|
| 33 |
+
|
| 34 |
+
# test empty
|
| 35 |
+
null_index = Index([])
|
| 36 |
+
tm.assert_index_equal(Index(["a"], dtype=object), null_index.insert(0, "a"))
|
| 37 |
+
|
| 38 |
+
def test_insert_missing(self, nulls_fixture, using_infer_string):
|
| 39 |
+
# GH#22295
|
| 40 |
+
# test there is no mangling of NA values
|
| 41 |
+
expected = Index(["a", nulls_fixture, "b", "c"], dtype=object)
|
| 42 |
+
result = Index(list("abc"), dtype=object).insert(
|
| 43 |
+
1, Index([nulls_fixture], dtype=object)
|
| 44 |
+
)
|
| 45 |
+
tm.assert_index_equal(result, expected)
|
| 46 |
+
|
| 47 |
+
@pytest.mark.parametrize(
|
| 48 |
+
"val", [(1, 2), np.datetime64("2019-12-31"), np.timedelta64(1, "D")]
|
| 49 |
+
)
|
| 50 |
+
@pytest.mark.parametrize("loc", [-1, 2])
|
| 51 |
+
def test_insert_datetime_into_object(self, loc, val):
|
| 52 |
+
# GH#44509
|
| 53 |
+
idx = Index(["1", "2", "3"])
|
| 54 |
+
result = idx.insert(loc, val)
|
| 55 |
+
expected = Index(["1", "2", val, "3"])
|
| 56 |
+
tm.assert_index_equal(result, expected)
|
| 57 |
+
assert type(expected[2]) is type(val)
|
| 58 |
+
|
| 59 |
+
def test_insert_none_into_string_numpy(self):
|
| 60 |
+
# GH#55365
|
| 61 |
+
pytest.importorskip("pyarrow")
|
| 62 |
+
index = Index(["a", "b", "c"], dtype="string[pyarrow_numpy]")
|
| 63 |
+
result = index.insert(-1, None)
|
| 64 |
+
expected = Index(["a", "b", None, "c"], dtype="string[pyarrow_numpy]")
|
| 65 |
+
tm.assert_index_equal(result, expected)
|
| 66 |
+
|
| 67 |
+
@pytest.mark.parametrize(
|
| 68 |
+
"pos,expected",
|
| 69 |
+
[
|
| 70 |
+
(0, Index(["b", "c", "d"], name="index")),
|
| 71 |
+
(-1, Index(["a", "b", "c"], name="index")),
|
| 72 |
+
],
|
| 73 |
+
)
|
| 74 |
+
def test_delete(self, pos, expected):
|
| 75 |
+
index = Index(["a", "b", "c", "d"], name="index")
|
| 76 |
+
result = index.delete(pos)
|
| 77 |
+
tm.assert_index_equal(result, expected)
|
| 78 |
+
assert result.name == expected.name
|
| 79 |
+
|
| 80 |
+
def test_delete_raises(self):
|
| 81 |
+
index = Index(["a", "b", "c", "d"], name="index")
|
| 82 |
+
msg = "index 5 is out of bounds for axis 0 with size 4"
|
| 83 |
+
with pytest.raises(IndexError, match=msg):
|
| 84 |
+
index.delete(5)
|
| 85 |
+
|
| 86 |
+
def test_append_multiple(self):
|
| 87 |
+
index = Index(["a", "b", "c", "d", "e", "f"])
|
| 88 |
+
|
| 89 |
+
foos = [index[:2], index[2:4], index[4:]]
|
| 90 |
+
result = foos[0].append(foos[1:])
|
| 91 |
+
tm.assert_index_equal(result, index)
|
| 92 |
+
|
| 93 |
+
# empty
|
| 94 |
+
result = index.append([])
|
| 95 |
+
tm.assert_index_equal(result, index)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_setops.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from pandas import (
|
| 8 |
+
Index,
|
| 9 |
+
Series,
|
| 10 |
+
)
|
| 11 |
+
import pandas._testing as tm
|
| 12 |
+
from pandas.core.algorithms import safe_sort
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def equal_contents(arr1, arr2) -> bool:
|
| 16 |
+
"""
|
| 17 |
+
Checks if the set of unique elements of arr1 and arr2 are equivalent.
|
| 18 |
+
"""
|
| 19 |
+
return frozenset(arr1) == frozenset(arr2)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TestIndexSetOps:
|
| 23 |
+
@pytest.mark.parametrize(
|
| 24 |
+
"method", ["union", "intersection", "difference", "symmetric_difference"]
|
| 25 |
+
)
|
| 26 |
+
def test_setops_sort_validation(self, method):
|
| 27 |
+
idx1 = Index(["a", "b"])
|
| 28 |
+
idx2 = Index(["b", "c"])
|
| 29 |
+
|
| 30 |
+
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
|
| 31 |
+
getattr(idx1, method)(idx2, sort=2)
|
| 32 |
+
|
| 33 |
+
# sort=True is supported as of GH#??
|
| 34 |
+
getattr(idx1, method)(idx2, sort=True)
|
| 35 |
+
|
| 36 |
+
def test_setops_preserve_object_dtype(self):
|
| 37 |
+
idx = Index([1, 2, 3], dtype=object)
|
| 38 |
+
result = idx.intersection(idx[1:])
|
| 39 |
+
expected = idx[1:]
|
| 40 |
+
tm.assert_index_equal(result, expected)
|
| 41 |
+
|
| 42 |
+
# if other is not monotonic increasing, intersection goes through
|
| 43 |
+
# a different route
|
| 44 |
+
result = idx.intersection(idx[1:][::-1])
|
| 45 |
+
tm.assert_index_equal(result, expected)
|
| 46 |
+
|
| 47 |
+
result = idx._union(idx[1:], sort=None)
|
| 48 |
+
expected = idx
|
| 49 |
+
tm.assert_numpy_array_equal(result, expected.values)
|
| 50 |
+
|
| 51 |
+
result = idx.union(idx[1:], sort=None)
|
| 52 |
+
tm.assert_index_equal(result, expected)
|
| 53 |
+
|
| 54 |
+
# if other is not monotonic increasing, _union goes through
|
| 55 |
+
# a different route
|
| 56 |
+
result = idx._union(idx[1:][::-1], sort=None)
|
| 57 |
+
tm.assert_numpy_array_equal(result, expected.values)
|
| 58 |
+
|
| 59 |
+
result = idx.union(idx[1:][::-1], sort=None)
|
| 60 |
+
tm.assert_index_equal(result, expected)
|
| 61 |
+
|
| 62 |
+
def test_union_base(self):
|
| 63 |
+
index = Index([0, "a", 1, "b", 2, "c"])
|
| 64 |
+
first = index[3:]
|
| 65 |
+
second = index[:5]
|
| 66 |
+
|
| 67 |
+
result = first.union(second)
|
| 68 |
+
|
| 69 |
+
expected = Index([0, 1, 2, "a", "b", "c"])
|
| 70 |
+
tm.assert_index_equal(result, expected)
|
| 71 |
+
|
| 72 |
+
@pytest.mark.parametrize("klass", [np.array, Series, list])
|
| 73 |
+
def test_union_different_type_base(self, klass):
|
| 74 |
+
# GH 10149
|
| 75 |
+
index = Index([0, "a", 1, "b", 2, "c"])
|
| 76 |
+
first = index[3:]
|
| 77 |
+
second = index[:5]
|
| 78 |
+
|
| 79 |
+
result = first.union(klass(second.values))
|
| 80 |
+
|
| 81 |
+
assert equal_contents(result, index)
|
| 82 |
+
|
| 83 |
+
def test_union_sort_other_incomparable(self):
|
| 84 |
+
# https://github.com/pandas-dev/pandas/issues/24959
|
| 85 |
+
idx = Index([1, pd.Timestamp("2000")])
|
| 86 |
+
# default (sort=None)
|
| 87 |
+
with tm.assert_produces_warning(RuntimeWarning):
|
| 88 |
+
result = idx.union(idx[:1])
|
| 89 |
+
|
| 90 |
+
tm.assert_index_equal(result, idx)
|
| 91 |
+
|
| 92 |
+
# sort=None
|
| 93 |
+
with tm.assert_produces_warning(RuntimeWarning):
|
| 94 |
+
result = idx.union(idx[:1], sort=None)
|
| 95 |
+
tm.assert_index_equal(result, idx)
|
| 96 |
+
|
| 97 |
+
# sort=False
|
| 98 |
+
result = idx.union(idx[:1], sort=False)
|
| 99 |
+
tm.assert_index_equal(result, idx)
|
| 100 |
+
|
| 101 |
+
def test_union_sort_other_incomparable_true(self):
|
| 102 |
+
idx = Index([1, pd.Timestamp("2000")])
|
| 103 |
+
with pytest.raises(TypeError, match=".*"):
|
| 104 |
+
idx.union(idx[:1], sort=True)
|
| 105 |
+
|
| 106 |
+
def test_intersection_equal_sort_true(self):
|
| 107 |
+
idx = Index(["c", "a", "b"])
|
| 108 |
+
sorted_ = Index(["a", "b", "c"])
|
| 109 |
+
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
|
| 110 |
+
|
| 111 |
+
def test_intersection_base(self, sort):
|
| 112 |
+
# (same results for py2 and py3 but sortedness not tested elsewhere)
|
| 113 |
+
index = Index([0, "a", 1, "b", 2, "c"])
|
| 114 |
+
first = index[:5]
|
| 115 |
+
second = index[:3]
|
| 116 |
+
|
| 117 |
+
expected = Index([0, 1, "a"]) if sort is None else Index([0, "a", 1])
|
| 118 |
+
result = first.intersection(second, sort=sort)
|
| 119 |
+
tm.assert_index_equal(result, expected)
|
| 120 |
+
|
| 121 |
+
@pytest.mark.parametrize("klass", [np.array, Series, list])
|
| 122 |
+
def test_intersection_different_type_base(self, klass, sort):
|
| 123 |
+
# GH 10149
|
| 124 |
+
index = Index([0, "a", 1, "b", 2, "c"])
|
| 125 |
+
first = index[:5]
|
| 126 |
+
second = index[:3]
|
| 127 |
+
|
| 128 |
+
result = first.intersection(klass(second.values), sort=sort)
|
| 129 |
+
assert equal_contents(result, second)
|
| 130 |
+
|
| 131 |
+
def test_intersection_nosort(self):
|
| 132 |
+
result = Index(["c", "b", "a"]).intersection(["b", "a"])
|
| 133 |
+
expected = Index(["b", "a"])
|
| 134 |
+
tm.assert_index_equal(result, expected)
|
| 135 |
+
|
| 136 |
+
def test_intersection_equal_sort(self):
|
| 137 |
+
idx = Index(["c", "a", "b"])
|
| 138 |
+
tm.assert_index_equal(idx.intersection(idx, sort=False), idx)
|
| 139 |
+
tm.assert_index_equal(idx.intersection(idx, sort=None), idx)
|
| 140 |
+
|
| 141 |
+
def test_intersection_str_dates(self, sort):
|
| 142 |
+
dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)]
|
| 143 |
+
|
| 144 |
+
i1 = Index(dt_dates, dtype=object)
|
| 145 |
+
i2 = Index(["aa"], dtype=object)
|
| 146 |
+
result = i2.intersection(i1, sort=sort)
|
| 147 |
+
|
| 148 |
+
assert len(result) == 0
|
| 149 |
+
|
| 150 |
+
@pytest.mark.parametrize(
|
| 151 |
+
"index2,expected_arr",
|
| 152 |
+
[(Index(["B", "D"]), ["B"]), (Index(["B", "D", "A"]), ["A", "B"])],
|
| 153 |
+
)
|
| 154 |
+
def test_intersection_non_monotonic_non_unique(self, index2, expected_arr, sort):
|
| 155 |
+
# non-monotonic non-unique
|
| 156 |
+
index1 = Index(["A", "B", "A", "C"])
|
| 157 |
+
expected = Index(expected_arr)
|
| 158 |
+
result = index1.intersection(index2, sort=sort)
|
| 159 |
+
if sort is None:
|
| 160 |
+
expected = expected.sort_values()
|
| 161 |
+
tm.assert_index_equal(result, expected)
|
| 162 |
+
|
| 163 |
+
def test_difference_base(self, sort):
|
| 164 |
+
# (same results for py2 and py3 but sortedness not tested elsewhere)
|
| 165 |
+
index = Index([0, "a", 1, "b", 2, "c"])
|
| 166 |
+
first = index[:4]
|
| 167 |
+
second = index[3:]
|
| 168 |
+
|
| 169 |
+
result = first.difference(second, sort)
|
| 170 |
+
expected = Index([0, "a", 1])
|
| 171 |
+
if sort is None:
|
| 172 |
+
expected = Index(safe_sort(expected))
|
| 173 |
+
tm.assert_index_equal(result, expected)
|
| 174 |
+
|
| 175 |
+
def test_symmetric_difference(self):
|
| 176 |
+
# (same results for py2 and py3 but sortedness not tested elsewhere)
|
| 177 |
+
index = Index([0, "a", 1, "b", 2, "c"])
|
| 178 |
+
first = index[:4]
|
| 179 |
+
second = index[3:]
|
| 180 |
+
|
| 181 |
+
result = first.symmetric_difference(second)
|
| 182 |
+
expected = Index([0, 1, 2, "a", "c"])
|
| 183 |
+
tm.assert_index_equal(result, expected)
|
| 184 |
+
|
| 185 |
+
@pytest.mark.parametrize(
|
| 186 |
+
"method,expected,sort",
|
| 187 |
+
[
|
| 188 |
+
(
|
| 189 |
+
"intersection",
|
| 190 |
+
np.array(
|
| 191 |
+
[(1, "A"), (2, "A"), (1, "B"), (2, "B")],
|
| 192 |
+
dtype=[("num", int), ("let", "S1")],
|
| 193 |
+
),
|
| 194 |
+
False,
|
| 195 |
+
),
|
| 196 |
+
(
|
| 197 |
+
"intersection",
|
| 198 |
+
np.array(
|
| 199 |
+
[(1, "A"), (1, "B"), (2, "A"), (2, "B")],
|
| 200 |
+
dtype=[("num", int), ("let", "S1")],
|
| 201 |
+
),
|
| 202 |
+
None,
|
| 203 |
+
),
|
| 204 |
+
(
|
| 205 |
+
"union",
|
| 206 |
+
np.array(
|
| 207 |
+
[(1, "A"), (1, "B"), (1, "C"), (2, "A"), (2, "B"), (2, "C")],
|
| 208 |
+
dtype=[("num", int), ("let", "S1")],
|
| 209 |
+
),
|
| 210 |
+
None,
|
| 211 |
+
),
|
| 212 |
+
],
|
| 213 |
+
)
|
| 214 |
+
def test_tuple_union_bug(self, method, expected, sort):
|
| 215 |
+
index1 = Index(
|
| 216 |
+
np.array(
|
| 217 |
+
[(1, "A"), (2, "A"), (1, "B"), (2, "B")],
|
| 218 |
+
dtype=[("num", int), ("let", "S1")],
|
| 219 |
+
)
|
| 220 |
+
)
|
| 221 |
+
index2 = Index(
|
| 222 |
+
np.array(
|
| 223 |
+
[(1, "A"), (2, "A"), (1, "B"), (2, "B"), (1, "C"), (2, "C")],
|
| 224 |
+
dtype=[("num", int), ("let", "S1")],
|
| 225 |
+
)
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
result = getattr(index1, method)(index2, sort=sort)
|
| 229 |
+
assert result.ndim == 1
|
| 230 |
+
|
| 231 |
+
expected = Index(expected)
|
| 232 |
+
tm.assert_index_equal(result, expected)
|
| 233 |
+
|
| 234 |
+
@pytest.mark.parametrize("first_list", [["b", "a"], []])
|
| 235 |
+
@pytest.mark.parametrize("second_list", [["a", "b"], []])
|
| 236 |
+
@pytest.mark.parametrize(
|
| 237 |
+
"first_name, second_name, expected_name",
|
| 238 |
+
[("A", "B", None), (None, "B", None), ("A", None, None)],
|
| 239 |
+
)
|
| 240 |
+
def test_union_name_preservation(
|
| 241 |
+
self, first_list, second_list, first_name, second_name, expected_name, sort
|
| 242 |
+
):
|
| 243 |
+
first = Index(first_list, name=first_name)
|
| 244 |
+
second = Index(second_list, name=second_name)
|
| 245 |
+
union = first.union(second, sort=sort)
|
| 246 |
+
|
| 247 |
+
vals = set(first_list).union(second_list)
|
| 248 |
+
|
| 249 |
+
if sort is None and len(first_list) > 0 and len(second_list) > 0:
|
| 250 |
+
expected = Index(sorted(vals), name=expected_name)
|
| 251 |
+
tm.assert_index_equal(union, expected)
|
| 252 |
+
else:
|
| 253 |
+
expected = Index(vals, name=expected_name)
|
| 254 |
+
tm.assert_index_equal(union.sort_values(), expected.sort_values())
|
| 255 |
+
|
| 256 |
+
@pytest.mark.parametrize(
|
| 257 |
+
"diff_type, expected",
|
| 258 |
+
[["difference", [1, "B"]], ["symmetric_difference", [1, 2, "B", "C"]]],
|
| 259 |
+
)
|
| 260 |
+
def test_difference_object_type(self, diff_type, expected):
|
| 261 |
+
# GH 13432
|
| 262 |
+
idx1 = Index([0, 1, "A", "B"])
|
| 263 |
+
idx2 = Index([0, 2, "A", "C"])
|
| 264 |
+
result = getattr(idx1, diff_type)(idx2)
|
| 265 |
+
expected = Index(expected)
|
| 266 |
+
tm.assert_index_equal(result, expected)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/base_class/test_where.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas import Index
|
| 4 |
+
import pandas._testing as tm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestWhere:
|
| 8 |
+
def test_where_intlike_str_doesnt_cast_ints(self):
|
| 9 |
+
idx = Index(range(3))
|
| 10 |
+
mask = np.array([True, False, True])
|
| 11 |
+
res = idx.where(mask, "2")
|
| 12 |
+
expected = Index([0, "2", 2])
|
| 13 |
+
tm.assert_index_equal(res, expected)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (184 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_astype.cpython-310.pyc
ADDED
|
Binary file (2.34 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_constructors.cpython-310.pyc
ADDED
|
Binary file (3.89 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_fillna.cpython-310.pyc
ADDED
|
Binary file (1.81 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_formats.cpython-310.pyc
ADDED
|
Binary file (5.37 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_indexing.cpython-310.pyc
ADDED
|
Binary file (13 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/__pycache__/test_reindex.cpython-310.pyc
ADDED
|
Binary file (3.18 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/categorical/test_reindex.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas import (
|
| 5 |
+
Categorical,
|
| 6 |
+
CategoricalIndex,
|
| 7 |
+
Index,
|
| 8 |
+
Interval,
|
| 9 |
+
)
|
| 10 |
+
import pandas._testing as tm
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestReindex:
|
| 14 |
+
def test_reindex_list_non_unique(self):
|
| 15 |
+
# GH#11586
|
| 16 |
+
msg = "cannot reindex on an axis with duplicate labels"
|
| 17 |
+
ci = CategoricalIndex(["a", "b", "c", "a"])
|
| 18 |
+
with pytest.raises(ValueError, match=msg):
|
| 19 |
+
ci.reindex(["a", "c"])
|
| 20 |
+
|
| 21 |
+
def test_reindex_categorical_non_unique(self):
|
| 22 |
+
msg = "cannot reindex on an axis with duplicate labels"
|
| 23 |
+
ci = CategoricalIndex(["a", "b", "c", "a"])
|
| 24 |
+
with pytest.raises(ValueError, match=msg):
|
| 25 |
+
ci.reindex(Categorical(["a", "c"]))
|
| 26 |
+
|
| 27 |
+
def test_reindex_list_non_unique_unused_category(self):
|
| 28 |
+
msg = "cannot reindex on an axis with duplicate labels"
|
| 29 |
+
ci = CategoricalIndex(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
|
| 30 |
+
with pytest.raises(ValueError, match=msg):
|
| 31 |
+
ci.reindex(["a", "c"])
|
| 32 |
+
|
| 33 |
+
def test_reindex_categorical_non_unique_unused_category(self):
|
| 34 |
+
msg = "cannot reindex on an axis with duplicate labels"
|
| 35 |
+
ci = CategoricalIndex(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
|
| 36 |
+
with pytest.raises(ValueError, match=msg):
|
| 37 |
+
ci.reindex(Categorical(["a", "c"]))
|
| 38 |
+
|
| 39 |
+
def test_reindex_duplicate_target(self):
|
| 40 |
+
# See GH25459
|
| 41 |
+
cat = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c", "d"])
|
| 42 |
+
res, indexer = cat.reindex(["a", "c", "c"])
|
| 43 |
+
exp = Index(["a", "c", "c"])
|
| 44 |
+
tm.assert_index_equal(res, exp, exact=True)
|
| 45 |
+
tm.assert_numpy_array_equal(indexer, np.array([0, 2, 2], dtype=np.intp))
|
| 46 |
+
|
| 47 |
+
res, indexer = cat.reindex(
|
| 48 |
+
CategoricalIndex(["a", "c", "c"], categories=["a", "b", "c", "d"])
|
| 49 |
+
)
|
| 50 |
+
exp = CategoricalIndex(["a", "c", "c"], categories=["a", "b", "c", "d"])
|
| 51 |
+
tm.assert_index_equal(res, exp, exact=True)
|
| 52 |
+
tm.assert_numpy_array_equal(indexer, np.array([0, 2, 2], dtype=np.intp))
|
| 53 |
+
|
| 54 |
+
def test_reindex_empty_index(self):
|
| 55 |
+
# See GH16770
|
| 56 |
+
c = CategoricalIndex([])
|
| 57 |
+
res, indexer = c.reindex(["a", "b"])
|
| 58 |
+
tm.assert_index_equal(res, Index(["a", "b"]), exact=True)
|
| 59 |
+
tm.assert_numpy_array_equal(indexer, np.array([-1, -1], dtype=np.intp))
|
| 60 |
+
|
| 61 |
+
def test_reindex_categorical_added_category(self):
|
| 62 |
+
# GH 42424
|
| 63 |
+
ci = CategoricalIndex(
|
| 64 |
+
[Interval(0, 1, closed="right"), Interval(1, 2, closed="right")],
|
| 65 |
+
ordered=True,
|
| 66 |
+
)
|
| 67 |
+
ci_add = CategoricalIndex(
|
| 68 |
+
[
|
| 69 |
+
Interval(0, 1, closed="right"),
|
| 70 |
+
Interval(1, 2, closed="right"),
|
| 71 |
+
Interval(2, 3, closed="right"),
|
| 72 |
+
Interval(3, 4, closed="right"),
|
| 73 |
+
],
|
| 74 |
+
ordered=True,
|
| 75 |
+
)
|
| 76 |
+
result, _ = ci.reindex(ci_add)
|
| 77 |
+
expected = ci_add
|
| 78 |
+
tm.assert_index_equal(expected, result)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__init__.py
ADDED
|
File without changes
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (186 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_drop_duplicates.cpython-310.pyc
ADDED
|
Binary file (2.94 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_equals.cpython-310.pyc
ADDED
|
Binary file (6.06 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_indexing.cpython-310.pyc
ADDED
|
Binary file (1.4 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_is_monotonic.cpython-310.pyc
ADDED
|
Binary file (1.01 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas import (
|
| 5 |
+
PeriodIndex,
|
| 6 |
+
Series,
|
| 7 |
+
date_range,
|
| 8 |
+
period_range,
|
| 9 |
+
timedelta_range,
|
| 10 |
+
)
|
| 11 |
+
import pandas._testing as tm
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class DropDuplicates:
|
| 15 |
+
def test_drop_duplicates_metadata(self, idx):
|
| 16 |
+
# GH#10115
|
| 17 |
+
result = idx.drop_duplicates()
|
| 18 |
+
tm.assert_index_equal(idx, result)
|
| 19 |
+
assert idx.freq == result.freq
|
| 20 |
+
|
| 21 |
+
idx_dup = idx.append(idx)
|
| 22 |
+
result = idx_dup.drop_duplicates()
|
| 23 |
+
|
| 24 |
+
expected = idx
|
| 25 |
+
if not isinstance(idx, PeriodIndex):
|
| 26 |
+
# freq is reset except for PeriodIndex
|
| 27 |
+
assert idx_dup.freq is None
|
| 28 |
+
assert result.freq is None
|
| 29 |
+
expected = idx._with_freq(None)
|
| 30 |
+
else:
|
| 31 |
+
assert result.freq == expected.freq
|
| 32 |
+
|
| 33 |
+
tm.assert_index_equal(result, expected)
|
| 34 |
+
|
| 35 |
+
@pytest.mark.parametrize(
|
| 36 |
+
"keep, expected, index",
|
| 37 |
+
[
|
| 38 |
+
(
|
| 39 |
+
"first",
|
| 40 |
+
np.concatenate(([False] * 10, [True] * 5)),
|
| 41 |
+
np.arange(0, 10, dtype=np.int64),
|
| 42 |
+
),
|
| 43 |
+
(
|
| 44 |
+
"last",
|
| 45 |
+
np.concatenate(([True] * 5, [False] * 10)),
|
| 46 |
+
np.arange(5, 15, dtype=np.int64),
|
| 47 |
+
),
|
| 48 |
+
(
|
| 49 |
+
False,
|
| 50 |
+
np.concatenate(([True] * 5, [False] * 5, [True] * 5)),
|
| 51 |
+
np.arange(5, 10, dtype=np.int64),
|
| 52 |
+
),
|
| 53 |
+
],
|
| 54 |
+
)
|
| 55 |
+
def test_drop_duplicates(self, keep, expected, index, idx):
|
| 56 |
+
# to check Index/Series compat
|
| 57 |
+
idx = idx.append(idx[:5])
|
| 58 |
+
|
| 59 |
+
tm.assert_numpy_array_equal(idx.duplicated(keep=keep), expected)
|
| 60 |
+
expected = idx[~expected]
|
| 61 |
+
|
| 62 |
+
result = idx.drop_duplicates(keep=keep)
|
| 63 |
+
tm.assert_index_equal(result, expected)
|
| 64 |
+
|
| 65 |
+
result = Series(idx).drop_duplicates(keep=keep)
|
| 66 |
+
expected = Series(expected, index=index)
|
| 67 |
+
tm.assert_series_equal(result, expected)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class TestDropDuplicatesPeriodIndex(DropDuplicates):
|
| 71 |
+
@pytest.fixture(params=["D", "3D", "h", "2h", "min", "2min", "s", "3s"])
|
| 72 |
+
def freq(self, request):
|
| 73 |
+
return request.param
|
| 74 |
+
|
| 75 |
+
@pytest.fixture
|
| 76 |
+
def idx(self, freq):
|
| 77 |
+
return period_range("2011-01-01", periods=10, freq=freq, name="idx")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class TestDropDuplicatesDatetimeIndex(DropDuplicates):
|
| 81 |
+
@pytest.fixture
|
| 82 |
+
def idx(self, freq_sample):
|
| 83 |
+
return date_range("2011-01-01", freq=freq_sample, periods=10, name="idx")
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class TestDropDuplicatesTimedeltaIndex(DropDuplicates):
|
| 87 |
+
@pytest.fixture
|
| 88 |
+
def idx(self, freq_sample):
|
| 89 |
+
return timedelta_range("1 day", periods=10, freq=freq_sample, name="idx")
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/datetimelike_/test_value_counts.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas import (
|
| 4 |
+
DatetimeIndex,
|
| 5 |
+
NaT,
|
| 6 |
+
PeriodIndex,
|
| 7 |
+
Series,
|
| 8 |
+
TimedeltaIndex,
|
| 9 |
+
date_range,
|
| 10 |
+
period_range,
|
| 11 |
+
timedelta_range,
|
| 12 |
+
)
|
| 13 |
+
import pandas._testing as tm
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class TestValueCounts:
|
| 17 |
+
# GH#7735
|
| 18 |
+
|
| 19 |
+
def test_value_counts_unique_datetimeindex(self, tz_naive_fixture):
|
| 20 |
+
tz = tz_naive_fixture
|
| 21 |
+
orig = date_range("2011-01-01 09:00", freq="h", periods=10, tz=tz)
|
| 22 |
+
self._check_value_counts_with_repeats(orig)
|
| 23 |
+
|
| 24 |
+
def test_value_counts_unique_timedeltaindex(self):
|
| 25 |
+
orig = timedelta_range("1 days 09:00:00", freq="h", periods=10)
|
| 26 |
+
self._check_value_counts_with_repeats(orig)
|
| 27 |
+
|
| 28 |
+
def test_value_counts_unique_periodindex(self):
|
| 29 |
+
orig = period_range("2011-01-01 09:00", freq="h", periods=10)
|
| 30 |
+
self._check_value_counts_with_repeats(orig)
|
| 31 |
+
|
| 32 |
+
def _check_value_counts_with_repeats(self, orig):
|
| 33 |
+
# create repeated values, 'n'th element is repeated by n+1 times
|
| 34 |
+
idx = type(orig)(
|
| 35 |
+
np.repeat(orig._values, range(1, len(orig) + 1)), dtype=orig.dtype
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
exp_idx = orig[::-1]
|
| 39 |
+
if not isinstance(exp_idx, PeriodIndex):
|
| 40 |
+
exp_idx = exp_idx._with_freq(None)
|
| 41 |
+
expected = Series(range(10, 0, -1), index=exp_idx, dtype="int64", name="count")
|
| 42 |
+
|
| 43 |
+
for obj in [idx, Series(idx)]:
|
| 44 |
+
tm.assert_series_equal(obj.value_counts(), expected)
|
| 45 |
+
|
| 46 |
+
tm.assert_index_equal(idx.unique(), orig)
|
| 47 |
+
|
| 48 |
+
def test_value_counts_unique_datetimeindex2(self, tz_naive_fixture):
|
| 49 |
+
tz = tz_naive_fixture
|
| 50 |
+
idx = DatetimeIndex(
|
| 51 |
+
[
|
| 52 |
+
"2013-01-01 09:00",
|
| 53 |
+
"2013-01-01 09:00",
|
| 54 |
+
"2013-01-01 09:00",
|
| 55 |
+
"2013-01-01 08:00",
|
| 56 |
+
"2013-01-01 08:00",
|
| 57 |
+
NaT,
|
| 58 |
+
],
|
| 59 |
+
tz=tz,
|
| 60 |
+
)
|
| 61 |
+
self._check_value_counts_dropna(idx)
|
| 62 |
+
|
| 63 |
+
def test_value_counts_unique_timedeltaindex2(self):
|
| 64 |
+
idx = TimedeltaIndex(
|
| 65 |
+
[
|
| 66 |
+
"1 days 09:00:00",
|
| 67 |
+
"1 days 09:00:00",
|
| 68 |
+
"1 days 09:00:00",
|
| 69 |
+
"1 days 08:00:00",
|
| 70 |
+
"1 days 08:00:00",
|
| 71 |
+
NaT,
|
| 72 |
+
]
|
| 73 |
+
)
|
| 74 |
+
self._check_value_counts_dropna(idx)
|
| 75 |
+
|
| 76 |
+
def test_value_counts_unique_periodindex2(self):
|
| 77 |
+
idx = PeriodIndex(
|
| 78 |
+
[
|
| 79 |
+
"2013-01-01 09:00",
|
| 80 |
+
"2013-01-01 09:00",
|
| 81 |
+
"2013-01-01 09:00",
|
| 82 |
+
"2013-01-01 08:00",
|
| 83 |
+
"2013-01-01 08:00",
|
| 84 |
+
NaT,
|
| 85 |
+
],
|
| 86 |
+
freq="h",
|
| 87 |
+
)
|
| 88 |
+
self._check_value_counts_dropna(idx)
|
| 89 |
+
|
| 90 |
+
def _check_value_counts_dropna(self, idx):
|
| 91 |
+
exp_idx = idx[[2, 3]]
|
| 92 |
+
expected = Series([3, 2], index=exp_idx, name="count")
|
| 93 |
+
|
| 94 |
+
for obj in [idx, Series(idx)]:
|
| 95 |
+
tm.assert_series_equal(obj.value_counts(), expected)
|
| 96 |
+
|
| 97 |
+
exp_idx = idx[[2, 3, -1]]
|
| 98 |
+
expected = Series([3, 2, 1], index=exp_idx, name="count")
|
| 99 |
+
|
| 100 |
+
for obj in [idx, Series(idx)]:
|
| 101 |
+
tm.assert_series_equal(obj.value_counts(dropna=False), expected)
|
| 102 |
+
|
| 103 |
+
tm.assert_index_equal(idx.unique(), exp_idx)
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__init__.py
ADDED
|
File without changes
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (181 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_astype.cpython-310.pyc
ADDED
|
Binary file (8.47 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_constructors.cpython-310.pyc
ADDED
|
Binary file (17.9 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_equals.cpython-310.pyc
ADDED
|
Binary file (1.16 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_formats.cpython-310.pyc
ADDED
|
Binary file (3.5 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_indexing.cpython-310.pyc
ADDED
|
Binary file (20.6 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_interval.cpython-310.pyc
ADDED
|
Binary file (23.9 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_interval_range.cpython-310.pyc
ADDED
|
Binary file (9.15 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_interval_tree.cpython-310.pyc
ADDED
|
Binary file (7.29 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_join.cpython-310.pyc
ADDED
|
Binary file (1.38 kB). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_pickle.cpython-310.pyc
ADDED
|
Binary file (837 Bytes). View file
|
|
|
valley/lib/python3.10/site-packages/pandas/tests/indexes/interval/__pycache__/test_setops.cpython-310.pyc
ADDED
|
Binary file (5.26 kB). View file
|
|
|