@@ -118,21 +118,18 @@ def test_binary_input_aligns_columns(request, dtype_a, dtype_b):
118118
119119 if isinstance (dtype_a , dict ) and isinstance (dtype_b , dict ):
120120 dtype_b ["C" ] = dtype_b .pop ("B" )
121-
122121 df2 = pd .DataFrame ({"A" : [1 , 2 ], "C" : [3 , 4 ]}).astype (dtype_b )
123- with tm .assert_produces_warning (FutureWarning ):
124- result = np .heaviside (df1 , df2 )
125- # Expected future behaviour:
126- # expected = np.heaviside(
127- # np.array([[1, 3, np.nan], [2, 4, np.nan]]),
128- # np.array([[1, np.nan, 3], [2, np.nan, 4]]),
129- # )
130- # expected = pd.DataFrame(expected, index=[0, 1], columns=["A", "B", "C"])
131- expected = pd .DataFrame ([[1.0 , 1.0 ], [1.0 , 1.0 ]], columns = ["A" , "B" ])
122+ # As of 2.0, align first before applying the ufunc
123+ result = np .heaviside (df1 , df2 )
124+ expected = np .heaviside (
125+ np .array ([[1 , 3 , np .nan ], [2 , 4 , np .nan ]]),
126+ np .array ([[1 , np .nan , 3 ], [2 , np .nan , 4 ]]),
127+ )
128+ expected = pd .DataFrame (expected , index = [0 , 1 ], columns = ["A" , "B" , "C" ])
132129 tm .assert_frame_equal (result , expected )
133130
134- # ensure the expected is the same when applying with numpy array
135131 result = np .heaviside (df1 , df2 .values )
132+ expected = pd .DataFrame ([[1.0 , 1.0 ], [1.0 , 1.0 ]], columns = ["A" , "B" ])
136133 tm .assert_frame_equal (result , expected )
137134
138135
@@ -146,35 +143,29 @@ def test_binary_input_aligns_index(request, dtype):
146143 )
147144 df1 = pd .DataFrame ({"A" : [1 , 2 ], "B" : [3 , 4 ]}, index = ["a" , "b" ]).astype (dtype )
148145 df2 = pd .DataFrame ({"A" : [1 , 2 ], "B" : [3 , 4 ]}, index = ["a" , "c" ]).astype (dtype )
149- with tm .assert_produces_warning (FutureWarning ):
150- result = np .heaviside (df1 , df2 )
151- # Expected future behaviour:
152- # expected = np.heaviside(
153- # np.array([[1, 3], [3, 4], [np.nan, np.nan]]),
154- # np.array([[1, 3], [np.nan, np.nan], [3, 4]]),
155- # )
156- # # TODO(FloatArray): this will be Float64Dtype.
157- # expected = pd.DataFrame(expected, index=["a", "b", "c"], columns=["A", "B"])
158- expected = pd .DataFrame (
159- [[1.0 , 1.0 ], [1.0 , 1.0 ]], columns = ["A" , "B" ], index = ["a" , "b" ]
146+ result = np .heaviside (df1 , df2 )
147+ expected = np .heaviside (
148+ np .array ([[1 , 3 ], [3 , 4 ], [np .nan , np .nan ]]),
149+ np .array ([[1 , 3 ], [np .nan , np .nan ], [3 , 4 ]]),
160150 )
151+ # TODO(FloatArray): this will be Float64Dtype.
152+ expected = pd .DataFrame (expected , index = ["a" , "b" , "c" ], columns = ["A" , "B" ])
161153 tm .assert_frame_equal (result , expected )
162154
163- # ensure the expected is the same when applying with numpy array
164155 result = np .heaviside (df1 , df2 .values )
156+ expected = pd .DataFrame (
157+ [[1.0 , 1.0 ], [1.0 , 1.0 ]], columns = ["A" , "B" ], index = ["a" , "b" ]
158+ )
165159 tm .assert_frame_equal (result , expected )
166160
167161
168- @pytest .mark .filterwarnings ("ignore:Calling a ufunc on non-aligned:FutureWarning" )
169162def test_binary_frame_series_raises ():
170163 # We don't currently implement
171164 df = pd .DataFrame ({"A" : [1 , 2 ]})
172- # with pytest.raises(NotImplementedError, match="logaddexp"):
173- with pytest .raises (ValueError , match = "" ):
165+ with pytest .raises (NotImplementedError , match = "logaddexp" ):
174166 np .logaddexp (df , df ["A" ])
175167
176- # with pytest.raises(NotImplementedError, match="logaddexp"):
177- with pytest .raises (ValueError , match = "" ):
168+ with pytest .raises (NotImplementedError , match = "logaddexp" ):
178169 np .logaddexp (df ["A" ], df )
179170
180171
@@ -206,7 +197,8 @@ def test_frame_outer_disallowed():
206197 np .subtract .outer (df , df )
207198
208199
209- def test_alignment_deprecation ():
200+ def test_alignment_deprecation_enforced ():
201+ # Enforced in 2.0
210202 # https://github.com/pandas-dev/pandas/issues/39184
211203 df1 = pd .DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
212204 df2 = pd .DataFrame ({"b" : [1 , 2 , 3 ], "c" : [4 , 5 , 6 ]})
@@ -221,12 +213,11 @@ def test_alignment_deprecation():
221213 result = np .add (df1 , df1 )
222214 tm .assert_frame_equal (result , expected )
223215
224- with tm .assert_produces_warning (FutureWarning ):
225- # non-aligned -> warns
226- result = np .add (df1 , df2 )
216+ result = np .add (df1 , df2 .values )
227217 tm .assert_frame_equal (result , expected )
228218
229- result = np .add (df1 , df2 .values )
219+ result = np .add (df1 , df2 )
220+ expected = pd .DataFrame ({"a" : [np .nan ] * 3 , "b" : [5 , 7 , 9 ], "c" : [np .nan ] * 3 })
230221 tm .assert_frame_equal (result , expected )
231222
232223 result = np .add (df1 .values , df2 )
@@ -241,20 +232,23 @@ def test_alignment_deprecation():
241232 result = np .add (df1 , s1 )
242233 tm .assert_frame_equal (result , expected )
243234
244- with tm .assert_produces_warning (FutureWarning ):
245- result = np .add (df1 , s2 )
235+ result = np .add (df1 , s2 .values )
246236 tm .assert_frame_equal (result , expected )
247237
248- with tm .assert_produces_warning (FutureWarning ):
249- result = np .add (s2 , df1 )
238+ expected = pd .DataFrame (
239+ {"a" : [np .nan ] * 3 , "b" : [5.0 , 6.0 , 7.0 ], "c" : [np .nan ] * 3 }
240+ )
241+ result = np .add (df1 , s2 )
250242 tm .assert_frame_equal (result , expected )
251243
252- result = np .add (df1 , s2 .values )
253- tm .assert_frame_equal (result , expected )
244+ msg = "Cannot apply ufunc <ufunc 'add'> to mixed DataFrame and Series inputs."
245+ with pytest .raises (NotImplementedError , match = msg ):
246+ np .add (s2 , df1 )
254247
255248
256249@td .skip_if_no ("numba" )
257- def test_alignment_deprecation_many_inputs (request ):
250+ def test_alignment_deprecation_many_inputs_enforced ():
251+ # Enforced in 2.0
258252 # https://github.com/pandas-dev/pandas/issues/39184
259253 # test that the deprecation also works with > 2 inputs -> using a numba
260254 # written ufunc for this because numpy itself doesn't have such ufuncs
@@ -271,31 +265,34 @@ def my_ufunc(x, y, z):
271265 df2 = pd .DataFrame ({"b" : [1 , 2 , 3 ], "c" : [4 , 5 , 6 ]})
272266 df3 = pd .DataFrame ({"a" : [1 , 2 , 3 ], "c" : [4 , 5 , 6 ]})
273267
274- with tm .assert_produces_warning (FutureWarning ):
275- result = my_ufunc (df1 , df2 , df3 )
276- expected = pd .DataFrame ([[3.0 , 12.0 ], [6.0 , 15.0 ], [9.0 , 18.0 ]], columns = ["a" , "b" ])
268+ result = my_ufunc (df1 , df2 , df3 )
269+ expected = pd .DataFrame (np .full ((3 , 3 ), np .nan ), columns = ["a" , "b" , "c" ])
277270 tm .assert_frame_equal (result , expected )
278271
279272 # all aligned -> no warning
280273 with tm .assert_produces_warning (None ):
281274 result = my_ufunc (df1 , df1 , df1 )
275+ expected = pd .DataFrame ([[3.0 , 12.0 ], [6.0 , 15.0 ], [9.0 , 18.0 ]], columns = ["a" , "b" ])
282276 tm .assert_frame_equal (result , expected )
283277
284278 # mixed frame / arrays
285- with tm .assert_produces_warning (FutureWarning ):
286- result = my_ufunc (df1 , df2 , df3 .values )
287- tm .assert_frame_equal (result , expected )
279+ msg = (
280+ r"operands could not be broadcast together with shapes \(3,3\) \(3,3\) \(3,2\)"
281+ )
282+ with pytest .raises (ValueError , match = msg ):
283+ my_ufunc (df1 , df2 , df3 .values )
288284
289285 # single frame -> no warning
290286 with tm .assert_produces_warning (None ):
291287 result = my_ufunc (df1 , df2 .values , df3 .values )
292288 tm .assert_frame_equal (result , expected )
293289
294290 # takes indices of first frame
295- with tm .assert_produces_warning (FutureWarning ):
296- result = my_ufunc (df1 .values , df2 , df3 )
297- expected = expected .set_axis (["b" , "c" ], axis = 1 )
298- tm .assert_frame_equal (result , expected )
291+ msg = (
292+ r"operands could not be broadcast together with shapes \(3,2\) \(3,3\) \(3,3\)"
293+ )
294+ with pytest .raises (ValueError , match = msg ):
295+ my_ufunc (df1 .values , df2 , df3 )
299296
300297
301298def test_array_ufuncs_for_many_arguments ():
0 commit comments