forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_categorical.py
172 lines (117 loc) · 3.93 KB
/
test_categorical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import string
import pytest
import numpy as np
import pandas as pd
import pandas.util.testing as tm
from pandas.api.types import CategoricalDtype
from pandas import Categorical
from pandas.tests.extension import base
def make_data():
return np.random.choice(list(string.ascii_letters), size=100)
@pytest.fixture
def dtype():
return CategoricalDtype()
@pytest.fixture
def data():
"""Length-100 PeriodArray for semantics test."""
return Categorical(make_data())
@pytest.fixture
def data_missing():
"""Length 2 array with [NA, Valid]"""
return Categorical([np.nan, 'A'])
@pytest.fixture
def data_for_sorting():
return Categorical(['A', 'B', 'C'], categories=['C', 'A', 'B'],
ordered=True)
@pytest.fixture
def data_missing_for_sorting():
return Categorical(['A', None, 'B'], categories=['B', 'A'],
ordered=True)
@pytest.fixture
def na_value():
return np.nan
@pytest.fixture
def data_for_grouping():
return Categorical(['a', 'a', None, None, 'b', 'b', 'a', 'c'])
class TestDtype(base.BaseDtypeTests):
pass
class TestInterface(base.BaseInterfaceTests):
@pytest.mark.skip(reason="Memory usage doesn't match")
def test_memory_usage(self):
# Is this deliberate?
pass
class TestConstructors(base.BaseConstructorsTests):
pass
class TestReshaping(base.BaseReshapingTests):
@pytest.mark.skip(reason="Unobserved categories preseved in concat.")
def test_concat_columns(self, data, na_value):
pass
@pytest.mark.skip(reason="Unobserved categories preseved in concat.")
def test_align(self, data, na_value):
pass
@pytest.mark.skip(reason="Unobserved categories preseved in concat.")
def test_align_frame(self, data, na_value):
pass
@pytest.mark.skip(reason="Unobserved categories preseved in concat.")
def test_merge(self, data, na_value):
pass
class TestGetitem(base.BaseGetitemTests):
skip_take = pytest.mark.skip(reason="GH-20664.")
@pytest.mark.skip(reason="Backwards compatibility")
def test_getitem_scalar(self):
# CategoricalDtype.type isn't "correct" since it should
# be a parent of the elements (object). But don't want
# to break things by changing.
pass
@skip_take
def test_take(self):
# TODO remove this once Categorical.take is fixed
pass
@skip_take
def test_take_negative(self):
pass
@skip_take
def test_take_pandas_style_negative_raises(self):
pass
@skip_take
def test_take_non_na_fill_value(self):
pass
@skip_take
def test_take_out_of_bounds_raises(self):
pass
@pytest.mark.skip(reason="GH-20747. Unobserved categories.")
def test_take_series(self):
pass
@skip_take
def test_reindex_non_na_fill_value(self):
pass
@pytest.mark.xfail(reason="Categorical.take buggy")
def test_take_empty(self):
pass
@pytest.mark.xfail(reason="test not written correctly for categorical")
def test_reindex(self):
pass
class TestSetitem(base.BaseSetitemTests):
pass
class TestMissing(base.BaseMissingTests):
@pytest.mark.skip(reason="Not implemented")
def test_fillna_limit_pad(self):
pass
@pytest.mark.skip(reason="Not implemented")
def test_fillna_limit_backfill(self):
pass
class TestMethods(base.BaseMethodsTests):
pass
@pytest.mark.skip(reason="Unobserved categories included")
def test_value_counts(self, all_data, dropna):
pass
class TestCasting(base.BaseCastingTests):
pass
def test_combine():
orig_data1 = make_data()
orig_data2 = make_data()
s1 = pd.Series(Categorical(orig_data1, ordered=True))
s2 = pd.Series(Categorical(orig_data2, ordered=True))
result = s1.combine(s2, lambda x1, x2: x1 <= x2)
expected = pd.Series([a <= b for (a, b) in zip(orig_data1, orig_data2)])
tm.assert_series_equal(result, expected)