-
Notifications
You must be signed in to change notification settings - Fork 185
chore(typing): Generic CompliantDataFrame
#2115
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f3ada9
feat(typing): Make `CompliantDataFrame` generic
dangotbanned bbc648a
chore(typing): Update eager backends
dangotbanned 8934ade
fix: Make `PolarsSeries` compliant
dangotbanned 66d33ab
fix(typing): Resolve new `mypy` errors
dangotbanned 9162a7e
Merge branch 'main' into typing-compliant-frames-1
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
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
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 |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Callable | ||
| from typing import Generic | ||
| from typing import Literal | ||
| from typing import Protocol | ||
| from typing import Sequence | ||
|
|
@@ -52,7 +51,12 @@ def __narwhals_series__(self) -> CompliantSeries: ... | |
| def alias(self, name: str) -> Self: ... | ||
|
|
||
|
|
||
| class CompliantDataFrame(Protocol): | ||
| CompliantSeriesT_co = TypeVar( | ||
| "CompliantSeriesT_co", bound=CompliantSeries, covariant=True | ||
| ) | ||
|
|
||
|
|
||
| class CompliantDataFrame(Protocol[CompliantSeriesT_co]): | ||
| def __narwhals_dataframe__(self) -> Self: ... | ||
| def __narwhals_namespace__(self) -> Any: ... | ||
| def simple_select( | ||
|
|
@@ -64,6 +68,7 @@ def aggregate(self, *exprs: Any) -> Self: | |
|
|
||
| @property | ||
| def columns(self) -> Sequence[str]: ... | ||
| def get_column(self, name: str) -> CompliantSeriesT_co: ... | ||
|
Comment on lines
69
to
+71
Member
Author
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.
Member
Author
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. @MarcoGorelli I chose The eventual goal will be (#2104 (comment)) |
||
|
|
||
|
|
||
| class CompliantLazyFrame(Protocol): | ||
|
|
@@ -80,30 +85,25 @@ def aggregate(self, *exprs: Any) -> Self: | |
| def columns(self) -> Sequence[str]: ... | ||
|
|
||
|
|
||
| CompliantFrameT_contra = TypeVar( | ||
| "CompliantFrameT_contra", | ||
| bound="CompliantDataFrame | CompliantLazyFrame", | ||
| contravariant=True, | ||
| ) | ||
| CompliantSeriesT_co = TypeVar( | ||
| "CompliantSeriesT_co", bound=CompliantSeries, covariant=True | ||
| CompliantFrameT = TypeVar( | ||
| "CompliantFrameT", bound="CompliantDataFrame[Any] | CompliantLazyFrame" | ||
| ) | ||
|
|
||
|
|
||
| class CompliantExpr(Protocol, Generic[CompliantFrameT_contra, CompliantSeriesT_co]): | ||
| class CompliantExpr(Protocol[CompliantFrameT, CompliantSeriesT_co]): | ||
| _implementation: Implementation | ||
| _backend_version: tuple[int, ...] | ||
| _version: Version | ||
| _evaluate_output_names: Callable[[CompliantFrameT_contra], Sequence[str]] | ||
| _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: Any) -> Sequence[CompliantSeriesT_co]: ... | ||
| def __call__(self, df: CompliantFrameT) -> Sequence[CompliantSeriesT_co]: ... | ||
| def __narwhals_expr__(self) -> None: ... | ||
| def __narwhals_namespace__( | ||
| self, | ||
| ) -> CompliantNamespace[CompliantFrameT_contra, CompliantSeriesT_co]: ... | ||
| ) -> CompliantNamespace[CompliantFrameT, CompliantSeriesT_co]: ... | ||
| def is_null(self) -> Self: ... | ||
| def alias(self, name: str) -> Self: ... | ||
| def cast(self, dtype: DType) -> Self: ... | ||
|
|
@@ -125,21 +125,21 @@ def broadcast( | |
| ) -> Self: ... | ||
|
|
||
|
|
||
| class CompliantNamespace(Protocol, Generic[CompliantFrameT_contra, CompliantSeriesT_co]): | ||
| class CompliantNamespace(Protocol[CompliantFrameT, CompliantSeriesT_co]): | ||
| def col( | ||
| self, *column_names: str | ||
| ) -> CompliantExpr[CompliantFrameT_contra, CompliantSeriesT_co]: ... | ||
| ) -> CompliantExpr[CompliantFrameT, CompliantSeriesT_co]: ... | ||
| def lit( | ||
| self, value: Any, dtype: DType | None | ||
| ) -> CompliantExpr[CompliantFrameT_contra, CompliantSeriesT_co]: ... | ||
| ) -> CompliantExpr[CompliantFrameT, CompliantSeriesT_co]: ... | ||
|
|
||
|
|
||
| class SupportsNativeNamespace(Protocol): | ||
| def __native_namespace__(self) -> ModuleType: ... | ||
|
|
||
|
|
||
| IntoCompliantExpr: TypeAlias = ( | ||
| "CompliantExpr[CompliantFrameT_contra, CompliantSeriesT_co] | CompliantSeriesT_co" | ||
| "CompliantExpr[CompliantFrameT, CompliantSeriesT_co] | CompliantSeriesT_co" | ||
| ) | ||
|
|
||
| IntoExpr: TypeAlias = Union["Expr", str, "Series[Any]"] | ||
|
|
||
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.
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.
why does this need changing?
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.
@MarcoGorelli
pyrightis fine withSelfIIRC - butmypystill needs all the extra inline annotations that we have onmainnarwhals/narwhals/_arrow/dataframe.py
Lines 357 to 374 in dc9fcaa
I had a tough time with that as well in (#2055) - where I've tried moving it into a method:
narwhals/narwhals/_protocols.py
Lines 50 to 87 in 35cef0b
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 was the log from (c11dc95)