6
6
from pandas .core .arrays .numpy_ import PandasArray , PandasDtype
7
7
import pandas .util .testing as tm
8
8
9
- from .. import base
9
+ from . import base
10
10
11
11
12
12
@pytest .fixture
13
13
def dtype ():
14
14
return PandasDtype (np .dtype ('float' ))
15
15
16
16
17
+ @pytest .fixture
18
+ def allow_in_pandas (monkeypatch ):
19
+ """
20
+ A monkeypatch to tells pandas to let us in.
21
+
22
+ By default, passing a PandasArray to an index / series / frame
23
+ constructor will unbox that PandasArray to an ndarray, and treat
24
+ it as a non-EA column. We don't want people using EAs without
25
+ reason.
26
+
27
+ The mechanism for this is a check against ABCPandasArray
28
+ in each constructor.
29
+
30
+ But, for testing, we need to allow them in pandas. So we patch
31
+ the _typ of PandasArray, so that we evade the ABCPandasArray
32
+ check.
33
+ """
34
+ with monkeypatch .context () as m :
35
+ m .setattr (PandasArray , '_typ' , 'extension' )
36
+ yield
37
+
38
+
17
39
@pytest .fixture
18
40
def data (allow_in_pandas , dtype ):
19
41
return PandasArray (np .arange (1 , 101 , dtype = dtype ._dtype ))
@@ -24,6 +46,18 @@ def data_missing(allow_in_pandas):
24
46
return PandasArray (np .array ([np .nan , 1.0 ]))
25
47
26
48
49
+ @pytest .fixture
50
+ def na_value ():
51
+ return np .nan
52
+
53
+
54
+ @pytest .fixture
55
+ def na_cmp ():
56
+ def cmp (a , b ):
57
+ return np .isnan (a ) and np .isnan (b )
58
+ return cmp
59
+
60
+
27
61
@pytest .fixture
28
62
def data_for_sorting (allow_in_pandas ):
29
63
"""Length-3 array with a known sort order.
0 commit comments