-
Notifications
You must be signed in to change notification settings - Fork 170
chore(typing): Fill out CompliantNamespace protocol
#2202
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 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4eb66a0
feat(typing): Fill out `CompliantNamespace` protocol
dangotbanned 8319d0f
refactor(typing): Simplify `EagerNamespace`
dangotbanned c7a9609
Merge remote-tracking branch 'upstream/main' into compliant-namespaceβ¦
dangotbanned 70170da
coverage
dangotbanned dad85d7
Merge branch 'main' into compliant-namespace-spec
dangotbanned 5168ae5
more coverage
dangotbanned 934ba38
Merge branch 'main' into compliant-namespace-spec
dangotbanned 554ef8d
Merge branch 'main' into compliant-namespace-spec
dangotbanned 5d609a7
refactor: Implement `CompliantNamespace.(all|col|exclude|nth)`
dangotbanned 420e4cc
Merge remote-tracking branch 'upstream/main' into compliant-namespaceβ¦
dangotbanned a621fa3
refactor(typing): Simplify `extract_compliant`
dangotbanned 70e15ff
Merge remote-tracking branch 'upstream/main' into compliant-namespaceβ¦
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 |
|---|---|---|
| @@ -1,44 +1,90 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from functools import partial | ||
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Container | ||
| from typing import Iterable | ||
| from typing import Literal | ||
| from typing import Protocol | ||
|
|
||
| from narwhals._compliant.typing import CompliantExprT | ||
| from narwhals._compliant.typing import CompliantFrameT | ||
| from narwhals._compliant.typing import CompliantSeriesOrNativeExprT_co | ||
| from narwhals._compliant.typing import EagerDataFrameT | ||
| from narwhals._compliant.typing import EagerExprT | ||
| from narwhals._compliant.typing import EagerSeriesT_co | ||
| from narwhals.utils import deprecated | ||
| from narwhals.utils import exclude_column_names | ||
| from narwhals.utils import get_column_names | ||
| from narwhals.utils import passthrough_column_names | ||
|
|
||
| if TYPE_CHECKING: | ||
| from narwhals._compliant.expr import CompliantExpr | ||
| from narwhals._compliant.selectors import CompliantSelectorNamespace | ||
| from narwhals.dtypes import DType | ||
| from narwhals.utils import Implementation | ||
| from narwhals.utils import Version | ||
|
|
||
| __all__ = ["CompliantNamespace", "EagerNamespace"] | ||
|
|
||
|
|
||
| class CompliantNamespace(Protocol[CompliantFrameT, CompliantSeriesOrNativeExprT_co]): | ||
| def col( | ||
| self, *column_names: str | ||
| ) -> CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co]: ... | ||
| def lit( | ||
| self, value: Any, dtype: DType | None | ||
| ) -> CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co]: ... | ||
| class CompliantNamespace(Protocol[CompliantFrameT, CompliantExprT]): | ||
| _implementation: Implementation | ||
| _backend_version: tuple[int, ...] | ||
| _version: Version | ||
|
|
||
| def all(self) -> CompliantExprT: | ||
| return self._expr.from_column_names( | ||
| get_column_names, function_name="all", context=self | ||
| ) | ||
|
|
||
| def col(self, *column_names: str) -> CompliantExprT: | ||
| return self._expr.from_column_names( | ||
| passthrough_column_names(column_names), function_name="col", context=self | ||
| ) | ||
|
|
||
| def exclude(self, excluded_names: Container[str]) -> CompliantExprT: | ||
| return self._expr.from_column_names( | ||
| partial(exclude_column_names, names=excluded_names), | ||
| function_name="exclude", | ||
| context=self, | ||
| ) | ||
|
|
||
| def nth(self, *column_indices: int) -> CompliantExprT: | ||
| return self._expr.from_column_indices(*column_indices, context=self) | ||
|
|
||
| def len(self) -> CompliantExprT: ... | ||
| def lit(self, value: Any, dtype: DType | None) -> CompliantExprT: ... | ||
| def all_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... | ||
| def any_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... | ||
| def sum_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... | ||
| def mean_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... | ||
| def min_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... | ||
| def max_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... | ||
| def concat( | ||
| self, | ||
| items: Iterable[CompliantFrameT], | ||
| *, | ||
| how: Literal["horizontal", "vertical", "diagonal"], | ||
| ) -> CompliantFrameT: ... | ||
| def when(self, predicate: CompliantExprT) -> Any: ... | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| def concat_str( | ||
| self, | ||
| *exprs: CompliantExprT, | ||
| separator: str, | ||
| ignore_nulls: bool, | ||
| ) -> CompliantExprT: ... | ||
| @property | ||
| def selectors(self) -> CompliantSelectorNamespace[Any, Any]: ... | ||
| @property | ||
| def _expr(self) -> type[CompliantExprT]: ... | ||
|
|
||
|
|
||
| class EagerNamespace( | ||
| CompliantNamespace[EagerDataFrameT, EagerSeriesT_co], | ||
| CompliantNamespace[EagerDataFrameT, EagerExprT], | ||
| Protocol[EagerDataFrameT, EagerSeriesT_co, EagerExprT], | ||
| ): | ||
| @property | ||
| def _expr(self) -> type[EagerExprT]: ... | ||
| @property | ||
| def _series(self) -> type[EagerSeriesT_co]: ... | ||
| def all_horizontal(self, *exprs: EagerExprT) -> EagerExprT: ... | ||
|
|
||
| @deprecated( | ||
| "Internally used for `numpy.ndarray` -> `CompliantSeries`\n" | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only got flagged after filling out the protocol.