@@ -986,8 +986,13 @@ def _read_parquet_impl(
986986 return from_native (native_frame , eager_only = True )
987987
988988
989+ @deprecate_native_namespace (warn_version = "1.31.0" , required = True )
989990def scan_parquet (
990- source : str , * , native_namespace : ModuleType , ** kwargs : Any
991+ source : str ,
992+ * ,
993+ backend : ModuleType | Implementation | str | None = None ,
994+ native_namespace : ModuleType | None = None , # noqa: ARG001
995+ ** kwargs : Any ,
991996) -> LazyFrame [Any ]:
992997 """Lazily read from a parquet file.
993998
@@ -996,7 +1001,19 @@ def scan_parquet(
9961001
9971002 Arguments:
9981003 source: Path to a file.
1004+ backend: The eager backend for DataFrame creation.
1005+ `backend` can be specified in various ways:
1006+
1007+ - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
1008+ `POLARS`, `MODIN` or `CUDF`.
1009+ - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
1010+ - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
9991011 native_namespace: The native library to use for DataFrame creation.
1012+
1013+ **Deprecated** (v1.31.0):
1014+ Please use `backend` instead. Note that `native_namespace` is still available
1015+ (and won't emit a deprecation warning) if you use `narwhals.stable.v1`,
1016+ see [perfect backwards compatibility policy](../backcompat.md/).
10001017 kwargs: Extra keyword arguments which are passed to the native parquet reader.
10011018 For example, you could use
10021019 `nw.scan_parquet('file.parquet', native_namespace=pd, engine='pyarrow')`.
@@ -1008,9 +1025,7 @@ def scan_parquet(
10081025 >>> import dask.dataframe as dd
10091026 >>> import narwhals as nw
10101027 >>>
1011- >>> nw.scan_parquet(
1012- ... "file.parquet", native_namespace=dd
1013- ... ).collect() # doctest:+SKIP
1028+ >>> nw.scan_parquet("file.parquet", backend="dask").collect() # doctest:+SKIP
10141029 ┌──────────────────┐
10151030 |Narwhals DataFrame|
10161031 |------------------|
@@ -1019,13 +1034,15 @@ def scan_parquet(
10191034 | 1 2 5 |
10201035 └──────────────────┘
10211036 """
1022- return _scan_parquet_impl (source , native_namespace = native_namespace , ** kwargs )
1037+ backend = cast ("ModuleType | Implementation | str" , backend )
1038+ return _scan_parquet_impl (source , backend = backend , ** kwargs )
10231039
10241040
10251041def _scan_parquet_impl (
1026- source : str , * , native_namespace : ModuleType , ** kwargs : Any
1042+ source : str , * , backend : ModuleType | Implementation | str , ** kwargs : Any
10271043) -> LazyFrame [Any ]:
1028- implementation = Implementation .from_native_namespace (native_namespace )
1044+ implementation = Implementation .from_backend (backend )
1045+ native_namespace = implementation .to_native_namespace ()
10291046 native_frame : NativeFrame | NativeLazyFrame
10301047 if implementation is Implementation .POLARS :
10311048 native_frame = native_namespace .scan_parquet (source , ** kwargs )
0 commit comments