|
35 | 35 | except ImportError:
|
36 | 36 | _HAVE_FASTPARQUET = False
|
37 | 37 |
|
| 38 | + |
38 | 39 | pytestmark = pytest.mark.filterwarnings(
|
39 | 40 | "ignore:RangeIndex.* is deprecated:DeprecationWarning"
|
40 | 41 | )
|
@@ -223,6 +224,49 @@ def test_options_get_engine(fp, pa):
|
223 | 224 | assert isinstance(get_engine("fastparquet"), FastParquetImpl)
|
224 | 225 |
|
225 | 226 |
|
| 227 | +def test_get_engine_auto_error_message(): |
| 228 | + # Expect different error messages from get_engine(engine="auto") |
| 229 | + # if engines aren't installed vs. are installed but bad version |
| 230 | + from pandas.compat._optional import VERSIONS |
| 231 | + |
| 232 | + # Do we have engines installed, but a bad version of them? |
| 233 | + pa_min_ver = VERSIONS.get("pyarrow") |
| 234 | + fp_min_ver = VERSIONS.get("fastparquet") |
| 235 | + have_pa_bad_version = ( |
| 236 | + False |
| 237 | + if not _HAVE_PYARROW |
| 238 | + else LooseVersion(pyarrow.__version__) < LooseVersion(pa_min_ver) |
| 239 | + ) |
| 240 | + have_fp_bad_version = ( |
| 241 | + False |
| 242 | + if not _HAVE_FASTPARQUET |
| 243 | + else LooseVersion(fastparquet.__version__) < LooseVersion(fp_min_ver) |
| 244 | + ) |
| 245 | + # Do we have usable engines installed? |
| 246 | + have_usable_pa = _HAVE_PYARROW and not have_pa_bad_version |
| 247 | + have_usable_fp = _HAVE_FASTPARQUET and not have_fp_bad_version |
| 248 | + |
| 249 | + if not have_usable_pa and not have_usable_fp: |
| 250 | + # No usable engines found. |
| 251 | + if have_pa_bad_version: |
| 252 | + match = f"Pandas requires version .{pa_min_ver}. or newer of .pyarrow." |
| 253 | + with pytest.raises(ImportError, match=match): |
| 254 | + get_engine("auto") |
| 255 | + else: |
| 256 | + match = "Missing optional dependency .pyarrow." |
| 257 | + with pytest.raises(ImportError, match=match): |
| 258 | + get_engine("auto") |
| 259 | + |
| 260 | + if have_fp_bad_version: |
| 261 | + match = f"Pandas requires version .{fp_min_ver}. or newer of .fastparquet." |
| 262 | + with pytest.raises(ImportError, match=match): |
| 263 | + get_engine("auto") |
| 264 | + else: |
| 265 | + match = "Missing optional dependency .fastparquet." |
| 266 | + with pytest.raises(ImportError, match=match): |
| 267 | + get_engine("auto") |
| 268 | + |
| 269 | + |
226 | 270 | def test_cross_engine_pa_fp(df_cross_compat, pa, fp):
|
227 | 271 | # cross-compat with differing reading/writing engines
|
228 | 272 |
|
|
0 commit comments