forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_interval.py
151 lines (100 loc) · 3.49 KB
/
test_interval.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
"""
This file contains a minimal set of tests for compliance with the extension
array interface test suite, and should contain no other tests.
The test suite for the full functionality of the array is located in
`pandas/tests/arrays/`.
The tests in this file are inherited from the BaseExtensionTests, and only
minimal tweaks should be applied to get the tests passing (by overwriting a
parent method).
Additional tests should either be added to one of the BaseExtensionTests
classes (if they are relevant for the extension interface for all dtypes), or
be added to the array-specific tests in `pandas/tests/arrays/`.
"""
import pytest
import numpy as np
from pandas import Interval
from pandas.core.arrays import IntervalArray
from pandas.core.dtypes.dtypes import IntervalDtype
from pandas.tests.extension import base
import pandas.util.testing as tm
def make_data():
N = 100
left = np.random.uniform(size=N).cumsum()
right = left + np.random.uniform(size=N)
return [Interval(l, r) for l, r in zip(left, right)]
@pytest.fixture
def dtype():
return IntervalDtype()
@pytest.fixture
def data():
"""Length-100 PeriodArray for semantics test."""
return IntervalArray(make_data())
@pytest.fixture
def data_missing():
"""Length 2 array with [NA, Valid]"""
return IntervalArray.from_tuples([None, (0, 1)])
@pytest.fixture
def data_repeated():
"""Return different versions of data for count times"""
def gen(count):
for _ in range(count):
yield IntervalArray(make_data())
yield gen
@pytest.fixture
def data_for_sorting():
return IntervalArray.from_tuples([(1, 2), (2, 3), (0, 1)])
@pytest.fixture
def data_missing_for_sorting():
return IntervalArray.from_tuples([(1, 2), None, (0, 1)])
@pytest.fixture
def na_value():
return np.nan
@pytest.fixture
def data_for_grouping():
a = (0, 1)
b = (1, 2)
c = (2, 3)
return IntervalArray.from_tuples([b, b, None, None, a, a, b, c])
class BaseInterval(object):
pass
class TestDtype(BaseInterval, base.BaseDtypeTests):
def test_array_type_with_arg(self, data, dtype):
assert dtype.construct_array_type() is IntervalArray
class TestCasting(BaseInterval, base.BaseCastingTests):
pass
class TestConstructors(BaseInterval, base.BaseConstructorsTests):
pass
class TestGetitem(BaseInterval, base.BaseGetitemTests):
pass
class TestGrouping(BaseInterval, base.BaseGroupbyTests):
pass
class TestInterface(BaseInterval, base.BaseInterfaceTests):
pass
class TestMethods(BaseInterval, base.BaseMethodsTests):
@pytest.mark.skip(reason='addition is not defined for intervals')
def test_combine_add(self, data_repeated):
pass
class TestMissing(BaseInterval, base.BaseMissingTests):
# Index.fillna only accepts scalar `value`, so we have to skip all
# non-scalar fill tests.
unsupported_fill = pytest.mark.skip("Unsupported fillna option.")
@unsupported_fill
def test_fillna_limit_pad(self):
pass
@unsupported_fill
def test_fillna_series_method(self):
pass
@unsupported_fill
def test_fillna_limit_backfill(self):
pass
@unsupported_fill
def test_fillna_series(self):
pass
def test_non_scalar_raises(self, data_missing):
msg = "Got a 'list' instead."
with tm.assert_raises_regex(TypeError, msg):
data_missing.fillna([1, 1])
class TestReshaping(BaseInterval, base.BaseReshapingTests):
pass
class TestSetitem(BaseInterval, base.BaseSetitemTests):
pass