-
Notifications
You must be signed in to change notification settings - Fork 170
refactor: adds _compliant sub-package
#2149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
931d7ea
refactor: Add `_compliant` sub-package
dangotbanned cef630e
refactor: migrate imports, delete `_selectors`
dangotbanned ca2ca24
refactor: Export `Eval(Names|Series)`
dangotbanned 9cc3ce8
feat(DRAFT): Add placeholder `(Eager|Lazy)Expr` protocols
dangotbanned 53413ae
ci: ignore coverage
dangotbanned 9efd3c6
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned 2bf05fb
refactor: avoid adding `typing.IntoCompliantExpr`
dangotbanned 7fb4914
refactor: avoid adding `typing.CompliantFrameT`
dangotbanned 51820a1
refactor: avoid adding `typing.CompliantSeriesT_co`
dangotbanned 8f1c5ca
refactor: avoid adding `typing.CompliantNamespace`
dangotbanned 5bf2bdb
refactor: avoid adding `typing.CompliantExpr`
dangotbanned 075228b
fix(typing): Resolve `NativeExpr`-related issues
dangotbanned a0fe52a
refactor(typing): spec out and reuse `LazyExpr`
dangotbanned 23fdf8f
be quiet `mypy`!
dangotbanned d58e2c9
feat(DRAFT): `EagerExpr` from `_expression_parsing.py`
dangotbanned 6cb725c
feat: Generic dunders
dangotbanned bc93782
chore(typing): fix variance issues
dangotbanned 7d48726
feat(DRAFT): add a couple more methods
dangotbanned 75b33c4
feat: Spec-out all generic parts of `EagerExpr`
dangotbanned b38b25b
Merge branch 'main' into compliant-package
dangotbanned 5d766c2
revert: remove unused `_series` property
dangotbanned a066213
feat: add `EagerExpr.from_column_(names|indices)`
dangotbanned 57ab13b
chore: add some notes on `Eager(Namespace|Series)`
dangotbanned e16e942
update import/exports
dangotbanned 364d2ee
fix(typing): Use `Self`
dangotbanned 484c997
refactor(DRAFT): start implementing `Arrow*`
dangotbanned 77b599a
fix: typo and add missing `count`
dangotbanned 7a1a653
refactor(DRAFT): mostly ready `ArrowExpr`
dangotbanned afddd4c
refactor(DRAFT): Possibly all `ArrowExpr`?
dangotbanned f87a629
refactor: migrate to `ArrowExpr._reuse_series_namespace_implementation`
dangotbanned d509fc9
fix: fix typo lol
dangotbanned 2535f35
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned 9d55d2a
chore: remove `ArrowExpr` parts from `_expression_parsing`
dangotbanned f16ece2
ci: get coverage for properties
dangotbanned 388f715
refactor(DRAFT): start migrating `PandasLike*`
dangotbanned 4bc483f
refactor(DRAFT): big progress on `Pandas*`
dangotbanned 9d7fc16
refactor: migrate expr namespaces
dangotbanned bf18326
fix: dont `__bool__` a `pd.Series`
dangotbanned 73656f1
fix(DRAFT): extend `is_eager_namespace`
dangotbanned c606ea0
refactor: drop all unused `_expression_parsing`
dangotbanned 6ce86c3
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned 00a3442
refactor: remove `implementation` from method names
dangotbanned 7cd3e2d
refactor: rename `attr` -> `method_name`, add annotation
dangotbanned 035976b
feat: Define `CompliantSeries._to_expr`
dangotbanned 874bf6d
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned ba14a82
refactor: get coverage and simplify `_polars.namespace`
dangotbanned e64626a
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned 612df69
refactor: avoid reimplementing `ArrowSeries._from_iterable`
dangotbanned 5a13b63
feat: Super reusable namespaces π€―
dangotbanned c662d85
maybe `3.8` compat?
dangotbanned d53ce01
chore(typing): add some safety for `.name`
dangotbanned 2777822
feat: adds `EagerExprNameNamespace`
dangotbanned b05f132
Merge branch 'main' into compliant-package
dangotbanned 067252b
refactor: Simplify `EagerExprNameNamespace`
dangotbanned 0d57240
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned 309f910
chore: resolve more conflicts from (#2168)
dangotbanned 3a434c2
Merge branch 'main' into compliant-package
dangotbanned 8ec9cd9
docs: add module-level doc
dangotbanned c368a60
docs(typing): Explain `is_eager_expr`
dangotbanned 7d3addc
docs: `NativeExpr`
dangotbanned 66ecf84
chore: remove outdated comments
dangotbanned d1dd6ce
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned b3bdb3b
fix(typing): `EagerNamespace.all_horizontal`
dangotbanned 0f6f803
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned 40d718f
refactor: Add `EagerExprStructNamespace`
dangotbanned 1338d34
Merge remote-tracking branch 'upstream/main' into compliant-package
dangotbanned c7ba9f9
Merge branch 'main' into compliant-package
dangotbanned 7119ad2
Merge branch 'main' into compliant-package
dangotbanned 42dd2c4
refactor: add `EagerDataFrame._evaluate_into_expr(s)`
dangotbanned 12da35b
chore: remove `expr.py` notes
dangotbanned 79c7c8d
chore: remove `namespace.py` notes
dangotbanned 34dd94a
docs: Use more helpful deprecation message
dangotbanned 617ebc3
Merge branch 'main' into compliant-package
dangotbanned 9b93ef8
Merge branch 'main' into compliant-package
dangotbanned File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from narwhals._compliant.dataframe import CompliantDataFrame | ||
| from narwhals._compliant.dataframe import CompliantLazyFrame | ||
| from narwhals._compliant.expr import CompliantExpr | ||
| from narwhals._compliant.expr import LazyExpr | ||
| from narwhals._compliant.namespace import CompliantNamespace | ||
| from narwhals._compliant.selectors import CompliantSelector | ||
| from narwhals._compliant.selectors import CompliantSelectorNamespace | ||
| from narwhals._compliant.selectors import EagerSelectorNamespace | ||
| from narwhals._compliant.selectors import EvalNames | ||
| from narwhals._compliant.selectors import EvalSeries | ||
| from narwhals._compliant.selectors import LazySelectorNamespace | ||
| from narwhals._compliant.series import CompliantSeries | ||
| from narwhals._compliant.typing import CompliantFrameT | ||
| from narwhals._compliant.typing import CompliantSeriesOrNativeExprT_co | ||
| from narwhals._compliant.typing import CompliantSeriesT_co | ||
| from narwhals._compliant.typing import IntoCompliantExpr | ||
|
|
||
| __all__ = [ | ||
| "CompliantDataFrame", | ||
| "CompliantExpr", | ||
| "CompliantFrameT", | ||
| "CompliantLazyFrame", | ||
| "CompliantNamespace", | ||
| "CompliantSelector", | ||
| "CompliantSelectorNamespace", | ||
| "CompliantSeries", | ||
| "CompliantSeriesOrNativeExprT_co", | ||
| "CompliantSeriesT_co", | ||
| "EagerSelectorNamespace", | ||
| "EvalNames", | ||
| "EvalSeries", | ||
| "IntoCompliantExpr", | ||
| "LazyExpr", | ||
| "LazySelectorNamespace", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Iterator | ||
| from typing import Mapping | ||
| from typing import Protocol | ||
| from typing import Sequence | ||
|
|
||
| from narwhals._compliant.typing import CompliantSeriesT_co | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing_extensions import Self | ||
|
|
||
| from narwhals.dtypes import DType | ||
|
|
||
| __all__ = ["CompliantDataFrame", "CompliantLazyFrame"] | ||
|
|
||
|
|
||
| class CompliantDataFrame(Protocol[CompliantSeriesT_co]): | ||
| def __narwhals_dataframe__(self) -> Self: ... | ||
| def __narwhals_namespace__(self) -> Any: ... | ||
| def simple_select( | ||
| self, *column_names: str | ||
| ) -> Self: ... # `select` where all args are column names. | ||
| def aggregate(self, *exprs: Any) -> Self: # pragma: no cover | ||
| ... # `select` where all args are aggregations or literals | ||
| # (so, no broadcasting is necessary). | ||
|
|
||
| @property | ||
| def columns(self) -> Sequence[str]: ... | ||
| @property | ||
| def schema(self) -> Mapping[str, DType]: ... | ||
| def get_column(self, name: str) -> CompliantSeriesT_co: ... | ||
| def iter_columns(self) -> Iterator[CompliantSeriesT_co]: ... | ||
|
|
||
|
|
||
| class CompliantLazyFrame(Protocol): | ||
| def __narwhals_lazyframe__(self) -> Self: ... | ||
| def __narwhals_namespace__(self) -> Any: ... | ||
| def simple_select( | ||
| self, *column_names: str | ||
| ) -> Self: ... # `select` where all args are column names. | ||
| def aggregate(self, *exprs: Any) -> Self: # pragma: no cover | ||
| ... # `select` where all args are aggregations or literals | ||
| # (so, no broadcasting is necessary). | ||
|
|
||
| @property | ||
| def columns(self) -> Sequence[str]: ... | ||
| @property | ||
| def schema(self) -> Mapping[str, DType]: ... | ||
| def _iter_columns(self) -> Iterator[Any]: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,259 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Callable | ||
| from typing import Literal | ||
| from typing import Protocol | ||
| from typing import Sequence | ||
|
|
||
| from narwhals._compliant.typing import CompliantDataFrameT | ||
| from narwhals._compliant.typing import CompliantFrameT | ||
| from narwhals._compliant.typing import CompliantLazyFrameT | ||
| from narwhals._compliant.typing import CompliantSeriesOrNativeExprT_co | ||
| from narwhals._compliant.typing import CompliantSeriesT_co | ||
| from narwhals._compliant.typing import NativeExprT_co | ||
| from narwhals.utils import deprecated | ||
| from narwhals.utils import not_implemented | ||
| from narwhals.utils import unstable | ||
|
|
||
| if not TYPE_CHECKING: # pragma: no cover | ||
| if sys.version_info >= (3, 9): | ||
| from typing import Protocol as Protocol38 | ||
| else: | ||
| from typing import Generic as Protocol38 | ||
| else: # pragma: no cover | ||
| # TODO @dangotbanned: Remove after dropping `3.8` (#2084) | ||
| # - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386 | ||
| from typing import Protocol as Protocol38 | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Mapping | ||
|
|
||
| from typing_extensions import Self | ||
|
|
||
| from narwhals._compliant.namespace import CompliantNamespace | ||
| from narwhals._compliant.series import CompliantSeries | ||
| from narwhals._expression_parsing import ExprKind | ||
| from narwhals.dtypes import DType | ||
| from narwhals.utils import Implementation | ||
| from narwhals.utils import Version | ||
|
|
||
| __all__ = ["CompliantExpr"] | ||
|
|
||
|
|
||
| # NOTE: Only common methods for lazy expr-like objects | ||
| class NativeExpr(Protocol): | ||
| def between(self, *args: Any, **kwds: Any) -> Any: ... | ||
| def isin(self, *args: Any, **kwds: Any) -> Any: ... | ||
|
|
||
|
|
||
| class CompliantExpr(Protocol38[CompliantFrameT, CompliantSeriesOrNativeExprT_co]): | ||
| _implementation: Implementation | ||
| _backend_version: tuple[int, ...] | ||
| _version: Version | ||
| _evaluate_output_names: Callable[[CompliantFrameT], Sequence[str]] | ||
| _alias_output_names: Callable[[Sequence[str]], Sequence[str]] | None | ||
| _depth: int | ||
| _function_name: str | ||
|
|
||
| def __call__( | ||
| self, df: CompliantFrameT | ||
| ) -> Sequence[CompliantSeriesOrNativeExprT_co]: ... | ||
| def __narwhals_expr__(self) -> None: ... | ||
| def __narwhals_namespace__( | ||
| self, | ||
| ) -> CompliantNamespace[CompliantFrameT, CompliantSeriesOrNativeExprT_co]: ... | ||
| def is_null(self) -> Self: ... | ||
| def abs(self) -> Self: ... | ||
| def all(self) -> Self: ... | ||
| def any(self) -> Self: ... | ||
| def alias(self, name: str) -> Self: ... | ||
| def cast(self, dtype: DType | type[DType]) -> Self: ... | ||
| def count(self) -> Self: ... | ||
| def min(self) -> Self: ... | ||
| def max(self) -> Self: ... | ||
| def arg_min(self) -> Self: ... | ||
| def arg_max(self) -> Self: ... | ||
| def arg_true(self) -> Self: ... | ||
| def mean(self) -> Self: ... | ||
| def sum(self) -> Self: ... | ||
| def median(self) -> Self: ... | ||
| def skew(self) -> Self: ... | ||
| def std(self, *, ddof: int) -> Self: ... | ||
| def var(self, *, ddof: int) -> Self: ... | ||
| def n_unique(self) -> Self: ... | ||
| def null_count(self) -> Self: ... | ||
| def drop_nulls(self) -> Self: ... | ||
| def fill_null( | ||
| self, | ||
| value: Any | None, | ||
| strategy: Literal["forward", "backward"] | None, | ||
| limit: int | None, | ||
| ) -> Self: ... | ||
| def diff(self) -> Self: ... | ||
| def unique(self) -> Self: ... | ||
| def len(self) -> Self: ... | ||
| def round(self, decimals: int) -> Self: ... | ||
| def mode(self) -> Self: ... | ||
| def head(self, n: int) -> Self: ... | ||
| def tail(self, n: int) -> Self: ... | ||
| def shift(self, n: int) -> Self: ... | ||
| def is_finite(self) -> Self: ... | ||
| def is_nan(self) -> Self: ... | ||
| def is_unique(self) -> Self: ... | ||
| def is_first_distinct(self) -> Self: ... | ||
| def is_last_distinct(self) -> Self: ... | ||
| def cum_sum(self, *, reverse: bool) -> Self: ... | ||
| def cum_count(self, *, reverse: bool) -> Self: ... | ||
| def cum_min(self, *, reverse: bool) -> Self: ... | ||
| def cum_max(self, *, reverse: bool) -> Self: ... | ||
| def cum_prod(self, *, reverse: bool) -> Self: ... | ||
| def is_in(self, other: Any) -> Self: ... | ||
| def sort(self, *, descending: bool, nulls_last: bool) -> Self: ... | ||
| def rank( | ||
| self, | ||
| method: Literal["average", "min", "max", "dense", "ordinal"], | ||
| *, | ||
| descending: bool, | ||
| ) -> Self: ... | ||
| def replace_strict( | ||
| self, | ||
| old: Sequence[Any] | Mapping[Any, Any], | ||
| new: Sequence[Any], | ||
| *, | ||
| return_dtype: DType | type[DType] | None, | ||
| ) -> Self: ... | ||
| def over(self: Self, keys: Sequence[str], kind: ExprKind) -> Self: ... | ||
| def sample( | ||
| self, | ||
| n: int | None, | ||
| *, | ||
| fraction: float | None, | ||
| with_replacement: bool, | ||
| seed: int | None, | ||
| ) -> Self: ... | ||
| def quantile( | ||
| self, | ||
| quantile: float, | ||
| interpolation: Literal["nearest", "higher", "lower", "midpoint", "linear"], | ||
| ) -> Self: ... | ||
| def map_batches( | ||
| self, | ||
| function: Callable[[CompliantSeries], CompliantExpr[Any, Any]], | ||
| return_dtype: DType | type[DType] | None, | ||
| ) -> Self: ... | ||
|
|
||
| @property | ||
| def str(self) -> Any: ... | ||
| @property | ||
| def name(self) -> Any: ... | ||
| @property | ||
| def dt(self) -> Any: ... | ||
| @property | ||
| def cat(self) -> Any: ... | ||
| @property | ||
| def list(self) -> Any: ... | ||
|
|
||
| @unstable | ||
| def ewm_mean( | ||
| self, | ||
| *, | ||
| com: float | None, | ||
| span: float | None, | ||
| half_life: float | None, | ||
| alpha: float | None, | ||
| adjust: bool, | ||
| min_samples: int, | ||
| ignore_nulls: bool, | ||
| ) -> Self: ... | ||
|
|
||
| @unstable | ||
| def rolling_sum( | ||
| self, | ||
| window_size: int, | ||
| *, | ||
| min_samples: int | None, | ||
| center: bool, | ||
| ) -> Self: ... | ||
|
|
||
| @unstable | ||
| def rolling_mean( | ||
| self, | ||
| window_size: int, | ||
| *, | ||
| min_samples: int | None, | ||
| center: bool, | ||
| ) -> Self: ... | ||
|
|
||
| @unstable | ||
| def rolling_var( | ||
| self, | ||
| window_size: int, | ||
| *, | ||
| min_samples: int | None, | ||
| center: bool, | ||
| ddof: int, | ||
| ) -> Self: ... | ||
|
|
||
| @unstable | ||
| def rolling_std( | ||
| self, | ||
| window_size: int, | ||
| *, | ||
| min_samples: int | None, | ||
| center: bool, | ||
| ddof: int, | ||
| ) -> Self: ... | ||
|
|
||
| @deprecated("Since `1.22.0`") | ||
| def gather_every(self, n: int, offset: int) -> Self: ... | ||
| def __and__(self, other: Any) -> Self: ... | ||
| def __or__(self, other: Any) -> Self: ... | ||
| def __add__(self, other: Any) -> Self: ... | ||
| def __sub__(self, other: Any) -> Self: ... | ||
| def __mul__(self, other: Any) -> Self: ... | ||
| def __floordiv__(self, other: Any) -> Self: ... | ||
| def __truediv__(self, other: Any) -> Self: ... | ||
| def __mod__(self, other: Any) -> Self: ... | ||
| def __pow__(self, other: Any) -> Self: ... | ||
| def __gt__(self, other: Any) -> Self: ... | ||
| def __ge__(self, other: Any) -> Self: ... | ||
| def __lt__(self, other: Any) -> Self: ... | ||
| def __le__(self, other: Any) -> Self: ... | ||
| def __invert__(self) -> Self: ... | ||
| def broadcast( | ||
| self, kind: Literal[ExprKind.AGGREGATION, ExprKind.LITERAL] | ||
| ) -> Self: ... | ||
|
|
||
|
|
||
| class EagerExpr( | ||
| CompliantExpr[CompliantDataFrameT, CompliantSeriesT_co], | ||
| Protocol38[CompliantDataFrameT, CompliantSeriesT_co], | ||
| ): ... | ||
|
|
||
|
|
||
| # NOTE: See (https://github.com/narwhals-dev/narwhals/issues/2044#issuecomment-2674262833) | ||
| class LazyExpr( | ||
| CompliantExpr[CompliantLazyFrameT, NativeExprT_co], | ||
| Protocol38[CompliantLazyFrameT, NativeExprT_co], | ||
| ): | ||
| arg_min: not_implemented = not_implemented() | ||
| arg_max: not_implemented = not_implemented() | ||
| arg_true: not_implemented = not_implemented() | ||
| head: not_implemented = not_implemented() | ||
| tail: not_implemented = not_implemented() | ||
| mode: not_implemented = not_implemented() | ||
| sort: not_implemented = not_implemented() | ||
| rank: not_implemented = not_implemented() | ||
| sample: not_implemented = not_implemented() | ||
| map_batches: not_implemented = not_implemented() | ||
| ewm_mean: not_implemented = not_implemented() | ||
| rolling_sum: not_implemented = not_implemented() | ||
| rolling_mean: not_implemented = not_implemented() | ||
| rolling_var: not_implemented = not_implemented() | ||
| rolling_std: not_implemented = not_implemented() | ||
| gather_every: not_implemented = not_implemented() | ||
| replace_strict: not_implemented = not_implemented() | ||
| cat: not_implemented = not_implemented() # pyright: ignore[reportAssignmentType] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.