7
7
import pandas .util .testing as tm
8
8
9
9
UNARY_UFUNCS = [np .positive , np .floor , np .exp ]
10
- BINARY_UFUNCS = [np .add , np .logaddexp ] # -> dunder op
10
+ BINARY_UFUNCS = [
11
+ np .add , # dunder op
12
+ np .logaddexp ,
13
+ ]
11
14
SPARSE = [
12
15
pytest .param (True ,
13
16
marks = pytest .mark .xfail (reason = "Series.__array_ufunc__" )),
@@ -52,8 +55,12 @@ def test_unary_ufunc(ufunc, sparse):
52
55
@pytest .mark .parametrize ("ufunc" , BINARY_UFUNCS )
53
56
@pytest .mark .parametrize ("sparse" , SPARSE , ids = SPARSE_IDS )
54
57
@pytest .mark .parametrize ("shuffle" , SHUFFLE )
55
- @pytest .mark .parametrize ("box_other" , [True , False ])
58
+ @pytest .mark .parametrize ("box_other" , [True , False ],
59
+ ids = ['other-boxed' , 'other-raw' ])
60
+ @pytest .mark .parametrize ("flip" , [True , False ],
61
+ ids = ['flipped' , 'straight' ])
56
62
def test_binary_ufunc (ufunc , sparse , shuffle , box_other ,
63
+ flip ,
57
64
arrays_for_binary_ufunc ):
58
65
# Check the invariant that
59
66
# ufunc(Series(a), Series(b)) == Series(ufunc(a, b))
@@ -80,8 +87,15 @@ def test_binary_ufunc(ufunc, sparse, shuffle, box_other,
80
87
elif shuffle :
81
88
a2 = a2 .take (idx )
82
89
83
- result = ufunc (s1 , s2 )
84
- expected = pd .Series (ufunc (a1 , a2 ), name = name )
90
+ a , b = s1 , s2
91
+ c , d = a1 , a2
92
+
93
+ if flip :
94
+ a , b = b , a
95
+ c , d = d , c
96
+
97
+ result = ufunc (a , b )
98
+ expected = pd .Series (ufunc (c , d ), name = name )
85
99
tm .assert_series_equal (result , expected )
86
100
87
101
@@ -150,3 +164,16 @@ def test_multiple_ouput_ufunc(sparse, arrays_for_binary_ufunc):
150
164
151
165
tm .assert_series_equal (result [0 ], pd .Series (expected [0 ], name = "name" ))
152
166
tm .assert_series_equal (result [1 ], pd .Series (expected [1 ], name = "name" ))
167
+
168
+
169
+ @pytest .mark .parametrize ("sparse" , SPARSE , ids = SPARSE_IDS )
170
+ @pytest .mark .parametrize ("ufunc" , BINARY_UFUNCS )
171
+ @pytest .mark .xfail (reason = "Series.__array_ufunc__" )
172
+ def test_binary_ufunc_drops_series_name (ufunc , sparse ,
173
+ arrays_for_binary_ufunc ):
174
+ a1 , a2 = arrays_for_binary_ufunc
175
+ s1 = pd .Series (a1 , name = 'a' )
176
+ s2 = pd .Series (a2 , name = 'b' )
177
+
178
+ result = ufunc (s1 , s2 )
179
+ assert result .name is None
0 commit comments