Skip to content

Commit 2d5b36d

Browse files
committed
enable testing for PyPy, fix error messages
1 parent 4e0630c commit 2d5b36d

File tree

16 files changed

+73
-25
lines changed

16 files changed

+73
-25
lines changed

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
env_file: actions-311.yaml
7070
pattern: "not slow and not network and not single_cpu"
7171
pandas_copy_on_write: "1"
72-
- name: "Pypy"
72+
- name: "PyPy"
7373
env_file: actions-pypy-39.yaml
7474
pattern: "not slow and not network and not single_cpu"
7575
test_args: "--max-worker-restart 0"
@@ -160,7 +160,7 @@ jobs:
160160

161161
- name: Test (not single_cpu)
162162
uses: ./.github/actions/run-tests
163-
if: ${{ matrix.name != 'Pypy' }}
163+
if: ${{ matrix.name != 'PyPy' }}
164164
env:
165165
# Set pattern to not single_cpu if not already set
166166
PATTERN: ${{ env.PATTERN == '' && 'not single_cpu' || matrix.pattern }}
@@ -170,7 +170,7 @@ jobs:
170170
env:
171171
PATTERN: 'single_cpu'
172172
PYTEST_WORKERS: 0
173-
if: ${{ matrix.pattern == '' && (always() && steps.build.outcome == 'success')}}
173+
if: ${{ (matrix.pattern == '' && (always() && steps.build.outcome == 'success')) || matrix.name == 'PyPy'}}
174174

175175
macos-windows:
176176
timeout-minutes: 180

ci/deps/actions-pypy-39.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515

1616
# test dependencies
1717
- pytest>=7.3.2
18-
- pytest-cov
18+
# - pytest-cov # Don't use coverage on PyPy, it is too slow
1919
- pytest-asyncio>=0.17.0
2020
- pytest-xdist>=2.2.0
2121
- hypothesis>=6.46.1

ci/run_tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export PYTHONHASHSEED=$(python -c 'import random; print(random.randint(1, 429496
88
# May help reproduce flaky CI builds if set in subsequent runs
99
echo PYTHONHASHSEED=$PYTHONHASHSEED
1010

11-
COVERAGE="-s --cov=pandas --cov-report=xml --cov-append --cov-config=pyproject.toml"
11+
export IS_PYPY=$(python -c "import sys; print(sys.implementation.name == 'pypy')")
12+
if [[ "$IS_PYPY" != "True" ]]; then
13+
COVERAGE="-s --cov=pandas --cov-report=xml --cov-append --cov-config=pyproject.toml"
14+
fi
1215

1316
PYTEST_CMD="MESONPY_EDITABLE_VERBOSE=1 PYTHONDEVMODE=1 PYTHONWARNDEFAULTENCODING=1 pytest -r fEs -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET"
1417

pandas/_testing/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import re
1010
import string
11-
from sys import byteorder
11+
from sys import byteorder, implementation
1212
from typing import (
1313
TYPE_CHECKING,
1414
Callable,
@@ -210,6 +210,9 @@
210210
]
211211
]
212212

213+
IS_PYPY = implementation.name == 'pypy'
214+
215+
213216
if not pa_version_under7p0:
214217
import pyarrow as pa
215218

@@ -1127,6 +1130,7 @@ def shares_memory(left, right) -> bool:
11271130
"iat",
11281131
"iloc",
11291132
"index_subclass_makers_generator",
1133+
"IS_PYPY",
11301134
"loc",
11311135
"makeBoolIndex",
11321136
"makeCategoricalIndex",

pandas/testing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
assert_frame_equal,
99
assert_index_equal,
1010
assert_series_equal,
11+
IS_PYPY,
1112
)
1213

1314
__all__ = [
1415
"assert_extension_array_equal",
1516
"assert_frame_equal",
1617
"assert_series_equal",
1718
"assert_index_equal",
19+
"IS_PYPY",
1820
]

pandas/tests/apply/test_invalid_arg.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ def transform2(row):
220220
)
221221
def test_agg_cython_table_raises_frame(df, func, expected, axis):
222222
# GH 21224
223-
msg = "can't multiply sequence by non-int of type 'str'"
223+
if tm.IS_PYPY:
224+
msg = "unsupported operand type(s) for"
225+
else:
226+
msg = "can't multiply sequence by non-int of type 'str'"
224227
warn = None if isinstance(func, str) else FutureWarning
225228
with pytest.raises(expected, match=msg):
226229
with tm.assert_produces_warning(warn, match="using DataFrame.cumprod"):
@@ -246,6 +249,8 @@ def test_agg_cython_table_raises_frame(df, func, expected, axis):
246249
def test_agg_cython_table_raises_series(series, func, expected):
247250
# GH21224
248251
msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type"
252+
if tm.IS_PYPY:
253+
msg += "|unsupported operand type(s) for"
249254
if func == "median" or func is np.nanmedian or func is np.median:
250255
msg = r"Cannot convert \['a' 'b' 'c'\] to numeric"
251256
warn = None if isinstance(func, str) else FutureWarning

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,8 @@ def test_dti_add_tick_tzaware(self, tz_aware_fixture, box_with_array):
13021302
tm.assert_equal(roundtrip, dates)
13031303

13041304
msg = "|".join(
1305-
["bad operand type for unary -", "cannot subtract DatetimeArray"]
1305+
["bad operand type for unary -", "cannot subtract DatetimeArray",
1306+
"unsupported operand type for unary"] # PyPy
13061307
)
13071308
with pytest.raises(TypeError, match=msg):
13081309
scalar - dates
@@ -1919,7 +1920,10 @@ def test_datetime64_ops_nat(self):
19191920

19201921
# subtraction
19211922
tm.assert_series_equal(-NaT + datetime_series, nat_series_dtype_timestamp)
1922-
msg = "bad operand type for unary -: 'DatetimeArray'"
1923+
if tm.IS_PYPY:
1924+
msg = "unsupported operand type for unary"
1925+
else:
1926+
msg = "bad operand type for unary -: 'DatetimeArray'"
19231927
with pytest.raises(TypeError, match=msg):
19241928
-single_nat_dtype_datetime + datetime_series
19251929

pandas/tests/arithmetic/test_period.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,10 @@ def test_pi_sub_intarray(self, int_holder):
10071007
expected = PeriodIndex([Period("2014Q1"), Period("NaT")])
10081008
tm.assert_index_equal(result, expected)
10091009

1010-
msg = r"bad operand type for unary -: 'PeriodArray'"
1010+
if tm.IS_PYPY:
1011+
msg = "unsupported operand type for unary"
1012+
else:
1013+
msg = r"bad operand type for unary -: 'PeriodArray'"
10111014
with pytest.raises(TypeError, match=msg):
10121015
other - pi
10131016

@@ -1043,6 +1046,7 @@ def test_parr_add_timedeltalike_minute_gt1(self, three_days, box_with_array):
10431046
[
10441047
r"bad operand type for unary -: 'PeriodArray'",
10451048
r"cannot subtract PeriodArray from timedelta64\[[hD]\]",
1049+
"unsupported operand type for unary", # PyPy
10461050
]
10471051
)
10481052
with pytest.raises(TypeError, match=msg):
@@ -1075,6 +1079,7 @@ def test_parr_add_timedeltalike_tick_gt1(self, three_days, freqstr, box_with_arr
10751079
[
10761080
r"bad operand type for unary -: 'PeriodArray'",
10771081
r"cannot subtract PeriodArray from timedelta64\[[hD]\]",
1082+
"unsupported operand type for unary", # PyPy
10781083
]
10791084
)
10801085
with pytest.raises(TypeError, match=msg):

pandas/tests/arrays/floating/test_arithmetic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def test_error_invalid_values(data, all_arithmetic_operators):
140140
"ufunc '.*' not supported for the input types, and the inputs could not",
141141
"ufunc '.*' did not contain a loop with signature matching types",
142142
"Concatenation operation is not implemented for NumPy arrays",
143+
r"unsupported operand type(s) for", # PyPy
143144
]
144145
)
145146
with pytest.raises(TypeError, match=msg):
@@ -161,6 +162,7 @@ def test_error_invalid_values(data, all_arithmetic_operators):
161162
"not all arguments converted during string formatting",
162163
"can't multiply sequence by non-int of type 'float'",
163164
"ufunc 'subtract' cannot use operands with types dtype",
165+
r"unsupported operand type(s) for", # PyPy
164166
(
165167
"ufunc 'add' cannot use operands with types "
166168
rf"dtype\('{tm.ENDIAN}M8\[ns\]'\)"

pandas/tests/computation/test_eval.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ def test_frame_invert(self, engine, parser):
401401
with pytest.raises(ValueError, match="unknown type object"):
402402
pd.eval(expr, engine=engine, parser=parser)
403403
else:
404-
msg = "bad operand type for unary ~: 'str'"
404+
if tm.IS_PYPY:
405+
msg = "unsupported operand type for unary"
406+
else:
407+
msg = "bad operand type for unary ~: 'str'"
405408
with pytest.raises(TypeError, match=msg):
406409
pd.eval(expr, engine=engine, parser=parser)
407410

@@ -448,7 +451,10 @@ def test_series_invert(self, engine, parser):
448451
with pytest.raises(ValueError, match="unknown type object"):
449452
pd.eval(expr, engine=engine, parser=parser)
450453
else:
451-
msg = "bad operand type for unary ~: 'str'"
454+
if tm.IS_PYPY:
455+
msg = "unsupported operand type for unary"
456+
else:
457+
msg = "bad operand type for unary ~: 'str'"
452458
with pytest.raises(TypeError, match=msg):
453459
pd.eval(expr, engine=engine, parser=parser)
454460

@@ -541,7 +547,10 @@ def test_series_pos(self, lhs, engine, parser):
541547
tm.assert_series_equal(expect, result)
542548

543549
def test_scalar_unary(self, engine, parser):
544-
msg = "bad operand type for unary ~: 'float'"
550+
if tm.IS_PYPY:
551+
msg = "unsupported operand type for unary"
552+
else:
553+
msg = "bad operand type for unary ~: 'float'"
545554
with pytest.raises(TypeError, match=msg):
546555
pd.eval("~1.0", engine=engine, parser=parser)
547556

0 commit comments

Comments
 (0)