Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/conftest.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_any_index.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_common.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_datetimelike.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_engines.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_frozen.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_index_new.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_indexing.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_numpy_compat.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_old_base.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_setops.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_subclass.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__init__.py +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_constructors.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_indexing.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_setops.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_constructors.py +80 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_formats.py +163 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_indexing.py +104 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_pickle.py +11 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_reshape.py +95 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_setops.py +266 -0
- lib/python3.12/site-packages/pandas/tests/indexes/base_class/test_where.py +13 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__init__.py +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_drop_duplicates.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_equals.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_indexing.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_is_monotonic.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_nat.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_sort_values.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_value_counts.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py +89 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_equals.py +181 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_indexing.py +45 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_is_monotonic.py +46 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_nat.py +53 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_sort_values.py +315 -0
- lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_value_counts.py +103 -0
- lib/python3.12/site-packages/pandas/tests/indexes/interval/__init__.py +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/interval/__pycache__/__init__.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/interval/__pycache__/test_astype.cpython-312.pyc +0 -0
- lib/python3.12/site-packages/pandas/tests/indexes/interval/__pycache__/test_constructors.cpython-312.pyc +0 -0
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (199 Bytes). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/conftest.cpython-312.pyc
ADDED
|
Binary file (1.6 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_any_index.cpython-312.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-312.pyc
ADDED
|
Binary file (93.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_common.cpython-312.pyc
ADDED
|
Binary file (23.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_datetimelike.cpython-312.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_engines.cpython-312.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_frozen.cpython-312.pyc
ADDED
|
Binary file (6.07 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_index_new.cpython-312.pyc
ADDED
|
Binary file (25.1 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_indexing.cpython-312.pyc
ADDED
|
Binary file (19.3 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_numpy_compat.cpython-312.pyc
ADDED
|
Binary file (9.37 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_old_base.cpython-312.pyc
ADDED
|
Binary file (56.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_setops.cpython-312.pyc
ADDED
|
Binary file (44.9 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/__pycache__/test_subclass.cpython-312.pyc
ADDED
|
Binary file (2.21 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__init__.py
ADDED
|
File without changes
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (210 Bytes). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_constructors.cpython-312.pyc
ADDED
|
Binary file (5.27 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_formats.cpython-312.pyc
ADDED
|
Binary file (6.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_indexing.cpython-312.pyc
ADDED
|
Binary file (7.3 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_pickle.cpython-312.pyc
ADDED
|
Binary file (751 Bytes). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_reshape.cpython-312.pyc
ADDED
|
Binary file (5.67 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_setops.cpython-312.pyc
ADDED
|
Binary file (13.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/base_class/__pycache__/test_where.cpython-312.pyc
ADDED
|
Binary file (1.05 kB). View file
|
|
|
lib/python3.12/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
|
lib/python3.12/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
|
lib/python3.12/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)
|
lib/python3.12/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)
|
lib/python3.12/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)
|
lib/python3.12/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)
|
lib/python3.12/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)
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__init__.py
ADDED
|
File without changes
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (213 Bytes). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_drop_duplicates.cpython-312.pyc
ADDED
|
Binary file (4.66 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_equals.cpython-312.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_indexing.cpython-312.pyc
ADDED
|
Binary file (2.61 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_is_monotonic.cpython-312.pyc
ADDED
|
Binary file (2.18 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_nat.cpython-312.pyc
ADDED
|
Binary file (2.92 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_sort_values.cpython-312.pyc
ADDED
|
Binary file (12.8 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/__pycache__/test_value_counts.cpython-312.pyc
ADDED
|
Binary file (4.71 kB). View file
|
|
|
lib/python3.12/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")
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_equals.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests shared for DatetimeIndex/TimedeltaIndex/PeriodIndex
|
| 3 |
+
"""
|
| 4 |
+
from datetime import (
|
| 5 |
+
datetime,
|
| 6 |
+
timedelta,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
import pandas as pd
|
| 13 |
+
from pandas import (
|
| 14 |
+
CategoricalIndex,
|
| 15 |
+
DatetimeIndex,
|
| 16 |
+
Index,
|
| 17 |
+
PeriodIndex,
|
| 18 |
+
TimedeltaIndex,
|
| 19 |
+
date_range,
|
| 20 |
+
period_range,
|
| 21 |
+
timedelta_range,
|
| 22 |
+
)
|
| 23 |
+
import pandas._testing as tm
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class EqualsTests:
|
| 27 |
+
def test_not_equals_numeric(self, index):
|
| 28 |
+
assert not index.equals(Index(index.asi8))
|
| 29 |
+
assert not index.equals(Index(index.asi8.astype("u8")))
|
| 30 |
+
assert not index.equals(Index(index.asi8).astype("f8"))
|
| 31 |
+
|
| 32 |
+
def test_equals(self, index):
|
| 33 |
+
assert index.equals(index)
|
| 34 |
+
assert index.equals(index.astype(object))
|
| 35 |
+
assert index.equals(CategoricalIndex(index))
|
| 36 |
+
assert index.equals(CategoricalIndex(index.astype(object)))
|
| 37 |
+
|
| 38 |
+
def test_not_equals_non_arraylike(self, index):
|
| 39 |
+
assert not index.equals(list(index))
|
| 40 |
+
|
| 41 |
+
def test_not_equals_strings(self, index):
|
| 42 |
+
other = Index([str(x) for x in index], dtype=object)
|
| 43 |
+
assert not index.equals(other)
|
| 44 |
+
assert not index.equals(CategoricalIndex(other))
|
| 45 |
+
|
| 46 |
+
def test_not_equals_misc_strs(self, index):
|
| 47 |
+
other = Index(list("abc"))
|
| 48 |
+
assert not index.equals(other)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class TestPeriodIndexEquals(EqualsTests):
|
| 52 |
+
@pytest.fixture
|
| 53 |
+
def index(self):
|
| 54 |
+
return period_range("2013-01-01", periods=5, freq="D")
|
| 55 |
+
|
| 56 |
+
# TODO: de-duplicate with other test_equals2 methods
|
| 57 |
+
@pytest.mark.parametrize("freq", ["D", "M"])
|
| 58 |
+
def test_equals2(self, freq):
|
| 59 |
+
# GH#13107
|
| 60 |
+
idx = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq=freq)
|
| 61 |
+
assert idx.equals(idx)
|
| 62 |
+
assert idx.equals(idx.copy())
|
| 63 |
+
assert idx.equals(idx.astype(object))
|
| 64 |
+
assert idx.astype(object).equals(idx)
|
| 65 |
+
assert idx.astype(object).equals(idx.astype(object))
|
| 66 |
+
assert not idx.equals(list(idx))
|
| 67 |
+
assert not idx.equals(pd.Series(idx))
|
| 68 |
+
|
| 69 |
+
idx2 = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq="h")
|
| 70 |
+
assert not idx.equals(idx2)
|
| 71 |
+
assert not idx.equals(idx2.copy())
|
| 72 |
+
assert not idx.equals(idx2.astype(object))
|
| 73 |
+
assert not idx.astype(object).equals(idx2)
|
| 74 |
+
assert not idx.equals(list(idx2))
|
| 75 |
+
assert not idx.equals(pd.Series(idx2))
|
| 76 |
+
|
| 77 |
+
# same internal, different tz
|
| 78 |
+
idx3 = PeriodIndex._simple_new(
|
| 79 |
+
idx._values._simple_new(idx._values.asi8, dtype=pd.PeriodDtype("h"))
|
| 80 |
+
)
|
| 81 |
+
tm.assert_numpy_array_equal(idx.asi8, idx3.asi8)
|
| 82 |
+
assert not idx.equals(idx3)
|
| 83 |
+
assert not idx.equals(idx3.copy())
|
| 84 |
+
assert not idx.equals(idx3.astype(object))
|
| 85 |
+
assert not idx.astype(object).equals(idx3)
|
| 86 |
+
assert not idx.equals(list(idx3))
|
| 87 |
+
assert not idx.equals(pd.Series(idx3))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class TestDatetimeIndexEquals(EqualsTests):
|
| 91 |
+
@pytest.fixture
|
| 92 |
+
def index(self):
|
| 93 |
+
return date_range("2013-01-01", periods=5)
|
| 94 |
+
|
| 95 |
+
def test_equals2(self):
|
| 96 |
+
# GH#13107
|
| 97 |
+
idx = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"])
|
| 98 |
+
assert idx.equals(idx)
|
| 99 |
+
assert idx.equals(idx.copy())
|
| 100 |
+
assert idx.equals(idx.astype(object))
|
| 101 |
+
assert idx.astype(object).equals(idx)
|
| 102 |
+
assert idx.astype(object).equals(idx.astype(object))
|
| 103 |
+
assert not idx.equals(list(idx))
|
| 104 |
+
assert not idx.equals(pd.Series(idx))
|
| 105 |
+
|
| 106 |
+
idx2 = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"], tz="US/Pacific")
|
| 107 |
+
assert not idx.equals(idx2)
|
| 108 |
+
assert not idx.equals(idx2.copy())
|
| 109 |
+
assert not idx.equals(idx2.astype(object))
|
| 110 |
+
assert not idx.astype(object).equals(idx2)
|
| 111 |
+
assert not idx.equals(list(idx2))
|
| 112 |
+
assert not idx.equals(pd.Series(idx2))
|
| 113 |
+
|
| 114 |
+
# same internal, different tz
|
| 115 |
+
idx3 = DatetimeIndex(idx.asi8, tz="US/Pacific")
|
| 116 |
+
tm.assert_numpy_array_equal(idx.asi8, idx3.asi8)
|
| 117 |
+
assert not idx.equals(idx3)
|
| 118 |
+
assert not idx.equals(idx3.copy())
|
| 119 |
+
assert not idx.equals(idx3.astype(object))
|
| 120 |
+
assert not idx.astype(object).equals(idx3)
|
| 121 |
+
assert not idx.equals(list(idx3))
|
| 122 |
+
assert not idx.equals(pd.Series(idx3))
|
| 123 |
+
|
| 124 |
+
# check that we do not raise when comparing with OutOfBounds objects
|
| 125 |
+
oob = Index([datetime(2500, 1, 1)] * 3, dtype=object)
|
| 126 |
+
assert not idx.equals(oob)
|
| 127 |
+
assert not idx2.equals(oob)
|
| 128 |
+
assert not idx3.equals(oob)
|
| 129 |
+
|
| 130 |
+
# check that we do not raise when comparing with OutOfBounds dt64
|
| 131 |
+
oob2 = oob.map(np.datetime64)
|
| 132 |
+
assert not idx.equals(oob2)
|
| 133 |
+
assert not idx2.equals(oob2)
|
| 134 |
+
assert not idx3.equals(oob2)
|
| 135 |
+
|
| 136 |
+
@pytest.mark.parametrize("freq", ["B", "C"])
|
| 137 |
+
def test_not_equals_bday(self, freq):
|
| 138 |
+
rng = date_range("2009-01-01", "2010-01-01", freq=freq)
|
| 139 |
+
assert not rng.equals(list(rng))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class TestTimedeltaIndexEquals(EqualsTests):
|
| 143 |
+
@pytest.fixture
|
| 144 |
+
def index(self):
|
| 145 |
+
return timedelta_range("1 day", periods=10)
|
| 146 |
+
|
| 147 |
+
def test_equals2(self):
|
| 148 |
+
# GH#13107
|
| 149 |
+
idx = TimedeltaIndex(["1 days", "2 days", "NaT"])
|
| 150 |
+
assert idx.equals(idx)
|
| 151 |
+
assert idx.equals(idx.copy())
|
| 152 |
+
assert idx.equals(idx.astype(object))
|
| 153 |
+
assert idx.astype(object).equals(idx)
|
| 154 |
+
assert idx.astype(object).equals(idx.astype(object))
|
| 155 |
+
assert not idx.equals(list(idx))
|
| 156 |
+
assert not idx.equals(pd.Series(idx))
|
| 157 |
+
|
| 158 |
+
idx2 = TimedeltaIndex(["2 days", "1 days", "NaT"])
|
| 159 |
+
assert not idx.equals(idx2)
|
| 160 |
+
assert not idx.equals(idx2.copy())
|
| 161 |
+
assert not idx.equals(idx2.astype(object))
|
| 162 |
+
assert not idx.astype(object).equals(idx2)
|
| 163 |
+
assert not idx.astype(object).equals(idx2.astype(object))
|
| 164 |
+
assert not idx.equals(list(idx2))
|
| 165 |
+
assert not idx.equals(pd.Series(idx2))
|
| 166 |
+
|
| 167 |
+
# Check that we dont raise OverflowError on comparisons outside the
|
| 168 |
+
# implementation range GH#28532
|
| 169 |
+
oob = Index([timedelta(days=10**6)] * 3, dtype=object)
|
| 170 |
+
assert not idx.equals(oob)
|
| 171 |
+
assert not idx2.equals(oob)
|
| 172 |
+
|
| 173 |
+
oob2 = Index([np.timedelta64(x) for x in oob], dtype=object)
|
| 174 |
+
assert (oob == oob2).all()
|
| 175 |
+
assert not idx.equals(oob2)
|
| 176 |
+
assert not idx2.equals(oob2)
|
| 177 |
+
|
| 178 |
+
oob3 = oob.map(np.timedelta64)
|
| 179 |
+
assert (oob3 == oob).all()
|
| 180 |
+
assert not idx.equals(oob3)
|
| 181 |
+
assert not idx2.equals(oob3)
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_indexing.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from pandas import (
|
| 6 |
+
DatetimeIndex,
|
| 7 |
+
Index,
|
| 8 |
+
)
|
| 9 |
+
import pandas._testing as tm
|
| 10 |
+
|
| 11 |
+
dtlike_dtypes = [
|
| 12 |
+
np.dtype("timedelta64[ns]"),
|
| 13 |
+
np.dtype("datetime64[ns]"),
|
| 14 |
+
pd.DatetimeTZDtype("ns", "Asia/Tokyo"),
|
| 15 |
+
pd.PeriodDtype("ns"),
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("ldtype", dtlike_dtypes)
|
| 20 |
+
@pytest.mark.parametrize("rdtype", dtlike_dtypes)
|
| 21 |
+
def test_get_indexer_non_unique_wrong_dtype(ldtype, rdtype):
|
| 22 |
+
vals = np.tile(3600 * 10**9 * np.arange(3, dtype=np.int64), 2)
|
| 23 |
+
|
| 24 |
+
def construct(dtype):
|
| 25 |
+
if dtype is dtlike_dtypes[-1]:
|
| 26 |
+
# PeriodArray will try to cast ints to strings
|
| 27 |
+
return DatetimeIndex(vals).astype(dtype)
|
| 28 |
+
return Index(vals, dtype=dtype)
|
| 29 |
+
|
| 30 |
+
left = construct(ldtype)
|
| 31 |
+
right = construct(rdtype)
|
| 32 |
+
|
| 33 |
+
result = left.get_indexer_non_unique(right)
|
| 34 |
+
|
| 35 |
+
if ldtype is rdtype:
|
| 36 |
+
ex1 = np.array([0, 3, 1, 4, 2, 5] * 2, dtype=np.intp)
|
| 37 |
+
ex2 = np.array([], dtype=np.intp)
|
| 38 |
+
tm.assert_numpy_array_equal(result[0], ex1)
|
| 39 |
+
tm.assert_numpy_array_equal(result[1], ex2)
|
| 40 |
+
|
| 41 |
+
else:
|
| 42 |
+
no_matches = np.array([-1] * 6, dtype=np.intp)
|
| 43 |
+
missing = np.arange(6, dtype=np.intp)
|
| 44 |
+
tm.assert_numpy_array_equal(result[0], no_matches)
|
| 45 |
+
tm.assert_numpy_array_equal(result[1], missing)
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_is_monotonic.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pandas import (
|
| 2 |
+
Index,
|
| 3 |
+
NaT,
|
| 4 |
+
date_range,
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_is_monotonic_with_nat():
|
| 9 |
+
# GH#31437
|
| 10 |
+
# PeriodIndex.is_monotonic_increasing should behave analogously to DatetimeIndex,
|
| 11 |
+
# in particular never be monotonic when we have NaT
|
| 12 |
+
dti = date_range("2016-01-01", periods=3)
|
| 13 |
+
pi = dti.to_period("D")
|
| 14 |
+
tdi = Index(dti.view("timedelta64[ns]"))
|
| 15 |
+
|
| 16 |
+
for obj in [pi, pi._engine, dti, dti._engine, tdi, tdi._engine]:
|
| 17 |
+
if isinstance(obj, Index):
|
| 18 |
+
# i.e. not Engines
|
| 19 |
+
assert obj.is_monotonic_increasing
|
| 20 |
+
assert obj.is_monotonic_increasing
|
| 21 |
+
assert not obj.is_monotonic_decreasing
|
| 22 |
+
assert obj.is_unique
|
| 23 |
+
|
| 24 |
+
dti1 = dti.insert(0, NaT)
|
| 25 |
+
pi1 = dti1.to_period("D")
|
| 26 |
+
tdi1 = Index(dti1.view("timedelta64[ns]"))
|
| 27 |
+
|
| 28 |
+
for obj in [pi1, pi1._engine, dti1, dti1._engine, tdi1, tdi1._engine]:
|
| 29 |
+
if isinstance(obj, Index):
|
| 30 |
+
# i.e. not Engines
|
| 31 |
+
assert not obj.is_monotonic_increasing
|
| 32 |
+
assert not obj.is_monotonic_increasing
|
| 33 |
+
assert not obj.is_monotonic_decreasing
|
| 34 |
+
assert obj.is_unique
|
| 35 |
+
|
| 36 |
+
dti2 = dti.insert(3, NaT)
|
| 37 |
+
pi2 = dti2.to_period("h")
|
| 38 |
+
tdi2 = Index(dti2.view("timedelta64[ns]"))
|
| 39 |
+
|
| 40 |
+
for obj in [pi2, pi2._engine, dti2, dti2._engine, tdi2, tdi2._engine]:
|
| 41 |
+
if isinstance(obj, Index):
|
| 42 |
+
# i.e. not Engines
|
| 43 |
+
assert not obj.is_monotonic_increasing
|
| 44 |
+
assert not obj.is_monotonic_increasing
|
| 45 |
+
assert not obj.is_monotonic_decreasing
|
| 46 |
+
assert obj.is_unique
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_nat.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas import (
|
| 5 |
+
DatetimeIndex,
|
| 6 |
+
NaT,
|
| 7 |
+
PeriodIndex,
|
| 8 |
+
TimedeltaIndex,
|
| 9 |
+
)
|
| 10 |
+
import pandas._testing as tm
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class NATests:
|
| 14 |
+
def test_nat(self, index_without_na):
|
| 15 |
+
empty_index = index_without_na[:0]
|
| 16 |
+
|
| 17 |
+
index_with_na = index_without_na.copy(deep=True)
|
| 18 |
+
index_with_na._data[1] = NaT
|
| 19 |
+
|
| 20 |
+
assert empty_index._na_value is NaT
|
| 21 |
+
assert index_with_na._na_value is NaT
|
| 22 |
+
assert index_without_na._na_value is NaT
|
| 23 |
+
|
| 24 |
+
idx = index_without_na
|
| 25 |
+
assert idx._can_hold_na
|
| 26 |
+
|
| 27 |
+
tm.assert_numpy_array_equal(idx._isnan, np.array([False, False]))
|
| 28 |
+
assert idx.hasnans is False
|
| 29 |
+
|
| 30 |
+
idx = index_with_na
|
| 31 |
+
assert idx._can_hold_na
|
| 32 |
+
|
| 33 |
+
tm.assert_numpy_array_equal(idx._isnan, np.array([False, True]))
|
| 34 |
+
assert idx.hasnans is True
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class TestDatetimeIndexNA(NATests):
|
| 38 |
+
@pytest.fixture
|
| 39 |
+
def index_without_na(self, tz_naive_fixture):
|
| 40 |
+
tz = tz_naive_fixture
|
| 41 |
+
return DatetimeIndex(["2011-01-01", "2011-01-02"], tz=tz)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class TestTimedeltaIndexNA(NATests):
|
| 45 |
+
@pytest.fixture
|
| 46 |
+
def index_without_na(self):
|
| 47 |
+
return TimedeltaIndex(["1 days", "2 days"])
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class TestPeriodIndexNA(NATests):
|
| 51 |
+
@pytest.fixture
|
| 52 |
+
def index_without_na(self):
|
| 53 |
+
return PeriodIndex(["2011-01-01", "2011-01-02"], freq="D")
|
lib/python3.12/site-packages/pandas/tests/indexes/datetimelike_/test_sort_values.py
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas import (
|
| 5 |
+
DatetimeIndex,
|
| 6 |
+
Index,
|
| 7 |
+
NaT,
|
| 8 |
+
PeriodIndex,
|
| 9 |
+
TimedeltaIndex,
|
| 10 |
+
timedelta_range,
|
| 11 |
+
)
|
| 12 |
+
import pandas._testing as tm
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def check_freq_ascending(ordered, orig, ascending):
|
| 16 |
+
"""
|
| 17 |
+
Check the expected freq on a PeriodIndex/DatetimeIndex/TimedeltaIndex
|
| 18 |
+
when the original index is generated (or generate-able) with
|
| 19 |
+
period_range/date_range/timedelta_range.
|
| 20 |
+
"""
|
| 21 |
+
if isinstance(ordered, PeriodIndex):
|
| 22 |
+
assert ordered.freq == orig.freq
|
| 23 |
+
elif isinstance(ordered, (DatetimeIndex, TimedeltaIndex)):
|
| 24 |
+
if ascending:
|
| 25 |
+
assert ordered.freq.n == orig.freq.n
|
| 26 |
+
else:
|
| 27 |
+
assert ordered.freq.n == -1 * orig.freq.n
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def check_freq_nonmonotonic(ordered, orig):
|
| 31 |
+
"""
|
| 32 |
+
Check the expected freq on a PeriodIndex/DatetimeIndex/TimedeltaIndex
|
| 33 |
+
when the original index is _not_ generated (or generate-able) with
|
| 34 |
+
period_range/date_range//timedelta_range.
|
| 35 |
+
"""
|
| 36 |
+
if isinstance(ordered, PeriodIndex):
|
| 37 |
+
assert ordered.freq == orig.freq
|
| 38 |
+
elif isinstance(ordered, (DatetimeIndex, TimedeltaIndex)):
|
| 39 |
+
assert ordered.freq is None
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class TestSortValues:
|
| 43 |
+
@pytest.fixture(params=[DatetimeIndex, TimedeltaIndex, PeriodIndex])
|
| 44 |
+
def non_monotonic_idx(self, request):
|
| 45 |
+
if request.param is DatetimeIndex:
|
| 46 |
+
return DatetimeIndex(["2000-01-04", "2000-01-01", "2000-01-02"])
|
| 47 |
+
elif request.param is PeriodIndex:
|
| 48 |
+
dti = DatetimeIndex(["2000-01-04", "2000-01-01", "2000-01-02"])
|
| 49 |
+
return dti.to_period("D")
|
| 50 |
+
else:
|
| 51 |
+
return TimedeltaIndex(
|
| 52 |
+
["1 day 00:00:05", "1 day 00:00:01", "1 day 00:00:02"]
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
def test_argmin_argmax(self, non_monotonic_idx):
|
| 56 |
+
assert non_monotonic_idx.argmin() == 1
|
| 57 |
+
assert non_monotonic_idx.argmax() == 0
|
| 58 |
+
|
| 59 |
+
def test_sort_values(self, non_monotonic_idx):
|
| 60 |
+
idx = non_monotonic_idx
|
| 61 |
+
ordered = idx.sort_values()
|
| 62 |
+
assert ordered.is_monotonic_increasing
|
| 63 |
+
ordered = idx.sort_values(ascending=False)
|
| 64 |
+
assert ordered[::-1].is_monotonic_increasing
|
| 65 |
+
|
| 66 |
+
ordered, dexer = idx.sort_values(return_indexer=True)
|
| 67 |
+
assert ordered.is_monotonic_increasing
|
| 68 |
+
tm.assert_numpy_array_equal(dexer, np.array([1, 2, 0], dtype=np.intp))
|
| 69 |
+
|
| 70 |
+
ordered, dexer = idx.sort_values(return_indexer=True, ascending=False)
|
| 71 |
+
assert ordered[::-1].is_monotonic_increasing
|
| 72 |
+
tm.assert_numpy_array_equal(dexer, np.array([0, 2, 1], dtype=np.intp))
|
| 73 |
+
|
| 74 |
+
def check_sort_values_with_freq(self, idx):
|
| 75 |
+
ordered = idx.sort_values()
|
| 76 |
+
tm.assert_index_equal(ordered, idx)
|
| 77 |
+
check_freq_ascending(ordered, idx, True)
|
| 78 |
+
|
| 79 |
+
ordered = idx.sort_values(ascending=False)
|
| 80 |
+
expected = idx[::-1]
|
| 81 |
+
tm.assert_index_equal(ordered, expected)
|
| 82 |
+
check_freq_ascending(ordered, idx, False)
|
| 83 |
+
|
| 84 |
+
ordered, indexer = idx.sort_values(return_indexer=True)
|
| 85 |
+
tm.assert_index_equal(ordered, idx)
|
| 86 |
+
tm.assert_numpy_array_equal(indexer, np.array([0, 1, 2], dtype=np.intp))
|
| 87 |
+
check_freq_ascending(ordered, idx, True)
|
| 88 |
+
|
| 89 |
+
ordered, indexer = idx.sort_values(return_indexer=True, ascending=False)
|
| 90 |
+
expected = idx[::-1]
|
| 91 |
+
tm.assert_index_equal(ordered, expected)
|
| 92 |
+
tm.assert_numpy_array_equal(indexer, np.array([2, 1, 0], dtype=np.intp))
|
| 93 |
+
check_freq_ascending(ordered, idx, False)
|
| 94 |
+
|
| 95 |
+
@pytest.mark.parametrize("freq", ["D", "h"])
|
| 96 |
+
def test_sort_values_with_freq_timedeltaindex(self, freq):
|
| 97 |
+
# GH#10295
|
| 98 |
+
idx = timedelta_range(start=f"1{freq}", periods=3, freq=freq).rename("idx")
|
| 99 |
+
|
| 100 |
+
self.check_sort_values_with_freq(idx)
|
| 101 |
+
|
| 102 |
+
@pytest.mark.parametrize(
|
| 103 |
+
"idx",
|
| 104 |
+
[
|
| 105 |
+
DatetimeIndex(
|
| 106 |
+
["2011-01-01", "2011-01-02", "2011-01-03"], freq="D", name="idx"
|
| 107 |
+
),
|
| 108 |
+
DatetimeIndex(
|
| 109 |
+
["2011-01-01 09:00", "2011-01-01 10:00", "2011-01-01 11:00"],
|
| 110 |
+
freq="h",
|
| 111 |
+
name="tzidx",
|
| 112 |
+
tz="Asia/Tokyo",
|
| 113 |
+
),
|
| 114 |
+
],
|
| 115 |
+
)
|
| 116 |
+
def test_sort_values_with_freq_datetimeindex(self, idx):
|
| 117 |
+
self.check_sort_values_with_freq(idx)
|
| 118 |
+
|
| 119 |
+
@pytest.mark.parametrize("freq", ["D", "2D", "4D"])
|
| 120 |
+
def test_sort_values_with_freq_periodindex(self, freq):
|
| 121 |
+
# here with_freq refers to being period_range-like
|
| 122 |
+
idx = PeriodIndex(
|
| 123 |
+
["2011-01-01", "2011-01-02", "2011-01-03"], freq=freq, name="idx"
|
| 124 |
+
)
|
| 125 |
+
self.check_sort_values_with_freq(idx)
|
| 126 |
+
|
| 127 |
+
@pytest.mark.parametrize(
|
| 128 |
+
"idx",
|
| 129 |
+
[
|
| 130 |
+
PeriodIndex(["2011", "2012", "2013"], name="pidx", freq="Y"),
|
| 131 |
+
Index([2011, 2012, 2013], name="idx"), # for compatibility check
|
| 132 |
+
],
|
| 133 |
+
)
|
| 134 |
+
def test_sort_values_with_freq_periodindex2(self, idx):
|
| 135 |
+
# here with_freq indicates this is period_range-like
|
| 136 |
+
self.check_sort_values_with_freq(idx)
|
| 137 |
+
|
| 138 |
+
def check_sort_values_without_freq(self, idx, expected):
|
| 139 |
+
ordered = idx.sort_values(na_position="first")
|
| 140 |
+
tm.assert_index_equal(ordered, expected)
|
| 141 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 142 |
+
|
| 143 |
+
if not idx.isna().any():
|
| 144 |
+
ordered = idx.sort_values()
|
| 145 |
+
tm.assert_index_equal(ordered, expected)
|
| 146 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 147 |
+
|
| 148 |
+
ordered = idx.sort_values(ascending=False)
|
| 149 |
+
tm.assert_index_equal(ordered, expected[::-1])
|
| 150 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 151 |
+
|
| 152 |
+
ordered, indexer = idx.sort_values(return_indexer=True, na_position="first")
|
| 153 |
+
tm.assert_index_equal(ordered, expected)
|
| 154 |
+
|
| 155 |
+
exp = np.array([0, 4, 3, 1, 2], dtype=np.intp)
|
| 156 |
+
tm.assert_numpy_array_equal(indexer, exp)
|
| 157 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 158 |
+
|
| 159 |
+
if not idx.isna().any():
|
| 160 |
+
ordered, indexer = idx.sort_values(return_indexer=True)
|
| 161 |
+
tm.assert_index_equal(ordered, expected)
|
| 162 |
+
|
| 163 |
+
exp = np.array([0, 4, 3, 1, 2], dtype=np.intp)
|
| 164 |
+
tm.assert_numpy_array_equal(indexer, exp)
|
| 165 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 166 |
+
|
| 167 |
+
ordered, indexer = idx.sort_values(return_indexer=True, ascending=False)
|
| 168 |
+
tm.assert_index_equal(ordered, expected[::-1])
|
| 169 |
+
|
| 170 |
+
exp = np.array([2, 1, 3, 0, 4], dtype=np.intp)
|
| 171 |
+
tm.assert_numpy_array_equal(indexer, exp)
|
| 172 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 173 |
+
|
| 174 |
+
def test_sort_values_without_freq_timedeltaindex(self):
|
| 175 |
+
# GH#10295
|
| 176 |
+
|
| 177 |
+
idx = TimedeltaIndex(
|
| 178 |
+
["1 hour", "3 hour", "5 hour", "2 hour ", "1 hour"], name="idx1"
|
| 179 |
+
)
|
| 180 |
+
expected = TimedeltaIndex(
|
| 181 |
+
["1 hour", "1 hour", "2 hour", "3 hour", "5 hour"], name="idx1"
|
| 182 |
+
)
|
| 183 |
+
self.check_sort_values_without_freq(idx, expected)
|
| 184 |
+
|
| 185 |
+
@pytest.mark.parametrize(
|
| 186 |
+
"index_dates,expected_dates",
|
| 187 |
+
[
|
| 188 |
+
(
|
| 189 |
+
["2011-01-01", "2011-01-03", "2011-01-05", "2011-01-02", "2011-01-01"],
|
| 190 |
+
["2011-01-01", "2011-01-01", "2011-01-02", "2011-01-03", "2011-01-05"],
|
| 191 |
+
),
|
| 192 |
+
(
|
| 193 |
+
["2011-01-01", "2011-01-03", "2011-01-05", "2011-01-02", "2011-01-01"],
|
| 194 |
+
["2011-01-01", "2011-01-01", "2011-01-02", "2011-01-03", "2011-01-05"],
|
| 195 |
+
),
|
| 196 |
+
(
|
| 197 |
+
[NaT, "2011-01-03", "2011-01-05", "2011-01-02", NaT],
|
| 198 |
+
[NaT, NaT, "2011-01-02", "2011-01-03", "2011-01-05"],
|
| 199 |
+
),
|
| 200 |
+
],
|
| 201 |
+
)
|
| 202 |
+
def test_sort_values_without_freq_datetimeindex(
|
| 203 |
+
self, index_dates, expected_dates, tz_naive_fixture
|
| 204 |
+
):
|
| 205 |
+
tz = tz_naive_fixture
|
| 206 |
+
|
| 207 |
+
# without freq
|
| 208 |
+
idx = DatetimeIndex(index_dates, tz=tz, name="idx")
|
| 209 |
+
expected = DatetimeIndex(expected_dates, tz=tz, name="idx")
|
| 210 |
+
|
| 211 |
+
self.check_sort_values_without_freq(idx, expected)
|
| 212 |
+
|
| 213 |
+
@pytest.mark.parametrize(
|
| 214 |
+
"idx,expected",
|
| 215 |
+
[
|
| 216 |
+
(
|
| 217 |
+
PeriodIndex(
|
| 218 |
+
[
|
| 219 |
+
"2011-01-01",
|
| 220 |
+
"2011-01-03",
|
| 221 |
+
"2011-01-05",
|
| 222 |
+
"2011-01-02",
|
| 223 |
+
"2011-01-01",
|
| 224 |
+
],
|
| 225 |
+
freq="D",
|
| 226 |
+
name="idx1",
|
| 227 |
+
),
|
| 228 |
+
PeriodIndex(
|
| 229 |
+
[
|
| 230 |
+
"2011-01-01",
|
| 231 |
+
"2011-01-01",
|
| 232 |
+
"2011-01-02",
|
| 233 |
+
"2011-01-03",
|
| 234 |
+
"2011-01-05",
|
| 235 |
+
],
|
| 236 |
+
freq="D",
|
| 237 |
+
name="idx1",
|
| 238 |
+
),
|
| 239 |
+
),
|
| 240 |
+
(
|
| 241 |
+
PeriodIndex(
|
| 242 |
+
[
|
| 243 |
+
"2011-01-01",
|
| 244 |
+
"2011-01-03",
|
| 245 |
+
"2011-01-05",
|
| 246 |
+
"2011-01-02",
|
| 247 |
+
"2011-01-01",
|
| 248 |
+
],
|
| 249 |
+
freq="D",
|
| 250 |
+
name="idx2",
|
| 251 |
+
),
|
| 252 |
+
PeriodIndex(
|
| 253 |
+
[
|
| 254 |
+
"2011-01-01",
|
| 255 |
+
"2011-01-01",
|
| 256 |
+
"2011-01-02",
|
| 257 |
+
"2011-01-03",
|
| 258 |
+
"2011-01-05",
|
| 259 |
+
],
|
| 260 |
+
freq="D",
|
| 261 |
+
name="idx2",
|
| 262 |
+
),
|
| 263 |
+
),
|
| 264 |
+
(
|
| 265 |
+
PeriodIndex(
|
| 266 |
+
[NaT, "2011-01-03", "2011-01-05", "2011-01-02", NaT],
|
| 267 |
+
freq="D",
|
| 268 |
+
name="idx3",
|
| 269 |
+
),
|
| 270 |
+
PeriodIndex(
|
| 271 |
+
[NaT, NaT, "2011-01-02", "2011-01-03", "2011-01-05"],
|
| 272 |
+
freq="D",
|
| 273 |
+
name="idx3",
|
| 274 |
+
),
|
| 275 |
+
),
|
| 276 |
+
(
|
| 277 |
+
PeriodIndex(
|
| 278 |
+
["2011", "2013", "2015", "2012", "2011"], name="pidx", freq="Y"
|
| 279 |
+
),
|
| 280 |
+
PeriodIndex(
|
| 281 |
+
["2011", "2011", "2012", "2013", "2015"], name="pidx", freq="Y"
|
| 282 |
+
),
|
| 283 |
+
),
|
| 284 |
+
(
|
| 285 |
+
# For compatibility check
|
| 286 |
+
Index([2011, 2013, 2015, 2012, 2011], name="idx"),
|
| 287 |
+
Index([2011, 2011, 2012, 2013, 2015], name="idx"),
|
| 288 |
+
),
|
| 289 |
+
],
|
| 290 |
+
)
|
| 291 |
+
def test_sort_values_without_freq_periodindex(self, idx, expected):
|
| 292 |
+
# here without_freq means not generateable by period_range
|
| 293 |
+
self.check_sort_values_without_freq(idx, expected)
|
| 294 |
+
|
| 295 |
+
def test_sort_values_without_freq_periodindex_nat(self):
|
| 296 |
+
# doesn't quite fit into check_sort_values_without_freq
|
| 297 |
+
idx = PeriodIndex(["2011", "2013", "NaT", "2011"], name="pidx", freq="D")
|
| 298 |
+
expected = PeriodIndex(["NaT", "2011", "2011", "2013"], name="pidx", freq="D")
|
| 299 |
+
|
| 300 |
+
ordered = idx.sort_values(na_position="first")
|
| 301 |
+
tm.assert_index_equal(ordered, expected)
|
| 302 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 303 |
+
|
| 304 |
+
ordered = idx.sort_values(ascending=False)
|
| 305 |
+
tm.assert_index_equal(ordered, expected[::-1])
|
| 306 |
+
check_freq_nonmonotonic(ordered, idx)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def test_order_stability_compat():
|
| 310 |
+
# GH#35922. sort_values is stable both for normal and datetime-like Index
|
| 311 |
+
pidx = PeriodIndex(["2011", "2013", "2015", "2012", "2011"], name="pidx", freq="Y")
|
| 312 |
+
iidx = Index([2011, 2013, 2015, 2012, 2011], name="idx")
|
| 313 |
+
ordered1, indexer1 = pidx.sort_values(return_indexer=True, ascending=False)
|
| 314 |
+
ordered2, indexer2 = iidx.sort_values(return_indexer=True, ascending=False)
|
| 315 |
+
tm.assert_numpy_array_equal(indexer1, indexer2)
|
lib/python3.12/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)
|
lib/python3.12/site-packages/pandas/tests/indexes/interval/__init__.py
ADDED
|
File without changes
|
lib/python3.12/site-packages/pandas/tests/indexes/interval/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (208 Bytes). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/interval/__pycache__/test_astype.cpython-312.pyc
ADDED
|
Binary file (14.3 kB). View file
|
|
|
lib/python3.12/site-packages/pandas/tests/indexes/interval/__pycache__/test_constructors.cpython-312.pyc
ADDED
|
Binary file (29.3 kB). View file
|
|
|