|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
3 | 3 |
|
4 |
| -import pandas._config.config as cf |
5 |
| - |
6 | 4 | from pandas._libs import index as libindex
|
7 | 5 |
|
8 | 6 | from pandas.core.dtypes.dtypes import CategoricalDtype
|
@@ -100,65 +98,6 @@ def test_method_delegation(self):
|
100 | 98 | with pytest.raises(ValueError, match=msg):
|
101 | 99 | ci.set_categories(list("cab"), inplace=True)
|
102 | 100 |
|
103 |
| - def test_contains(self): |
104 |
| - |
105 |
| - ci = self.create_index(categories=list("cabdef")) |
106 |
| - |
107 |
| - assert "a" in ci |
108 |
| - assert "z" not in ci |
109 |
| - assert "e" not in ci |
110 |
| - assert np.nan not in ci |
111 |
| - |
112 |
| - # assert codes NOT in index |
113 |
| - assert 0 not in ci |
114 |
| - assert 1 not in ci |
115 |
| - |
116 |
| - ci = CategoricalIndex(list("aabbca") + [np.nan], categories=list("cabdef")) |
117 |
| - assert np.nan in ci |
118 |
| - |
119 |
| - @pytest.mark.parametrize( |
120 |
| - "item, expected", |
121 |
| - [ |
122 |
| - (pd.Interval(0, 1), True), |
123 |
| - (1.5, True), |
124 |
| - (pd.Interval(0.5, 1.5), False), |
125 |
| - ("a", False), |
126 |
| - (pd.Timestamp(1), False), |
127 |
| - (pd.Timedelta(1), False), |
128 |
| - ], |
129 |
| - ids=str, |
130 |
| - ) |
131 |
| - def test_contains_interval(self, item, expected): |
132 |
| - # GH 23705 |
133 |
| - ci = CategoricalIndex(IntervalIndex.from_breaks(range(3))) |
134 |
| - result = item in ci |
135 |
| - assert result is expected |
136 |
| - |
137 |
| - def test_contains_list(self): |
138 |
| - # GH#21729 |
139 |
| - idx = pd.CategoricalIndex([1, 2, 3]) |
140 |
| - |
141 |
| - assert "a" not in idx |
142 |
| - |
143 |
| - with pytest.raises(TypeError, match="unhashable type"): |
144 |
| - ["a"] in idx |
145 |
| - |
146 |
| - with pytest.raises(TypeError, match="unhashable type"): |
147 |
| - ["a", "b"] in idx |
148 |
| - |
149 |
| - @pytest.mark.parametrize("klass", [list, tuple, np.array, pd.Series]) |
150 |
| - def test_where(self, klass): |
151 |
| - i = self.create_index() |
152 |
| - cond = [True] * len(i) |
153 |
| - expected = i |
154 |
| - result = i.where(klass(cond)) |
155 |
| - tm.assert_index_equal(result, expected) |
156 |
| - |
157 |
| - cond = [False] + [True] * (len(i) - 1) |
158 |
| - expected = CategoricalIndex([np.nan] + i[1:].tolist(), categories=i.categories) |
159 |
| - result = i.where(klass(cond)) |
160 |
| - tm.assert_index_equal(result, expected) |
161 |
| - |
162 | 101 | def test_append(self):
|
163 | 102 |
|
164 | 103 | ci = self.create_index()
|
@@ -503,106 +442,6 @@ def test_frame_repr(self):
|
503 | 442 | expected = " A\na 1\nb 2\nc 3"
|
504 | 443 | assert result == expected
|
505 | 444 |
|
506 |
| - def test_string_categorical_index_repr(self): |
507 |
| - # short |
508 |
| - idx = pd.CategoricalIndex(["a", "bb", "ccc"]) |
509 |
| - expected = """CategoricalIndex(['a', 'bb', 'ccc'], categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa |
510 |
| - assert repr(idx) == expected |
511 |
| - |
512 |
| - # multiple lines |
513 |
| - idx = pd.CategoricalIndex(["a", "bb", "ccc"] * 10) |
514 |
| - expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', |
515 |
| - 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', |
516 |
| - 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'], |
517 |
| - categories=['a', 'bb', 'ccc'], ordered=False, dtype='category')""" # noqa |
518 |
| - |
519 |
| - assert repr(idx) == expected |
520 |
| - |
521 |
| - # truncated |
522 |
| - idx = pd.CategoricalIndex(["a", "bb", "ccc"] * 100) |
523 |
| - expected = """CategoricalIndex(['a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', |
524 |
| - ... |
525 |
| - 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc', 'a', 'bb', 'ccc'], |
526 |
| - categories=['a', 'bb', 'ccc'], ordered=False, dtype='category', length=300)""" # noqa |
527 |
| - |
528 |
| - assert repr(idx) == expected |
529 |
| - |
530 |
| - # larger categories |
531 |
| - idx = pd.CategoricalIndex(list("abcdefghijklmmo")) |
532 |
| - expected = """CategoricalIndex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', |
533 |
| - 'm', 'm', 'o'], |
534 |
| - categories=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', ...], ordered=False, dtype='category')""" # noqa |
535 |
| - |
536 |
| - assert repr(idx) == expected |
537 |
| - |
538 |
| - # short |
539 |
| - idx = pd.CategoricalIndex(["あ", "いい", "ううう"]) |
540 |
| - expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa |
541 |
| - assert repr(idx) == expected |
542 |
| - |
543 |
| - # multiple lines |
544 |
| - idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 10) |
545 |
| - expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', |
546 |
| - 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', |
547 |
| - 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'], |
548 |
| - categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa |
549 |
| - |
550 |
| - assert repr(idx) == expected |
551 |
| - |
552 |
| - # truncated |
553 |
| - idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 100) |
554 |
| - expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', |
555 |
| - ... |
556 |
| - 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'], |
557 |
| - categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa |
558 |
| - |
559 |
| - assert repr(idx) == expected |
560 |
| - |
561 |
| - # larger categories |
562 |
| - idx = pd.CategoricalIndex(list("あいうえおかきくけこさしすせそ")) |
563 |
| - expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し', |
564 |
| - 'す', 'せ', 'そ'], |
565 |
| - categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa |
566 |
| - |
567 |
| - assert repr(idx) == expected |
568 |
| - |
569 |
| - # Emable Unicode option ----------------------------------------- |
570 |
| - with cf.option_context("display.unicode.east_asian_width", True): |
571 |
| - |
572 |
| - # short |
573 |
| - idx = pd.CategoricalIndex(["あ", "いい", "ううう"]) |
574 |
| - expected = """CategoricalIndex(['あ', 'いい', 'ううう'], categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa |
575 |
| - assert repr(idx) == expected |
576 |
| - |
577 |
| - # multiple lines |
578 |
| - idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 10) |
579 |
| - expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', |
580 |
| - 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', |
581 |
| - 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', |
582 |
| - 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'], |
583 |
| - categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa |
584 |
| - |
585 |
| - assert repr(idx) == expected |
586 |
| - |
587 |
| - # truncated |
588 |
| - idx = pd.CategoricalIndex(["あ", "いい", "ううう"] * 100) |
589 |
| - expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', |
590 |
| - 'ううう', 'あ', |
591 |
| - ... |
592 |
| - 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', |
593 |
| - 'あ', 'いい', 'ううう'], |
594 |
| - categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa |
595 |
| - |
596 |
| - assert repr(idx) == expected |
597 |
| - |
598 |
| - # larger categories |
599 |
| - idx = pd.CategoricalIndex(list("あいうえおかきくけこさしすせそ")) |
600 |
| - expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', |
601 |
| - 'さ', 'し', 'す', 'せ', 'そ'], |
602 |
| - categories=['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', ...], ordered=False, dtype='category')""" # noqa |
603 |
| - |
604 |
| - assert repr(idx) == expected |
605 |
| - |
606 | 445 | def test_fillna_categorical(self):
|
607 | 446 | # GH 11343
|
608 | 447 | idx = CategoricalIndex([1.0, np.nan, 3.0, 1.0], name="x")
|
|
0 commit comments