From 10edfbfacc60f95daf407e553730182dbf3b18ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:35:15 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.1 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.1...v0.3.2) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9f56f374a..917b86cb1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.2.1 + rev: v0.3.2 hooks: # Run the formatter. - id: ruff-format @@ -9,7 +9,7 @@ repos: - id: ruff args: [--fix] - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.8.0' + rev: 'v1.9.0' hooks: - id: mypy additional_dependencies: ['polars==0.20.10', 'pytest==8.0.1'] From 613015476fc2275f105cf5101288452579b6d609 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:35:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- narwhals/pandas_like/dtypes.py | 54 +++----- narwhals/polars.py | 48 +++---- narwhals/spec/__init__.py | 230 +++++++++++---------------------- 3 files changed, 112 insertions(+), 220 deletions(-) diff --git a/narwhals/pandas_like/dtypes.py b/narwhals/pandas_like/dtypes.py index 318016b51..fac53db5c 100644 --- a/narwhals/pandas_like/dtypes.py +++ b/narwhals/pandas_like/dtypes.py @@ -21,73 +21,55 @@ def __eq__(self, other: DType | type[DType]) -> bool: # type: ignore[override] return isinstance_or_issubclass(other, type(self)) -class NumericType(DType): - ... +class NumericType(DType): ... -class TemporalType(DType): - ... +class TemporalType(DType): ... -class Int64(NumericType): - ... +class Int64(NumericType): ... -class Int32(NumericType): - ... +class Int32(NumericType): ... -class Int16(NumericType): - ... +class Int16(NumericType): ... -class Int8(NumericType): - ... +class Int8(NumericType): ... -class UInt64(NumericType): - ... +class UInt64(NumericType): ... -class UInt32(NumericType): - ... +class UInt32(NumericType): ... -class UInt16(NumericType): - ... +class UInt16(NumericType): ... -class UInt8(NumericType): - ... +class UInt8(NumericType): ... -class Float64(NumericType): - ... +class Float64(NumericType): ... -class Float32(NumericType): - ... +class Float32(NumericType): ... -class String(DType): - ... +class String(DType): ... -class Boolean(DType): - ... +class Boolean(DType): ... -class Object(DType): - ... +class Object(DType): ... -class Datetime(DType): - ... +class Datetime(DType): ... -class Date(DType): - ... +class Date(DType): ... -class Duration(DType): - ... +class Duration(DType): ... diff --git a/narwhals/polars.py b/narwhals/polars.py index af2f93488..9407d3a1a 100644 --- a/narwhals/polars.py +++ b/narwhals/polars.py @@ -154,68 +154,52 @@ def is_numeric(cls: type[Self]) -> bool: return reverse_translate_dtype(cls).is_numeric() # type: ignore[no-any-return] -class NumericType(DType): - ... +class NumericType(DType): ... -class TemporalType(DType): - ... +class TemporalType(DType): ... -class Int64(NumericType): - ... +class Int64(NumericType): ... -class Int32(NumericType): - ... +class Int32(NumericType): ... -class Int16(NumericType): - ... +class Int16(NumericType): ... -class Int8(NumericType): - ... +class Int8(NumericType): ... -class UInt64(NumericType): - ... +class UInt64(NumericType): ... -class UInt32(NumericType): - ... +class UInt32(NumericType): ... -class UInt16(NumericType): - ... +class UInt16(NumericType): ... -class UInt8(NumericType): - ... +class UInt8(NumericType): ... -class Float64(NumericType): - ... +class Float64(NumericType): ... -class Float32(NumericType): - ... +class Float32(NumericType): ... -class String(DType): - ... +class String(DType): ... -class Boolean(DType): - ... +class Boolean(DType): ... -class Datetime(TemporalType): - ... +class Datetime(TemporalType): ... -class Date(TemporalType): - ... +class Date(TemporalType): ... class Namespace(NamespaceProtocol): diff --git a/narwhals/spec/__init__.py b/narwhals/spec/__init__.py index 83903c4c7..8363dbbc9 100644 --- a/narwhals/spec/__init__.py +++ b/narwhals/spec/__init__.py @@ -13,102 +13,75 @@ class Expr(Protocol): # --- convert --- - def alias(self, name: str) -> Self: - ... + def alias(self, name: str) -> Self: ... - def cast(self, dtype: DType) -> Self: - ... + def cast(self, dtype: DType) -> Self: ... # --- binary --- def __eq__(self, other: object) -> Expr: # type: ignore[override] ... - def __and__(self, other: Any) -> Expr: - ... + def __and__(self, other: Any) -> Expr: ... - def __or__(self, other: Any) -> Expr: - ... + def __or__(self, other: Any) -> Expr: ... - def __add__(self, other: Any) -> Expr: - ... + def __add__(self, other: Any) -> Expr: ... - def __radd__(self, other: Any) -> Expr: - ... + def __radd__(self, other: Any) -> Expr: ... - def __sub__(self, other: Any) -> Expr: - ... + def __sub__(self, other: Any) -> Expr: ... - def __rsub__(self, other: Any) -> Expr: - ... + def __rsub__(self, other: Any) -> Expr: ... - def __mul__(self, other: Any) -> Expr: - ... + def __mul__(self, other: Any) -> Expr: ... - def __rmul__(self, other: Any) -> Expr: - ... + def __rmul__(self, other: Any) -> Expr: ... - def __le__(self, other: Any) -> Expr: - ... + def __le__(self, other: Any) -> Expr: ... - def __lt__(self, other: Any) -> Expr: - ... + def __lt__(self, other: Any) -> Expr: ... - def __gt__(self, other: Any) -> Expr: - ... + def __gt__(self, other: Any) -> Expr: ... - def __ge__(self, other: Any) -> Expr: - ... + def __ge__(self, other: Any) -> Expr: ... # --- unary --- - def mean(self) -> Expr: - ... + def mean(self) -> Expr: ... - def sum(self) -> Expr: - ... + def sum(self) -> Expr: ... - def min(self) -> Expr: - ... + def min(self) -> Expr: ... - def max(self) -> Expr: - ... + def max(self) -> Expr: ... - def n_unique(self) -> Expr: - ... + def n_unique(self) -> Expr: ... # --- transform --- def is_between( self, lower_bound: Any, upper_bound: Any, closed: str = "both" - ) -> Expr: - ... + ) -> Expr: ... - def is_in(self, other: Any) -> Expr: - ... + def is_in(self, other: Any) -> Expr: ... - def is_null(self) -> Expr: - ... + def is_null(self) -> Expr: ... # --- partial reduction --- - def drop_nulls(self) -> Expr: - ... + def drop_nulls(self) -> Expr: ... - def sample(self, n: int, fraction: float, *, with_replacement: bool) -> Expr: - ... + def sample(self, n: int, fraction: float, *, with_replacement: bool) -> Expr: ... # --- namespaces --- @property - def str(self) -> ExprStringNamespace: - ... + def str(self) -> ExprStringNamespace: ... class ExprStringNamespace(Protocol): - def ends_with(self, suffix: str) -> Expr: - ... + def ends_with(self, suffix: str) -> Expr: ... class DType(Protocol): @classmethod - def is_numeric(cls: type[Self]) -> bool: - ... + def is_numeric(cls: type[Self]) -> bool: ... class Namespace(Protocol): @@ -126,129 +99,96 @@ class Namespace(Protocol): String: DType # --- selection --- - def col(self, *names: str | Iterable[str]) -> Expr: - ... + def col(self, *names: str | Iterable[str]) -> Expr: ... - def all(self) -> Expr: - ... + def all(self) -> Expr: ... # --- reduction --- - def sum(self, *columns: str) -> Expr: - ... + def sum(self, *columns: str) -> Expr: ... - def mean(self, *columns: str) -> Expr: - ... + def mean(self, *columns: str) -> Expr: ... - def max(self, *columns: str) -> Expr: - ... + def max(self, *columns: str) -> Expr: ... - def min(self, *columns: str) -> Expr: - ... + def min(self, *columns: str) -> Expr: ... - def len(self) -> Expr: - ... + def len(self) -> Expr: ... # --- horizontal --- - def all_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> Expr: - ... + def all_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> Expr: ... - def any_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> Expr: - ... + def any_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> Expr: ... - def sum_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> Expr: - ... + def sum_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> Expr: ... - def concat(self, items: Iterable[DataFrame], *, how: str = "vertical") -> DataFrame: - ... + def concat( + self, items: Iterable[DataFrame], *, how: str = "vertical" + ) -> DataFrame: ... class Series(Protocol): - def alias(self, name: str) -> Self: - ... + def alias(self, name: str) -> Self: ... @property - def name(self) -> str: - ... + def name(self) -> str: ... @property - def shape(self) -> tuple[int]: - ... + def shape(self) -> tuple[int]: ... - def rename(self, name: str) -> Self: - ... + def rename(self, name: str) -> Self: ... - def cast(self, dtype: DType) -> Self: - ... + def cast(self, dtype: DType) -> Self: ... - def item(self) -> Any: - ... + def item(self) -> Any: ... def is_between( self, lower_bound: Any, upper_bound: Any, closed: str = "both" - ) -> Series: - ... + ) -> Series: ... - def is_in(self, other: Any) -> Series: - ... + def is_in(self, other: Any) -> Series: ... - def is_null(self) -> Series: - ... + def is_null(self) -> Series: ... - def drop_nulls(self) -> Series: - ... + def drop_nulls(self) -> Series: ... - def n_unique(self) -> int: - ... + def n_unique(self) -> int: ... - def zip_with(self, mask: Self, other: Self) -> Self: - ... + def zip_with(self, mask: Self, other: Self) -> Self: ... - def sample(self, n: int, fraction: float, *, with_replacement: bool) -> Series: - ... + def sample(self, n: int, fraction: float, *, with_replacement: bool) -> Series: ... - def to_numpy(self) -> Any: - ... + def to_numpy(self) -> Any: ... - def to_pandas(self) -> Any: - ... + def to_pandas(self) -> Any: ... class DataFrame(Protocol): - def __getitem__(self, column_name: str) -> Series: - ... + def __getitem__(self, column_name: str) -> Series: ... # --- properties --- @property - def columns(self) -> list[str]: - ... + def columns(self) -> list[str]: ... @property - def schema(self) -> dict[str, DType]: - ... + def schema(self) -> dict[str, DType]: ... @property - def shape(self) -> tuple[int, int]: - ... + def shape(self) -> tuple[int, int]: ... - def iter_columns(self) -> Iterable[Series]: - ... + def iter_columns(self) -> Iterable[Series]: ... # --- reshape --- def with_columns( self, *exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr - ) -> Self: - ... + ) -> Self: ... - def filter(self, *predicates: IntoExpr | Iterable[IntoExpr]) -> Self: - ... + def filter(self, *predicates: IntoExpr | Iterable[IntoExpr]) -> Self: ... def select( self, *exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr - ) -> Self: - ... + ) -> Self: ... - def rename(self, mapping: dict[str, str]) -> Self: - ... + def rename(self, mapping: dict[str, str]) -> Self: ... # --- transform --- def sort( @@ -256,27 +196,20 @@ def sort( by: str | Iterable[str], *more_by: str, descending: bool | Sequence[bool] = False, - ) -> Self: - ... + ) -> Self: ... # --- convert --- - def lazy(self) -> Self: - ... + def lazy(self) -> Self: ... - def collect(self) -> Self: - ... + def collect(self) -> Self: ... - def cache(self) -> Self: - ... + def cache(self) -> Self: ... - def to_numpy(self) -> Any: - ... + def to_numpy(self) -> Any: ... - def to_pandas(self) -> Any: - ... + def to_pandas(self) -> Any: ... - def to_dict(self, *, as_series: bool = True) -> dict[str, Any]: - ... + def to_dict(self, *, as_series: bool = True) -> dict[str, Any]: ... # --- actions --- def join( @@ -286,33 +219,26 @@ def join( how: Literal["inner"] = "inner", left_on: str | list[str], right_on: str | list[str], - ) -> Self: - ... + ) -> Self: ... - def group_by(self, *keys: str | Iterable[str]) -> GroupBy: - ... + def group_by(self, *keys: str | Iterable[str]) -> GroupBy: ... # --- partial reduction --- - def head(self, n: int) -> Self: - ... + def head(self, n: int) -> Self: ... - def unique(self, subset: list[str]) -> Self: - ... + def unique(self, subset: list[str]) -> Self: ... @property - def is_eager(self) -> bool: - ... + def is_eager(self) -> bool: ... @property - def is_lazy(self) -> bool: - ... + def is_lazy(self) -> bool: ... class GroupBy(Protocol): def agg( self, *aggs: IntoExpr | Iterable[IntoExpr], **named_aggs: IntoExpr - ) -> DataFrame: - ... + ) -> DataFrame: ... IntoExpr = Expr | str | int | float | Series