|
4 | 4 | import numpy as np
|
5 | 5 | import pytest
|
6 | 6 |
|
| 7 | +from pandas.compat._optional import import_optional_dependency |
| 8 | + |
7 | 9 | from pandas import option_context
|
8 | 10 | import pandas._testing as tm
|
9 | 11 | from pandas.core.api import DataFrame
|
10 | 12 | from pandas.core.computation import expressions as expr
|
| 13 | +from pandas.util.version import Version |
11 | 14 |
|
12 | 15 |
|
13 | 16 | @pytest.fixture
|
@@ -340,35 +343,43 @@ def test_bool_ops_warn_on_arithmetic(self, op_str, opname, monkeypatch):
|
340 | 343 | return
|
341 | 344 |
|
342 | 345 | msg = "operator is not supported by numexpr"
|
| 346 | + ne = import_optional_dependency("numexpr", errors="ignore") |
| 347 | + warning = ( |
| 348 | + UserWarning |
| 349 | + if ne |
| 350 | + and op_str in {"+", "*"} |
| 351 | + and Version(ne.__version__) < Version("2.13.1") |
| 352 | + else None |
| 353 | + ) |
343 | 354 | with monkeypatch.context() as m:
|
344 | 355 | m.setattr(expr, "_MIN_ELEMENTS", 5)
|
345 | 356 | with option_context("compute.use_numexpr", True):
|
346 |
| - with tm.assert_produces_warning(UserWarning, match=msg): |
| 357 | + with tm.assert_produces_warning(warning, match=msg): |
347 | 358 | r = f(df, df)
|
348 | 359 | e = fe(df, df)
|
349 | 360 | tm.assert_frame_equal(r, e)
|
350 | 361 |
|
351 |
| - with tm.assert_produces_warning(UserWarning, match=msg): |
| 362 | + with tm.assert_produces_warning(warning, match=msg): |
352 | 363 | r = f(df.a, df.b)
|
353 | 364 | e = fe(df.a, df.b)
|
354 | 365 | tm.assert_series_equal(r, e)
|
355 | 366 |
|
356 |
| - with tm.assert_produces_warning(UserWarning, match=msg): |
| 367 | + with tm.assert_produces_warning(warning, match=msg): |
357 | 368 | r = f(df.a, True)
|
358 | 369 | e = fe(df.a, True)
|
359 | 370 | tm.assert_series_equal(r, e)
|
360 | 371 |
|
361 |
| - with tm.assert_produces_warning(UserWarning, match=msg): |
| 372 | + with tm.assert_produces_warning(warning, match=msg): |
362 | 373 | r = f(False, df.a)
|
363 | 374 | e = fe(False, df.a)
|
364 | 375 | tm.assert_series_equal(r, e)
|
365 | 376 |
|
366 |
| - with tm.assert_produces_warning(UserWarning, match=msg): |
| 377 | + with tm.assert_produces_warning(warning, match=msg): |
367 | 378 | r = f(False, df)
|
368 | 379 | e = fe(False, df)
|
369 | 380 | tm.assert_frame_equal(r, e)
|
370 | 381 |
|
371 |
| - with tm.assert_produces_warning(UserWarning, match=msg): |
| 382 | + with tm.assert_produces_warning(warning, match=msg): |
372 | 383 | r = f(df, True)
|
373 | 384 | e = fe(df, True)
|
374 | 385 | tm.assert_frame_equal(r, e)
|
|
0 commit comments