Skip to content

Commit bf5bede

Browse files
authored
refactor: Reduce returns in Namespace.from_native_object (#2914)
1 parent 0e80656 commit bf5bede

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

narwhals/_namespace.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,36 +354,37 @@ def from_native_object(
354354
) -> Namespace[CompliantNamespaceAny]: ...
355355

356356
@classmethod
357-
def from_native_object( # noqa: PLR0911
357+
def from_native_object(
358358
cls: type[Namespace[Any]], native: NativeAny, /
359359
) -> Namespace[Any]:
360360
if is_native_polars(native):
361-
return cls.from_backend(Implementation.POLARS)
361+
impl = Implementation.POLARS
362362
elif is_native_pandas(native):
363-
return cls.from_backend(Implementation.PANDAS)
363+
impl = Implementation.PANDAS
364364
elif is_native_arrow(native):
365-
return cls.from_backend(Implementation.PYARROW)
365+
impl = Implementation.PYARROW
366366
elif is_native_spark_like(native):
367-
return cls.from_backend(
367+
impl = (
368368
Implementation.SQLFRAME
369369
if is_native_sqlframe(native)
370370
else Implementation.PYSPARK_CONNECT
371371
if is_native_pyspark_connect(native)
372372
else Implementation.PYSPARK
373373
)
374-
elif is_native_dask(native):
375-
return cls.from_backend(Implementation.DASK) # pragma: no cover
374+
elif is_native_dask(native): # pragma: no cover
375+
impl = Implementation.DASK
376376
elif is_native_duckdb(native):
377-
return cls.from_backend(Implementation.DUCKDB)
377+
impl = Implementation.DUCKDB
378378
elif is_native_cudf(native): # pragma: no cover
379-
return cls.from_backend(Implementation.CUDF)
379+
impl = Implementation.CUDF
380380
elif is_native_modin(native): # pragma: no cover
381-
return cls.from_backend(Implementation.MODIN)
381+
impl = Implementation.MODIN
382382
elif is_native_ibis(native):
383-
return cls.from_backend(Implementation.IBIS)
383+
impl = Implementation.IBIS
384384
else:
385385
msg = f"Unsupported type: {type(native).__qualname__!r}"
386386
raise TypeError(msg)
387+
return cls.from_backend(impl)
387388

388389

389390
def is_native_polars(obj: Any) -> TypeIs[_NativePolars]:

0 commit comments

Comments
 (0)