|
19 | 19 | import polars as pl |
20 | 20 |
|
21 | 21 | if TYPE_CHECKING: |
22 | | - from collections.abc import Mapping |
| 22 | + from collections.abc import Callable, Mapping |
23 | 23 | from pathlib import Path |
24 | 24 | from types import ModuleType |
25 | 25 | from typing import TypeAlias |
@@ -207,57 +207,44 @@ def test_scan_fail_spark_like_without_session( |
207 | 207 | getattr(nw, scan_method)("unused.csv", backend=backend) |
208 | 208 |
|
209 | 209 |
|
210 | | -@pytest.mark.parametrize("csv_path", ["str"], indirect=True) |
211 | | -def test_read_csv_raise_sep_multiple_lazy(csv_path: FileSource) -> None: |
212 | | - pytest.importorskip("duckdb") |
213 | | - pytest.importorskip("pandas") |
214 | | - pytest.importorskip("pyarrow") |
215 | | - pytest.importorskip("sqlframe") |
216 | | - import duckdb |
217 | | - import pandas as pd |
218 | | - import pyarrow as pa |
219 | | - import sqlframe |
| 210 | +def _pyarrow_parse_options() -> dict[str, Any]: |
220 | 211 | from pyarrow import csv |
221 | | - from sqlframe.duckdb import DuckDBSession |
222 | 212 |
|
223 | | - msg = "do not match:" |
224 | | - with pytest.raises(TypeError, match=msg): |
225 | | - nw.read_csv( |
226 | | - csv_path, |
227 | | - backend=pa, |
228 | | - separator="|", |
229 | | - parse_options=csv.ParseOptions(delimiter=";"), |
230 | | - ) |
231 | | - with pytest.raises(TypeError, match=msg): |
232 | | - nw.scan_csv( |
233 | | - csv_path, |
234 | | - backend=pa, |
235 | | - separator="|", |
236 | | - parse_options=csv.ParseOptions(delimiter=";"), |
237 | | - ) |
238 | | - with pytest.raises(TypeError, match=msg): |
239 | | - nw.read_csv(csv_path, backend=pd, separator="|", sep=";") |
240 | | - with pytest.raises(TypeError, match=msg): |
241 | | - nw.scan_csv(csv_path, backend=pd, separator="|", sep=";") |
242 | | - with pytest.raises(TypeError, match=msg): |
243 | | - nw.scan_csv(csv_path, backend=duckdb, separator="|", delimiter=";") |
244 | | - with pytest.raises(TypeError, match=msg): |
245 | | - nw.scan_csv(csv_path, backend=duckdb, separator="|", delim=";") |
246 | | - with pytest.raises(TypeError, match=msg): |
247 | | - nw.scan_csv( |
248 | | - csv_path, |
249 | | - backend=sqlframe, |
250 | | - separator="|", |
251 | | - sep=";", |
252 | | - session=DuckDBSession(), |
253 | | - inferSchema=True, |
254 | | - ) |
255 | | - with pytest.raises(TypeError, match=msg): |
256 | | - nw.scan_csv( |
257 | | - csv_path, |
258 | | - backend=sqlframe, |
259 | | - separator="|", |
260 | | - delimiter=";", |
261 | | - session=DuckDBSession(), |
262 | | - inferSchema=True, |
263 | | - ) |
| 213 | + return {"parse_options": csv.ParseOptions(delimiter=";")} |
| 214 | + |
| 215 | + |
| 216 | +@pytest.mark.parametrize( |
| 217 | + ("backend", "into_kwargs"), |
| 218 | + [("pyarrow", _pyarrow_parse_options), ("pandas", lambda: {"sep": ";"})], |
| 219 | +) |
| 220 | +def test_read_csv_raise_on_conflicting_separator( |
| 221 | + backend: Literal["pandas", "pyarrow"], into_kwargs: Callable[[], dict[str, Any]] |
| 222 | +) -> None: |
| 223 | + pytest.importorskip(backend) |
| 224 | + kwargs = into_kwargs() |
| 225 | + with pytest.raises(TypeError, match="do not match:"): |
| 226 | + nw.read_csv("unused.csv", backend=backend, separator="|", **kwargs) |
| 227 | + |
| 228 | + |
| 229 | +@pytest.mark.parametrize( |
| 230 | + ("backend", "into_kwargs"), |
| 231 | + [ |
| 232 | + ("pyarrow", _pyarrow_parse_options), |
| 233 | + ("pandas", lambda: {"sep": ";"}), |
| 234 | + ("duckdb", lambda: {"delimiter": ";"}), |
| 235 | + ("duckdb", lambda: {"delim": ";"}), |
| 236 | + ("sqlframe", lambda: {"sep": ";"}), |
| 237 | + ("sqlframe", lambda: {"delimiter": ";"}), |
| 238 | + ], |
| 239 | +) |
| 240 | +def test_scan_csv_raise_on_conflicting_separator( |
| 241 | + backend: Literal["duckdb", "pandas", "pyarrow", "sqlframe"], |
| 242 | + into_kwargs: Callable[[], dict[str, Any]], |
| 243 | +) -> None: |
| 244 | + # Separator validation raises before the source is read (and, for spark-like |
| 245 | + # backends, before a session is required), so a literal path and a string |
| 246 | + # backend are enough. Backend objects are imported lazily via `into_kwargs`. |
| 247 | + pytest.importorskip(backend) |
| 248 | + kwargs = into_kwargs() |
| 249 | + with pytest.raises(TypeError, match="do not match:"): |
| 250 | + nw.scan_csv("unused.csv", backend=backend, separator="|", **kwargs) |
0 commit comments