-
Notifications
You must be signed in to change notification settings - Fork 179
chore: Make Polars(Expr|Series) compliant
#2328
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
7 commits
Select commit
Hold shift + click to select a range
239777d
chore(typing): Make `PolarsSeries` compliant
dangotbanned 98a2991
fix(typing): Un-confuse `mypy`
dangotbanned 3bfd1ae
chore(typing): Make `PolarsExpr` compliant
dangotbanned 8692555
chore(typing): Comment on outsanding issue
dangotbanned 22acb4f
chore(typing): Update `PolarsNamespace.selectors`
dangotbanned 54fa4ce
chore: Ignore coverage on `PolarsExpr.__narwhals_namespace__`
dangotbanned e082282
Merge branch 'main' into polars-series-compliant
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 |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Iterable | ||
| from typing import Iterator | ||
| from typing import Mapping | ||
| from typing import Sequence | ||
| from typing import cast | ||
| from typing import overload | ||
|
|
@@ -22,8 +24,11 @@ | |
| from types import ModuleType | ||
| from typing import TypeVar | ||
|
|
||
| import pandas as pd | ||
| from typing_extensions import Self | ||
|
|
||
| from narwhals._arrow.typing import ArrowArray | ||
| from narwhals._polars.dataframe import Method | ||
| from narwhals._polars.dataframe import PolarsDataFrame | ||
| from narwhals._polars.expr import PolarsExpr | ||
| from narwhals._polars.namespace import PolarsNamespace | ||
|
|
@@ -177,12 +182,16 @@ def __getitem__( | |
| ) -> Any | Self: | ||
| return self._from_native_object(self.native.__getitem__(item)) | ||
|
|
||
| def cast(self: Self, dtype: DType) -> Self: | ||
| def cast(self: Self, dtype: DType | type[DType]) -> Self: | ||
| dtype_pl = narwhals_to_native_dtype(dtype, self._version, self._backend_version) | ||
| return self._with_native(self.native.cast(dtype_pl)) | ||
|
|
||
| def replace_strict( | ||
| self: Self, old: Sequence[Any], new: Sequence[Any], *, return_dtype: DType | None | ||
| self: Self, | ||
| old: Sequence[Any] | Mapping[Any, Any], | ||
| new: Sequence[Any], | ||
| *, | ||
| return_dtype: DType | type[DType] | None, | ||
| ) -> Self: | ||
| ser = self.native | ||
| dtype = ( | ||
|
|
@@ -586,14 +595,74 @@ def str(self: Self) -> PolarsSeriesStringNamespace: | |
| def cat(self: Self) -> PolarsSeriesCatNamespace: | ||
| return PolarsSeriesCatNamespace(self) | ||
|
|
||
| @property | ||
| def list(self: Self) -> PolarsSeriesListNamespace: | ||
| return PolarsSeriesListNamespace(self) | ||
|
|
||
| @property | ||
| def struct(self: Self) -> PolarsSeriesStructNamespace: | ||
| return PolarsSeriesStructNamespace(self) | ||
|
|
||
| __iter__: Method[Iterator[Any]] | ||
| __floordiv__: Method[Self] | ||
| __mod__: Method[Self] | ||
| __rand__: Method[Self] | ||
| __rfloordiv__: Method[Self] | ||
| __rmod__: Method[Self] | ||
| __ror__: Method[Self] | ||
| __rtruediv__: Method[Self] | ||
| __truediv__: Method[Self] | ||
| abs: Method[Self] | ||
| all: Method[bool] | ||
| any: Method[bool] | ||
| arg_max: Method[int] | ||
| arg_min: Method[int] | ||
| arg_true: Method[Self] | ||
| clip: Method[Self] | ||
| count: Method[int] | ||
| cum_max: Method[Self] | ||
| cum_min: Method[Self] | ||
| cum_prod: Method[Self] | ||
| cum_sum: Method[Self] | ||
| diff: Method[Self] | ||
| drop_nulls: Method[Self] | ||
| fill_null: Method[Self] | ||
| filter: Method[Self] | ||
| gather_every: Method[Self] | ||
| head: Method[Self] | ||
| is_between: Method[Self] | ||
| is_finite: Method[Self] | ||
| is_first_distinct: Method[Self] | ||
| is_in: Method[Self] | ||
| is_last_distinct: Method[Self] | ||
| is_null: Method[Self] | ||
| is_sorted: Method[bool] | ||
| is_unique: Method[Self] | ||
| item: Method[Any] | ||
| len: Method[int] | ||
| max: Method[Any] | ||
| mean: Method[float] | ||
| min: Method[Any] | ||
| mode: Method[Self] | ||
| n_unique: Method[int] | ||
| null_count: Method[int] | ||
| quantile: Method[float] | ||
| rank: Method[Self] | ||
| round: Method[Self] | ||
| sample: Method[Self] | ||
| shift: Method[Self] | ||
| skew: Method[float | None] | ||
| std: Method[float] | ||
| sum: Method[float] | ||
| tail: Method[Self] | ||
| to_arrow: Method[ArrowArray] | ||
| to_frame: Method[PolarsDataFrame] | ||
| to_list: Method[list[Any]] | ||
| to_pandas: Method[pd.Series[Any]] | ||
| unique: Method[Self] | ||
| var: Method[float] | ||
| zip_with: Method[Self] | ||
|
|
||
| @property | ||
| def list(self: Self) -> PolarsSeriesListNamespace: | ||
| return PolarsSeriesListNamespace(self) | ||
|
Comment on lines
+656
to
+664
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. Had to move See these for more info π |
||
|
|
||
|
|
||
| class PolarsSeriesDateTimeNamespace: | ||
| def __init__(self: Self, series: PolarsSeries) -> None: | ||
|
|
||
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.
Weird that the
keys->partition_byrename didn't show up as an issue elsewhere π€