forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_numpy.py
182 lines (123 loc) · 4.64 KB
/
test_numpy.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
173
174
175
176
177
178
179
180
181
182
import numpy as np
import pytest
import pandas as pd
from pandas import compat
from pandas.core.arrays.numpy_ import PandasArray, PandasDtype
import pandas.util.testing as tm
from .. import base
@pytest.fixture
def dtype():
return PandasDtype(np.dtype('float'))
@pytest.fixture
def data(allow_in_pandas, dtype):
return PandasArray(np.arange(1, 101, dtype=dtype._dtype))
@pytest.fixture
def data_missing(allow_in_pandas):
return PandasArray(np.array([np.nan, 1.0]))
@pytest.fixture
def data_for_sorting(allow_in_pandas):
"""Length-3 array with a known sort order.
This should be three items [B, C, A] with
A < B < C
"""
return PandasArray(
np.array([1, 2, 0])
)
@pytest.fixture
def data_missing_for_sorting(allow_in_pandas):
"""Length-3 array with a known sort order.
This should be three items [B, NA, A] with
A < B and NA missing.
"""
return PandasArray(
np.array([1, np.nan, 0])
)
@pytest.fixture
def data_for_grouping(allow_in_pandas):
"""Data for factorization, grouping, and unique tests.
Expected to be like [B, B, NA, NA, A, A, B, C]
Where A < B < C and NA is missing
"""
a, b, c = np.arange(3)
return PandasArray(np.array(
[b, b, np.nan, np.nan, a, a, b, c]
))
class BaseNumPyTests(object):
pass
class TestCasting(BaseNumPyTests, base.BaseCastingTests):
pass
class TestConstructors(BaseNumPyTests, base.BaseConstructorsTests):
@pytest.mark.skip(reason="We don't register our dtype")
# We don't want to register. This test should probably be split in two.
def test_from_dtype(self, data):
pass
class TestDtype(BaseNumPyTests, base.BaseDtypeTests):
@pytest.mark.skip(reason="Incorrect expected.")
# we unsurprisingly clash with a NumPy name.
def test_check_dtype(self, data):
pass
class TestGetitem(BaseNumPyTests, base.BaseGetitemTests):
pass
class TestGroupby(BaseNumPyTests, base.BaseGroupbyTests):
pass
class TestInterface(BaseNumPyTests, base.BaseInterfaceTests):
pass
class TestMethods(BaseNumPyTests, base.BaseMethodsTests):
@pytest.mark.skip(reason="TODO: remove?")
def test_value_counts(self, all_data, dropna):
pass
@pytest.mark.skip(reason="Incorrect expected")
# We have a bool dtype, so the result is an ExtensionArray
# but expected is not
def test_combine_le(self, data_repeated):
super(TestMethods, self).test_combine_le(data_repeated)
class TestArithmetics(BaseNumPyTests, base.BaseArithmeticOpsTests):
divmod_exc = None
series_scalar_exc = None
frame_scalar_exc = None
series_array_exc = None
def test_divmod_series_array(self, data):
s = pd.Series(data)
self._check_divmod_op(s, divmod, data, exc=None)
@pytest.mark.skip("We implement ops")
def test_error(self, data, all_arithmetic_operators):
pass
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
if (compat.PY2 and
all_arithmetic_operators in {'__div__', '__rdiv__'}):
raise pytest.skip(
"Matching NumPy int / int -> float behavior."
)
super(TestArithmetics, self).test_arith_series_with_scalar(
data, all_arithmetic_operators
)
def test_arith_series_with_array(self, data, all_arithmetic_operators):
if (compat.PY2 and
all_arithmetic_operators in {'__div__', '__rdiv__'}):
raise pytest.skip(
"Matching NumPy int / int -> float behavior."
)
super(TestArithmetics, self).test_arith_series_with_array(
data, all_arithmetic_operators
)
class TestPrinting(BaseNumPyTests, base.BasePrintingTests):
pass
class TestNumericReduce(BaseNumPyTests, base.BaseNumericReduceTests):
def check_reduce(self, s, op_name, skipna):
result = getattr(s, op_name)(skipna=skipna)
# avoid coercing int -> float. Just cast to the actual numpy type.
expected = getattr(s.astype(s.dtype._dtype), op_name)(skipna=skipna)
tm.assert_almost_equal(result, expected)
class TestBooleanReduce(BaseNumPyTests, base.BaseBooleanReduceTests):
pass
class TestMising(BaseNumPyTests, base.BaseMissingTests):
pass
class TestReshaping(BaseNumPyTests, base.BaseReshapingTests):
@pytest.mark.skip("Incorrect parent test")
# not actually a mixed concat, since we concat int and int.
def test_concat_mixed_dtypes(self, data):
super(TestReshaping, self).test_concat_mixed_dtypes(data)
class TestSetitem(BaseNumPyTests, base.BaseSetitemTests):
pass
class TestParsing(BaseNumPyTests, base.BaseParsingTests):
pass