|
56 | 56 |
|
57 | 57 | from narwhals._compliant import CompliantExpr |
58 | 58 | from narwhals._compliant import CompliantFrameT |
| 59 | + from narwhals._compliant import CompliantNamespace |
59 | 60 | from narwhals._compliant import CompliantSeriesOrNativeExprT_co |
60 | 61 | from narwhals._compliant import NativeFrameT_co |
61 | 62 | from narwhals._compliant import NativeSeriesT_co |
@@ -344,6 +345,44 @@ def to_native_namespace(self: Self) -> ModuleType: |
344 | 345 | msg = "Not supported Implementation" # pragma: no cover |
345 | 346 | raise AssertionError(msg) |
346 | 347 |
|
| 348 | + def _to_compliant_namespace( |
| 349 | + self, version: Version, / |
| 350 | + ) -> CompliantNamespace[Any, Any]: |
| 351 | + native = self.to_native_namespace() |
| 352 | + into_version = native if not self.is_sqlframe() else native._version |
| 353 | + backend_version = parse_version(into_version) |
| 354 | + if self.is_pandas_like(): |
| 355 | + from narwhals._pandas_like.namespace import PandasLikeNamespace |
| 356 | + |
| 357 | + return PandasLikeNamespace( |
| 358 | + implementation=self, backend_version=backend_version, version=version |
| 359 | + ) |
| 360 | + elif self.is_polars(): |
| 361 | + from narwhals._polars.namespace import PolarsNamespace |
| 362 | + |
| 363 | + return PolarsNamespace(backend_version=backend_version, version=version) |
| 364 | + elif self.is_pyarrow(): |
| 365 | + from narwhals._arrow.namespace import ArrowNamespace |
| 366 | + |
| 367 | + return ArrowNamespace(backend_version=backend_version, version=version) |
| 368 | + elif self.is_spark_like(): |
| 369 | + from narwhals._spark_like.namespace import SparkLikeNamespace |
| 370 | + |
| 371 | + return SparkLikeNamespace( |
| 372 | + implementation=self, backend_version=backend_version, version=version |
| 373 | + ) |
| 374 | + elif self.is_duckdb(): |
| 375 | + from narwhals._duckdb.namespace import DuckDBNamespace |
| 376 | + |
| 377 | + return DuckDBNamespace(backend_version=backend_version, version=version) |
| 378 | + elif self.is_dask(): |
| 379 | + from narwhals._dask.namespace import DaskNamespace |
| 380 | + |
| 381 | + return DaskNamespace(backend_version=backend_version, version=version) |
| 382 | + else: |
| 383 | + msg = "Not supported Implementation" # pragma: no cover |
| 384 | + raise AssertionError(msg) |
| 385 | + |
347 | 386 | def is_pandas(self: Self) -> bool: |
348 | 387 | """Return whether implementation is pandas. |
349 | 388 |
|
|
0 commit comments