Skip to content

Commit

Permalink
chore: remove more trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jan 7, 2025
1 parent 1bdf4dc commit f6c6af5
Show file tree
Hide file tree
Showing 44 changed files with 168 additions and 606 deletions.
4 changes: 2 additions & 2 deletions narwhals/_arrow/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def join(
join_type="inner",
right_suffix=suffix,
)
.drop([key_token]),
.drop([key_token])
)

return self._from_native_frame(
Expand All @@ -370,7 +370,7 @@ def join(
right_keys=right_on,
join_type=how_to_join_map[how],
right_suffix=suffix,
),
)
)

def join_asof(
Expand Down
30 changes: 5 additions & 25 deletions narwhals/_arrow/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ def mode(self: Self) -> Self:
return reuse_series_implementation(self, "mode")

def map_batches(
self: Self,
function: Callable[[Any], Any],
return_dtype: DType | None,
self: Self, function: Callable[[Any], Any], return_dtype: DType | None
) -> Self:
def func(df: ArrowDataFrame) -> list[ArrowSeries]:
input_series_list = self._call(df)
Expand Down Expand Up @@ -463,11 +461,7 @@ def cum_prod(self: Self, *, reverse: bool) -> Self:
return reuse_series_implementation(self, "cum_prod", reverse=reverse)

def rolling_sum(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
self: Self, window_size: int, *, min_periods: int | None, center: bool
) -> Self:
return reuse_series_implementation(
self,
Expand All @@ -478,11 +472,7 @@ def rolling_sum(
)

def rolling_mean(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
self: Self, window_size: int, *, min_periods: int | None, center: bool
) -> Self:
return reuse_series_implementation(
self,
Expand All @@ -493,12 +483,7 @@ def rolling_mean(
)

def rolling_var(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
ddof: int,
self: Self, window_size: int, *, min_periods: int | None, center: bool, ddof: int
) -> Self:
return reuse_series_implementation(
self,
Expand All @@ -510,12 +495,7 @@ def rolling_var(
)

def rolling_std(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
ddof: int,
self: Self, window_size: int, *, min_periods: int | None, center: bool, ddof: int
) -> Self:
return reuse_series_implementation(
self,
Expand Down
8 changes: 2 additions & 6 deletions narwhals/_arrow/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ def __init__(
self._grouped = pa.TableGroupBy(self._df._native_frame, list(self._keys))

def agg(
self: Self,
*aggs: IntoArrowExpr,
**named_aggs: IntoArrowExpr,
self: Self, *aggs: IntoArrowExpr, **named_aggs: IntoArrowExpr
) -> ArrowDataFrame:
exprs = parse_into_exprs(
*aggs,
namespace=self._df.__narwhals_namespace__(),
**named_aggs,
*aggs, namespace=self._df.__narwhals_namespace__(), **named_aggs
)
for expr in exprs:
if expr._output_names is None:
Expand Down
5 changes: 1 addition & 4 deletions narwhals/_arrow/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ def selectors(self: Self) -> ArrowSelectorNamespace:
backend_version=self._backend_version, version=self._version
)

def when(
self: Self,
*predicates: IntoArrowExpr,
) -> ArrowWhen:
def when(self: Self, *predicates: IntoArrowExpr) -> ArrowWhen:
plx = self.__class__(backend_version=self._backend_version, version=self._version)
condition = plx.all_horizontal(*predicates)
return ArrowWhen(condition, self._backend_version, version=self._version)
Expand Down
2 changes: 1 addition & 1 deletion narwhals/_arrow/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def numeric(self: Self) -> ArrowSelector:
dtypes.UInt8,
dtypes.Float64,
dtypes.Float32,
],
]
)

def categorical(self: Self) -> ArrowSelector:
Expand Down
31 changes: 6 additions & 25 deletions narwhals/_arrow/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,7 @@ def cum_prod(self: Self, *, reverse: bool) -> Self:
return self._from_native_series(result)

def rolling_sum(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
self: Self, window_size: int, *, min_periods: int | None, center: bool
) -> Self:
import pyarrow.compute as pc

Expand Down Expand Up @@ -992,11 +988,7 @@ def rolling_sum(
return result[offset:]

def rolling_mean(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
self: Self, window_size: int, *, min_periods: int | None, center: bool
) -> Self:
import pyarrow.compute as pc

Expand Down Expand Up @@ -1031,12 +1023,7 @@ def rolling_mean(
return result[offset:]

def rolling_var(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
ddof: int,
self: Self, window_size: int, *, min_periods: int | None, center: bool, ddof: int
) -> Self:
import pyarrow.compute as pc # ignore-banned-import

Expand Down Expand Up @@ -1083,12 +1070,7 @@ def rolling_var(
return result[offset:]

def rolling_std(
self: Self,
window_size: int,
*,
min_periods: int | None,
center: bool,
ddof: int,
self: Self, window_size: int, *, min_periods: int | None, center: bool, ddof: int
) -> Self:
return (
self.rolling_var(
Expand Down Expand Up @@ -1149,8 +1131,7 @@ def __contains__(self: Self, other: Any) -> bool:
else pa.scalar(None, type=native_series.type)
)
return maybe_extract_py_scalar( # type: ignore[no-any-return]
pc.is_in(other_, native_series),
return_py_scalar=True,
pc.is_in(other_, native_series), return_py_scalar=True
)
except (ArrowInvalid, ArrowNotImplementedError, ArrowTypeError) as exc:
from narwhals.exceptions import InvalidOperationError
Expand Down Expand Up @@ -1553,7 +1534,7 @@ def slice(self: Self, offset: int, length: int | None) -> ArrowSeries:
return self._compliant_series._from_native_series(
pc.utf8_slice_codeunits(
self._compliant_series._native_series, start=offset, stop=stop
),
)
)

def to_datetime(self: Self, format: str | None) -> ArrowSeries: # noqa: A002
Expand Down
3 changes: 1 addition & 2 deletions narwhals/_arrow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ def floordiv_compat(left: Any, right: Any) -> Any:
# GH 56676
has_remainder = pc.not_equal(pc.multiply(divided, right), left)
has_one_negative_operand = pc.less(
pc.bit_wise_xor(left, right),
pa.scalar(0, type=divided.type),
pc.bit_wise_xor(left, right), pa.scalar(0, type=divided.type)
)
result = pc.if_else(
pc.and_(
Expand Down
17 changes: 5 additions & 12 deletions narwhals/_dask/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ def filter(self, *predicates: DaskExpr, **constraints: Any) -> Self:
mask = expr._call(self)[0]
return self._from_native_frame(self._native_frame.loc[mask])

def select(
self: Self,
*exprs: IntoDaskExpr,
**named_exprs: IntoDaskExpr,
) -> Self:
def select(self: Self, *exprs: IntoDaskExpr, **named_exprs: IntoDaskExpr) -> Self:
import dask.dataframe as dd

if exprs and all(isinstance(x, str) for x in exprs) and not named_exprs:
Expand Down Expand Up @@ -193,10 +189,7 @@ def head(self: Self, n: int) -> Self:
)

def unique(
self: Self,
subset: list[str] | None,
*,
keep: Literal["any", "none"] = "any",
self: Self, subset: list[str] | None, *, keep: Literal["any", "none"] = "any"
) -> Self:
if subset is not None and any(x not in self.columns for x in subset):
msg = f"Column(s) {subset} not found in {self.columns}"
Expand Down Expand Up @@ -259,7 +252,7 @@ def join(
right_on=key_token,
suffixes=("", suffix),
)
.drop(columns=key_token),
.drop(columns=key_token)
)

if how == "anti":
Expand Down Expand Up @@ -342,7 +335,7 @@ def join(
right_on=right_on,
how=how,
suffixes=("", suffix),
),
)
)

def join_asof(
Expand Down Expand Up @@ -370,7 +363,7 @@ def join_asof(
by=by,
direction=strategy,
suffixes=("", "_right"),
),
)
)

def group_by(self, *by: str, drop_null_keys: bool) -> DaskLazyGroupBy:
Expand Down
28 changes: 7 additions & 21 deletions narwhals/_dask/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def func(df: DaskLazyFrame) -> list[dask_expr.Series]:
except KeyError as e:
missing_columns = [x for x in column_names if x not in df.columns]
raise ColumnNotFoundError.from_missing_and_available_column_names(
missing_columns=missing_columns,
available_columns=df.columns,
missing_columns=missing_columns, available_columns=df.columns
) from e

return cls(
Expand Down Expand Up @@ -360,9 +359,7 @@ def cum_sum(self: Self, *, reverse: bool) -> Self:
raise NotImplementedError(msg)

return self._from_call(
lambda _input: _input.cumsum(),
"cum_sum",
returns_scalar=self._returns_scalar,
lambda _input: _input.cumsum(), "cum_sum", returns_scalar=self._returns_scalar
)

def cum_count(self: Self, *, reverse: bool) -> Self:
Expand All @@ -382,9 +379,7 @@ def cum_min(self: Self, *, reverse: bool) -> Self:
raise NotImplementedError(msg)

return self._from_call(
lambda _input: _input.cummin(),
"cum_min",
returns_scalar=self._returns_scalar,
lambda _input: _input.cummin(), "cum_min", returns_scalar=self._returns_scalar
)

def cum_max(self: Self, *, reverse: bool) -> Self:
Expand All @@ -393,9 +388,7 @@ def cum_max(self: Self, *, reverse: bool) -> Self:
raise NotImplementedError(msg)

return self._from_call(
lambda _input: _input.cummax(),
"cum_max",
returns_scalar=self._returns_scalar,
lambda _input: _input.cummax(), "cum_max", returns_scalar=self._returns_scalar
)

def cum_prod(self: Self, *, reverse: bool) -> Self:
Expand All @@ -410,10 +403,7 @@ def cum_prod(self: Self, *, reverse: bool) -> Self:
)

def is_between(
self,
lower_bound: Self | Any,
upper_bound: Self | Any,
closed: str = "both",
self, lower_bound: Self | Any, upper_bound: Self | Any, closed: str = "both"
) -> Self:
if closed == "none":
closed = "neither"
Expand Down Expand Up @@ -537,9 +527,7 @@ def func(
)

def clip(
self: Self,
lower_bound: Self | Any | None,
upper_bound: Self | Any | None,
self: Self, lower_bound: Self | Any | None, upper_bound: Self | Any | None
) -> Self:
return self._from_call(
lambda _input, lower_bound, upper_bound: _input.clip(
Expand Down Expand Up @@ -669,9 +657,7 @@ def is_in(self: Self, other: Any) -> Self:

def null_count(self: Self) -> Self:
return self._from_call(
lambda _input: _input.isna().sum(),
"null_count",
returns_scalar=True,
lambda _input: _input.isna().sum(), "null_count", returns_scalar=True
)

def tail(self: Self) -> NoReturn:
Expand Down
26 changes: 5 additions & 21 deletions narwhals/_dask/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def chunk(s: pd.core.groupby.generic.SeriesGroupBy) -> int:
def agg(s0: pd.core.groupby.generic.SeriesGroupBy) -> int:
return s0.sum() # type: ignore[no-any-return]

return dd.Aggregation(
name="nunique",
chunk=chunk,
agg=agg,
)
return dd.Aggregation(name="nunique", chunk=chunk, agg=agg)


def var(
Expand Down Expand Up @@ -81,20 +77,12 @@ def __init__(
self._df = df
self._keys = keys
self._grouped = self._df._native_frame.groupby(
list(self._keys),
dropna=drop_null_keys,
observed=True,
list(self._keys), dropna=drop_null_keys, observed=True
)

def agg(
self,
*aggs: IntoDaskExpr,
**named_aggs: IntoDaskExpr,
) -> DaskLazyFrame:
def agg(self, *aggs: IntoDaskExpr, **named_aggs: IntoDaskExpr) -> DaskLazyFrame:
exprs = parse_into_exprs(
*aggs,
namespace=self._df.__narwhals_namespace__(),
**named_aggs,
*aggs, namespace=self._df.__narwhals_namespace__(), **named_aggs
)
output_names: list[str] = copy(self._keys)
for expr in exprs:
Expand All @@ -109,11 +97,7 @@ def agg(
output_names.extend(expr._output_names)

return agg_dask(
self._df,
self._grouped,
exprs,
self._keys,
self._from_native_frame,
self._df, self._grouped, exprs, self._keys, self._from_native_frame
)

def _from_native_frame(self, df: DaskLazyFrame) -> DaskLazyFrame:
Expand Down
5 changes: 1 addition & 4 deletions narwhals/_dask/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,7 @@ def func(df: DaskLazyFrame) -> list[dask_expr.Series]:
kwargs={"exprs": exprs},
)

def when(
self,
*predicates: IntoDaskExpr,
) -> DaskWhen:
def when(self, *predicates: IntoDaskExpr) -> DaskWhen:
plx = self.__class__(backend_version=self._backend_version, version=self._version)
condition = plx.all_horizontal(*predicates)
return DaskWhen(
Expand Down
Loading

0 comments on commit f6c6af5

Please sign in to comment.