Skip to content

Commit

Permalink
rm imports
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Jan 27, 2025
1 parent 7c84531 commit 31dd90f
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 43 deletions.
4 changes: 0 additions & 4 deletions narwhals/_duckdb/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ def collect_schema(self: Self) -> dict[str, DType]:

def unique(self: Self, subset: Sequence[str] | None, keep: str) -> Self:
if subset is not None:
import duckdb

rel = self._native_frame
# Sanitise input
if any(x not in rel.columns for x in subset):
Expand Down Expand Up @@ -365,8 +363,6 @@ def sort(
return self._from_native_frame(result)

def drop_nulls(self: Self, subset: list[str] | None) -> Self:
import duckdb

rel = self._native_frame
subset_ = subset if subset is not None else rel.columns
keep_condition = " and ".join(f'"{col}" is not null' for col in subset_)
Expand Down
5 changes: 0 additions & 5 deletions narwhals/_polars/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def _from_native_object(

def __getattr__(self: Self, attr: str) -> Any:
def func(*args: Any, **kwargs: Any) -> Any:
import polars as pl

args, kwargs = extract_args_kwargs(args, kwargs) # type: ignore[assignment]
try:
return self._from_native_object(
Expand Down Expand Up @@ -176,7 +174,6 @@ def __getitem__(self: Self, item: Any) -> Any:
)
msg = f"Expected slice of integers or strings, got: {type(item[1])}" # pragma: no cover
raise TypeError(msg) # pragma: no cover
import polars as pl

if (
isinstance(item, tuple)
Expand Down Expand Up @@ -412,8 +409,6 @@ def collect_schema(self: Self) -> dict[str, DType]:
}

def collect(self: Self) -> PolarsDataFrame:
import polars as pl

try:
result = self._native_frame.collect()
except pl.exceptions.ColumnNotFoundError as e:
Expand Down
6 changes: 0 additions & 6 deletions narwhals/_polars/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def ewm_mean(
**extra_kwargs,
)
if self._backend_version < (1,): # pragma: no cover
import polars as pl

return self._from_native_expr(
pl.when(~expr.is_null()).then(native_expr).otherwise(None)
)
Expand Down Expand Up @@ -352,14 +350,10 @@ def len(self: Self) -> PolarsExpr:
native_result = native_expr.list.len()

if self._expr._backend_version < (1, 16): # pragma: no cover
import polars as pl

native_result: pl.Expr = ( # type: ignore[no-redef]
pl.when(~native_expr.is_null()).then(native_result).cast(pl.UInt32())
)
elif self._expr._backend_version < (1, 17): # pragma: no cover
import polars as pl

native_result = native_result.cast(pl.UInt32())

return self._expr._from_native_expr(native_result)
Expand Down
10 changes: 0 additions & 10 deletions narwhals/_polars/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ def by_dtype(self: Self, dtypes: Iterable[DType]) -> PolarsExpr:
)

def numeric(self: Self) -> PolarsExpr:
import polars as pl

from narwhals._polars.expr import PolarsExpr

return PolarsExpr(
Expand All @@ -236,8 +234,6 @@ def numeric(self: Self) -> PolarsExpr:
)

def boolean(self: Self) -> PolarsExpr:
import polars as pl

from narwhals._polars.expr import PolarsExpr

return PolarsExpr(
Expand All @@ -247,8 +243,6 @@ def boolean(self: Self) -> PolarsExpr:
)

def string(self: Self) -> PolarsExpr:
import polars as pl

from narwhals._polars.expr import PolarsExpr

return PolarsExpr(
Expand All @@ -258,8 +252,6 @@ def string(self: Self) -> PolarsExpr:
)

def categorical(self: Self) -> PolarsExpr:
import polars as pl

from narwhals._polars.expr import PolarsExpr

return PolarsExpr(
Expand All @@ -269,8 +261,6 @@ def categorical(self: Self) -> PolarsExpr:
)

def all(self: Self) -> PolarsExpr:
import polars as pl

from narwhals._polars.expr import PolarsExpr

return PolarsExpr(
Expand Down
14 changes: 0 additions & 14 deletions narwhals/_polars/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def _from_native_object(self: Self, series: T) -> T: ...
def _from_native_object(
self: Self, series: pl.Series | pl.DataFrame | T
) -> Self | PolarsDataFrame | T:
import polars as pl

if isinstance(series, pl.Series):
return self._from_native_series(series)
if isinstance(series, pl.DataFrame):
Expand Down Expand Up @@ -244,8 +242,6 @@ def median(self: Self) -> Any:
return self._native_series.median()

def to_dummies(self: Self, *, separator: str, drop_first: bool) -> PolarsDataFrame:
import polars as pl

from narwhals._polars.dataframe import PolarsDataFrame

if self._backend_version < (0, 20, 15):
Expand Down Expand Up @@ -294,8 +290,6 @@ def ewm_mean(
**extra_kwargs,
)
if self._backend_version < (1,): # pragma: no cover
import polars as pl

return self._from_native_series(
pl.select(
pl.when(~native_series.is_null()).then(native_result).otherwise(None)
Expand Down Expand Up @@ -405,8 +399,6 @@ def sort(self: Self, *, descending: bool, nulls_last: bool) -> Self:
result = self._native_series.sort(descending=descending)

if nulls_last:
import polars as pl

is_null = result.is_null()
result = pl.concat([result.filter(~is_null), result.filter(is_null)])
else:
Expand All @@ -433,8 +425,6 @@ def value_counts(
from narwhals._polars.dataframe import PolarsDataFrame

if self._backend_version < (1, 0, 0):
import polars as pl

value_name_ = name or ("proportion" if normalize else "count")

result = self._native_series.value_counts(sort=sort, parallel=parallel)
Expand Down Expand Up @@ -547,15 +537,11 @@ def len(self: Self) -> PolarsSeries:
native_result = native_series.list.len()

if self._series._backend_version < (1, 16): # pragma: no cover
import polars as pl

native_result = pl.select(
pl.when(~native_series.is_null()).then(native_result).otherwise(None)
)[native_series.name].cast(pl.UInt32())

elif self._series._backend_version < (1, 17): # pragma: no cover
import polars as pl

native_result = native_series.cast(pl.UInt32())

return self._series._from_native_series(native_result)
Expand Down
2 changes: 0 additions & 2 deletions narwhals/_polars/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ def native_to_narwhals_dtype(
def narwhals_to_native_dtype(
dtype: DType | type[DType], version: Version, backend_version: tuple[int, ...]
) -> pl.DataType:
import polars as pl

dtypes = import_dtypes_module(version)

if dtype == dtypes.Float64:
Expand Down
2 changes: 0 additions & 2 deletions narwhals/_spark_like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from narwhals.utils import isinstance_or_issubclass

if TYPE_CHECKING:
from pyspark.sql import Column

from narwhals._spark_like.dataframe import SparkLikeLazyFrame
from narwhals._spark_like.expr import SparkLikeExpr
from narwhals.dtypes import DType
Expand Down

0 comments on commit 31dd90f

Please sign in to comment.