Skip to content

Commit 2e6ab60

Browse files
Debian Science Teamrebecca-palmer
Debian Science Team
authored andcommitted
Avoid failing when a dependency is too old
(some of them are pulled in by other dependencies, so just not including them in d/control doesn't stop them being installed) Most of the content of this patch was generated by the following Python code: import pathlib import re basedir = pathlib.Path.cwd() if not (basedir / 'pandas/tests').exists(): raise FileNotFoundError('must be run from the pandas root') for source_file in basedir.glob('pandas/**/*.py'): with open(source_file, 'r') as fd: source_text = fd.read() if 'pytest.importorskip' in source_text: source_text = re.sub(r'pytest\.importorskip(.*)minversion', r'td.versioned_importorskip\1min_version', source_text) source_text = re.sub(r'pytest\.importorskip', r'td.versioned_importorskip', source_text) if '_test_decorators as td' not in source_text: # add the import if it isn't already present source_text, count = re.subn(r'^(import pandas|from pandas.*import)',r'import pandas.util._test_decorators as td\n\1', source_text, count=1, flags=re.MULTILINE) if count != 1: raise KeyError("failed to add import") with open(source_file, 'w') as fd: fd.write(source_text) Author: Rebecca N. Palmer <[email protected]> Forwarded: no Gbp-Pq: Name versioned_importorskip.patch
1 parent 024858c commit 2e6ab60

File tree

159 files changed

+689
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+689
-563
lines changed

pandas/_testing/_io.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def round_trip_localpath(writer, reader, path: str | None = None):
107107
pandas object
108108
The original object that was serialized and then re-read.
109109
"""
110-
import pytest
110+
import pandas.util._test_decorators as td
111111

112-
LocalPath = pytest.importorskip("py.path").local
112+
LocalPath = td.versioned_importorskip("py.path").local
113113
if path is None:
114114
path = "___localpath___"
115115
with ensure_clean(path) as path:

pandas/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ def ip():
18161816
18171817
Will raise a skip if IPython is not installed.
18181818
"""
1819-
pytest.importorskip("IPython", minversion="6.0.0")
1819+
td.versioned_importorskip("IPython", min_version="6.0.0")
18201820
from IPython.core.interactiveshell import InteractiveShell
18211821

18221822
# GH#35711 make sure sqlite history file handle is not leaked
@@ -1833,7 +1833,7 @@ def spmatrix(request):
18331833
"""
18341834
Yields scipy sparse matrix classes.
18351835
"""
1836-
sparse = pytest.importorskip("scipy.sparse")
1836+
sparse = td.versioned_importorskip("scipy.sparse")
18371837

18381838
return getattr(sparse, request.param + "_matrix")
18391839

pandas/tests/apply/test_frame_apply.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import pytest
66

7+
import pandas.util._test_decorators as td
78
from pandas.core.dtypes.dtypes import CategoricalDtype
89

910
import pandas as pd
@@ -35,7 +36,7 @@ def int_frame_const_col():
3536
@pytest.fixture(params=["python", pytest.param("numba", marks=pytest.mark.single_cpu)])
3637
def engine(request):
3738
if request.param == "numba":
38-
pytest.importorskip("numba")
39+
td.versioned_importorskip("numba")
3940
return request.param
4041

4142

pandas/tests/apply/test_numba.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_numba_vs_python_noop(float_frame, apply_axis):
2626

2727
def test_numba_vs_python_string_index():
2828
# GH#56189
29-
pytest.importorskip("pyarrow")
29+
td.versioned_importorskip("pyarrow")
3030
df = DataFrame(
3131
1,
3232
index=Index(["a", "b"], dtype="string[pyarrow_numpy]"),

pandas/tests/arrays/categorical/test_warnings.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import pytest
22

3+
import pandas.util._test_decorators as td
34
import pandas._testing as tm
45

56

67
class TestCategoricalWarnings:
78
def test_tab_complete_warning(self, ip):
89
# https://github.com/pandas-dev/pandas/issues/16409
9-
pytest.importorskip("IPython", minversion="6.0.0")
10+
td.versioned_importorskip("IPython", min_version="6.0.0")
1011
from IPython.core.completer import provisionalcompleter
1112

1213
code = "import pandas as pd; c = pd.Categorical([])"

pandas/tests/arrays/datetimes/test_constructors.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
import pandas.util._test_decorators as td
45
from pandas._libs import iNaT
56

67
from pandas.core.dtypes.dtypes import DatetimeTZDtype
@@ -226,7 +227,7 @@ def test_2d(self, order):
226227
def test_from_arrow_with_different_units_and_timezones_with(
227228
pa_unit, pd_unit, pa_tz, pd_tz, data
228229
):
229-
pa = pytest.importorskip("pyarrow")
230+
pa = td.versioned_importorskip("pyarrow")
230231

231232
pa_type = pa.timestamp(pa_unit, tz=pa_tz)
232233
arr = pa.array(data, type=pa_type)
@@ -253,7 +254,7 @@ def test_from_arrow_with_different_units_and_timezones_with(
253254
],
254255
)
255256
def test_from_arrow_from_empty(unit, tz):
256-
pa = pytest.importorskip("pyarrow")
257+
pa = td.versioned_importorskip("pyarrow")
257258

258259
data = []
259260
arr = pa.array(data)
@@ -269,7 +270,7 @@ def test_from_arrow_from_empty(unit, tz):
269270

270271

271272
def test_from_arrow_from_integers():
272-
pa = pytest.importorskip("pyarrow")
273+
pa = td.versioned_importorskip("pyarrow")
273274

274275
data = [0, 123456789, None, 2**63 - 1, iNaT, -123456789]
275276
arr = pa.array(data)

pandas/tests/arrays/interval/test_interval_pyarrow.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import numpy as np
22
import pytest
33

4+
import pandas.util._test_decorators as td
45
import pandas as pd
56
import pandas._testing as tm
67
from pandas.core.arrays import IntervalArray
78

89

910
def test_arrow_extension_type():
10-
pa = pytest.importorskip("pyarrow")
11+
pa = td.versioned_importorskip("pyarrow")
1112

1213
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
1314

@@ -23,7 +24,7 @@ def test_arrow_extension_type():
2324

2425

2526
def test_arrow_array():
26-
pa = pytest.importorskip("pyarrow")
27+
pa = td.versioned_importorskip("pyarrow")
2728

2829
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
2930

@@ -52,7 +53,7 @@ def test_arrow_array():
5253

5354

5455
def test_arrow_array_missing():
55-
pa = pytest.importorskip("pyarrow")
56+
pa = td.versioned_importorskip("pyarrow")
5657

5758
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
5859

@@ -89,7 +90,7 @@ def test_arrow_array_missing():
8990
ids=["float", "datetime64[ns]"],
9091
)
9192
def test_arrow_table_roundtrip(breaks):
92-
pa = pytest.importorskip("pyarrow")
93+
pa = td.versioned_importorskip("pyarrow")
9394

9495
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
9596

@@ -125,7 +126,7 @@ def test_arrow_table_roundtrip(breaks):
125126
ids=["float", "datetime64[ns]"],
126127
)
127128
def test_arrow_table_roundtrip_without_metadata(breaks):
128-
pa = pytest.importorskip("pyarrow")
129+
pa = td.versioned_importorskip("pyarrow")
129130

130131
arr = IntervalArray.from_breaks(breaks)
131132
arr[1] = None
@@ -145,7 +146,7 @@ def test_from_arrow_from_raw_struct_array():
145146
# in case pyarrow lost the Interval extension type (eg on parquet roundtrip
146147
# with datetime64[ns] subtype, see GH-45881), still allow conversion
147148
# from arrow to IntervalArray
148-
pa = pytest.importorskip("pyarrow")
149+
pa = td.versioned_importorskip("pyarrow")
149150

150151
arr = pa.array([{"left": 0, "right": 1}, {"left": 1, "right": 2}])
151152
dtype = pd.IntervalDtype(np.dtype("int64"), closed="neither")

pandas/tests/arrays/masked/test_arrow_compat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import numpy as np
22
import pytest
33

4+
import pandas.util._test_decorators as td
45
import pandas as pd
56
import pandas._testing as tm
67

78
pytestmark = pytest.mark.filterwarnings(
89
"ignore:Passing a BlockManager to DataFrame:DeprecationWarning"
910
)
1011

11-
pa = pytest.importorskip("pyarrow")
12+
pa = td.versioned_importorskip("pyarrow")
1213

1314
from pandas.core.arrays.arrow._arrow_utils import pyarrow_array_to_numpy_and_mask
1415

pandas/tests/arrays/period/test_arrow_compat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
import pandas.util._test_decorators as td
34
from pandas.compat.pyarrow import pa_version_under10p1
45

56
from pandas.core.dtypes.dtypes import PeriodDtype
@@ -16,7 +17,7 @@
1617
)
1718

1819

19-
pa = pytest.importorskip("pyarrow")
20+
pa = td.versioned_importorskip("pyarrow")
2021

2122

2223
def test_arrow_extension_type():

pandas/tests/arrays/sparse/test_accessor.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import pytest
55

6+
import pandas.util._test_decorators as td
67
import pandas as pd
78
from pandas import SparseDtype
89
import pandas._testing as tm
@@ -26,7 +27,7 @@ def test_get_attributes(self, attr):
2627
assert result == expected
2728

2829
def test_from_coo(self):
29-
scipy_sparse = pytest.importorskip("scipy.sparse")
30+
scipy_sparse = td.versioned_importorskip("scipy.sparse")
3031

3132
row = [0, 3, 1, 0]
3233
col = [0, 3, 1, 2]
@@ -64,7 +65,7 @@ def test_from_coo(self):
6465
def test_to_coo(
6566
self, sort_labels, expected_rows, expected_cols, expected_values_pos
6667
):
67-
sp_sparse = pytest.importorskip("scipy.sparse")
68+
sp_sparse = td.versioned_importorskip("scipy.sparse")
6869

6970
values = SparseArray([0, np.nan, 1, 0, None, 3], fill_value=0)
7071
index = pd.MultiIndex.from_tuples(
@@ -107,7 +108,7 @@ def test_accessor_raises(self):
107108
@pytest.mark.parametrize("labels", [None, list(string.ascii_letters[:10])])
108109
@pytest.mark.parametrize("dtype", ["float64", "int64"])
109110
def test_from_spmatrix(self, format, labels, dtype):
110-
sp_sparse = pytest.importorskip("scipy.sparse")
111+
sp_sparse = td.versioned_importorskip("scipy.sparse")
111112

112113
sp_dtype = SparseDtype(dtype, np.array(0, dtype=dtype).item())
113114

@@ -120,7 +121,7 @@ def test_from_spmatrix(self, format, labels, dtype):
120121

121122
@pytest.mark.parametrize("format", ["csc", "csr", "coo"])
122123
def test_from_spmatrix_including_explicit_zero(self, format):
123-
sp_sparse = pytest.importorskip("scipy.sparse")
124+
sp_sparse = td.versioned_importorskip("scipy.sparse")
124125

125126
mat = sp_sparse.random(10, 2, density=0.5, format=format)
126127
mat.data[0] = 0
@@ -134,7 +135,7 @@ def test_from_spmatrix_including_explicit_zero(self, format):
134135
[["a", "b"], pd.MultiIndex.from_product([["A"], ["a", "b"]]), ["a", "a"]],
135136
)
136137
def test_from_spmatrix_columns(self, columns):
137-
sp_sparse = pytest.importorskip("scipy.sparse")
138+
sp_sparse = td.versioned_importorskip("scipy.sparse")
138139

139140
dtype = SparseDtype("float64", 0.0)
140141

@@ -147,7 +148,7 @@ def test_from_spmatrix_columns(self, columns):
147148
"colnames", [("A", "B"), (1, 2), (1, pd.NA), (0.1, 0.2), ("x", "x"), (0, 0)]
148149
)
149150
def test_to_coo(self, colnames):
150-
sp_sparse = pytest.importorskip("scipy.sparse")
151+
sp_sparse = td.versioned_importorskip("scipy.sparse")
151152

152153
df = pd.DataFrame(
153154
{colnames[0]: [0, 1, 0], colnames[1]: [1, 0, 0]}, dtype="Sparse[int64, 0]"
@@ -158,7 +159,7 @@ def test_to_coo(self, colnames):
158159

159160
@pytest.mark.parametrize("fill_value", [1, np.nan])
160161
def test_to_coo_nonzero_fill_val_raises(self, fill_value):
161-
pytest.importorskip("scipy")
162+
td.versioned_importorskip("scipy")
162163
df = pd.DataFrame(
163164
{
164165
"A": SparseArray(
@@ -174,7 +175,7 @@ def test_to_coo_nonzero_fill_val_raises(self, fill_value):
174175

175176
def test_to_coo_midx_categorical(self):
176177
# GH#50996
177-
sp_sparse = pytest.importorskip("scipy.sparse")
178+
sp_sparse = td.versioned_importorskip("scipy.sparse")
178179

179180
midx = pd.MultiIndex.from_arrays(
180181
[
@@ -219,7 +220,7 @@ def test_density(self):
219220
@pytest.mark.parametrize("dtype", ["int64", "float64"])
220221
@pytest.mark.parametrize("dense_index", [True, False])
221222
def test_series_from_coo(self, dtype, dense_index):
222-
sp_sparse = pytest.importorskip("scipy.sparse")
223+
sp_sparse = td.versioned_importorskip("scipy.sparse")
223224

224225
A = sp_sparse.eye(3, format="coo", dtype=dtype)
225226
result = pd.Series.sparse.from_coo(A, dense_index=dense_index)
@@ -239,7 +240,7 @@ def test_series_from_coo(self, dtype, dense_index):
239240

240241
def test_series_from_coo_incorrect_format_raises(self):
241242
# gh-26554
242-
sp_sparse = pytest.importorskip("scipy.sparse")
243+
sp_sparse = td.versioned_importorskip("scipy.sparse")
243244

244245
m = sp_sparse.csr_matrix(np.array([[0, 1], [0, 0]]))
245246
with pytest.raises(

pandas/tests/arrays/sparse/test_constructors.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
import pandas.util._test_decorators as td
45
from pandas._libs.sparse import IntIndex
56

67
import pandas as pd
@@ -188,7 +189,7 @@ def test_constructor_inferred_fill_value(self, data, fill_value):
188189
@pytest.mark.parametrize("format", ["coo", "csc", "csr"])
189190
@pytest.mark.parametrize("size", [0, 10])
190191
def test_from_spmatrix(self, size, format):
191-
sp_sparse = pytest.importorskip("scipy.sparse")
192+
sp_sparse = td.versioned_importorskip("scipy.sparse")
192193

193194
mat = sp_sparse.random(size, 1, density=0.5, format=format)
194195
result = SparseArray.from_spmatrix(mat)
@@ -199,7 +200,7 @@ def test_from_spmatrix(self, size, format):
199200

200201
@pytest.mark.parametrize("format", ["coo", "csc", "csr"])
201202
def test_from_spmatrix_including_explicit_zero(self, format):
202-
sp_sparse = pytest.importorskip("scipy.sparse")
203+
sp_sparse = td.versioned_importorskip("scipy.sparse")
203204

204205
mat = sp_sparse.random(10, 1, density=0.5, format=format)
205206
mat.data[0] = 0
@@ -210,7 +211,7 @@ def test_from_spmatrix_including_explicit_zero(self, format):
210211
tm.assert_numpy_array_equal(result, expected)
211212

212213
def test_from_spmatrix_raises(self):
213-
sp_sparse = pytest.importorskip("scipy.sparse")
214+
sp_sparse = td.versioned_importorskip("scipy.sparse")
214215

215216
mat = sp_sparse.eye(5, 4, format="csc")
216217

pandas/tests/arrays/string_/test_string.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pytest
99

10+
import pandas.util._test_decorators as td
1011
from pandas.compat.pyarrow import pa_version_under12p0
1112

1213
from pandas.core.dtypes.common import is_dtype_equal
@@ -486,7 +487,7 @@ def test_fillna_args(dtype, arrow_string_storage):
486487

487488
def test_arrow_array(dtype):
488489
# protocol added in 0.15.0
489-
pa = pytest.importorskip("pyarrow")
490+
pa = td.versioned_importorskip("pyarrow")
490491
import pyarrow.compute as pc
491492

492493
data = pd.array(["a", "b", "c"], dtype=dtype)
@@ -502,7 +503,7 @@ def test_arrow_array(dtype):
502503
@pytest.mark.filterwarnings("ignore:Passing a BlockManager:DeprecationWarning")
503504
def test_arrow_roundtrip(dtype, string_storage2, request, using_infer_string):
504505
# roundtrip possible from arrow 1.0.0
505-
pa = pytest.importorskip("pyarrow")
506+
pa = td.versioned_importorskip("pyarrow")
506507

507508
if using_infer_string and string_storage2 != "pyarrow_numpy":
508509
request.applymarker(
@@ -532,7 +533,7 @@ def test_arrow_load_from_zero_chunks(
532533
dtype, string_storage2, request, using_infer_string
533534
):
534535
# GH-41040
535-
pa = pytest.importorskip("pyarrow")
536+
pa = td.versioned_importorskip("pyarrow")
536537

537538
if using_infer_string and string_storage2 != "pyarrow_numpy":
538539
request.applymarker(

0 commit comments

Comments
 (0)