@@ -840,8 +840,13 @@ def _read_csv_impl(
840840 return from_native (native_frame , eager_only = True )
841841
842842
843+ @deprecate_native_namespace (warn_version = "1.31.0" , required = True )
843844def scan_csv (
844- source : str , * , native_namespace : ModuleType , ** kwargs : Any
845+ source : str ,
846+ * ,
847+ backend : ModuleType | Implementation | str | None = None ,
848+ native_namespace : ModuleType | None = None , # noqa: ARG001
849+ ** kwargs : Any ,
845850) -> LazyFrame [Any ]:
846851 """Lazily read from a CSV file.
847852
@@ -850,10 +855,22 @@ def scan_csv(
850855
851856 Arguments:
852857 source: Path to a file.
858+ backend: The eager backend for DataFrame creation.
859+ `backend` can be specified in various ways:
860+
861+ - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
862+ `POLARS`, `MODIN` or `CUDF`.
863+ - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
864+ - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
853865 native_namespace: The native library to use for DataFrame creation.
866+
867+ **Deprecated** (v1.31.0):
868+ Please use `backend` instead. Note that `native_namespace` is still available
869+ (and won't emit a deprecation warning) if you use `narwhals.stable.v1`,
870+ see [perfect backwards compatibility policy](../backcompat.md/).
854871 kwargs: Extra keyword arguments which are passed to the native CSV reader.
855872 For example, you could use
856- `nw.scan_csv('file.csv', native_namespace =pd, engine='pyarrow')`.
873+ `nw.scan_csv('file.csv', backend =pd, engine='pyarrow')`.
857874
858875 Returns:
859876 LazyFrame.
@@ -862,7 +879,7 @@ def scan_csv(
862879 >>> import duckdb
863880 >>> import narwhals as nw
864881 >>>
865- >>> nw.scan_csv("file.csv", native_namespace= duckdb).to_native() # doctest:+SKIP
882+ >>> nw.scan_csv("file.csv", backend=" duckdb" ).to_native() # doctest:+SKIP
866883 ┌─────────┬───────┐
867884 │ a │ b │
868885 │ varchar │ int32 │
@@ -872,13 +889,15 @@ def scan_csv(
872889 │ z │ 3 │
873890 └─────────┴───────┘
874891 """
875- return _scan_csv_impl (source , native_namespace = native_namespace , ** kwargs )
892+ backend = cast ("ModuleType | Implementation | str" , backend )
893+ return _scan_csv_impl (source , backend = backend , ** kwargs )
876894
877895
878896def _scan_csv_impl (
879- source : str , * , native_namespace : ModuleType , ** kwargs : Any
897+ source : str , * , backend : ModuleType | Implementation | str , ** kwargs : Any
880898) -> LazyFrame [Any ]:
881- implementation = Implementation .from_native_namespace (native_namespace )
899+ implementation = Implementation .from_backend (backend )
900+ native_namespace = implementation .to_native_namespace ()
882901 native_frame : NativeFrame | NativeLazyFrame
883902 if implementation is Implementation .POLARS :
884903 native_frame = native_namespace .scan_csv (source , ** kwargs )
0 commit comments