|
9 | 9 | import pandas._testing as tm |
10 | 10 | from pandas.arrays import SparseArray |
11 | 11 |
|
| 12 | +# Probe whether np.fix works with Series without raising due to read-only out |
| 13 | +# This avoids relying solely on is_numpy_dev, which may not reflect CI pinning. |
| 14 | +try: |
| 15 | + _ser = pd.Series([-1.5, -0.5]) |
| 16 | + _probe_result = np.fix(_ser) |
| 17 | + _NP_FIX_WORKS = True |
| 18 | +except Exception: # pragma: no cover - best-effort environment probe |
| 19 | + _NP_FIX_WORKS = False |
| 20 | + |
12 | 21 |
|
13 | 22 | @pytest.fixture(params=[np.add, np.logaddexp]) |
14 | 23 | def ufunc(request): |
@@ -238,6 +247,12 @@ def __init__(self, value) -> None: |
238 | 247 | def __add__(self, other): |
239 | 248 | return self.value + other.value |
240 | 249 |
|
| 250 | + def __eq__(self, other) -> bool: |
| 251 | + return type(other) is Dummy and self.value == other.value |
| 252 | + |
| 253 | + def __repr__(self) -> str: |
| 254 | + return f"Dummy({self.value})" |
| 255 | + |
241 | 256 | arr = np.array([Dummy(0), Dummy(1)]) |
242 | 257 | ser = pd.Series(arr) |
243 | 258 | tm.assert_series_equal(np.add(ser, ser), pd.Series(np.add(ser, arr))) |
@@ -457,7 +472,11 @@ def add3(x, y, z): |
457 | 472 | ufunc(ser, ser, df) |
458 | 473 |
|
459 | 474 |
|
460 | | -@pytest.mark.xfail(reason="see https://github.com/pandas-dev/pandas/pull/51082") |
| 475 | +@pytest.mark.xfail( |
| 476 | + condition=not _NP_FIX_WORKS, |
| 477 | + reason="see https://github.com/pandas-dev/pandas/pull/51082", |
| 478 | + strict=True, |
| 479 | +) |
461 | 480 | def test_np_fix(): |
462 | 481 | # np.fix is not a ufunc but is composed of several ufunc calls under the hood |
463 | 482 | # with `out` and `where` keywords |
|
0 commit comments