-
Notifications
You must be signed in to change notification settings - Fork 166
chore: Support @requires.backend_version
in namespaces
#3127
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
21 commits
Select commit
Hold shift + click to select a range
8a0b9e0
test: Add failing tests
dangotbanned f80a83c
feat: Everything but the method name working
dangotbanned fbbe1b1
refactor: Remove no-longer-required `_version`
dangotbanned 3009d8e
feat: Add `_accessor` class var
dangotbanned c926ca8
refactor: Do the same thing as pandas_like
dangotbanned ccdd735
feat: prefix method name
dangotbanned 4b79c04
Merge branch 'main' into @requires-on-accessors
dangotbanned 4a87646
refactor: `NamespaceAccessor` typing/protocol changes
dangotbanned 6cc8ed0
refactor: `@requires` runtime changes
dangotbanned 6854043
revert "refactor: `@requires` runtime changes"
dangotbanned cfea56b
revert "refactor: `NamespaceAccessor` typing/protocol changes"
dangotbanned 7b271eb
refactor: try a different way
dangotbanned 456545f
Merge branch 'main' into @requires-on-accessors
dangotbanned 00af1a4
use it for PolarsExpr.str.zfill
FBruzzesi 88e9e9f
change check in is_namespace_accessor
FBruzzesi a52beb2
chore(typing): Narrow what can be passed to `is_namespace_accessor`
dangotbanned 72a6e0f
refactor: Make super private
dangotbanned 32a211b
chore: make the runtime check safer
dangotbanned 02c4984
perf: Move optimization into `_hasattr_static`
dangotbanned 7906b15
docs: Leave a trail for "why so strict dude?"
dangotbanned 75da19e
Merge branch 'main' into @requires-on-accessors
FBruzzesi 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,40 @@ | |
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Protocol | ||
from typing import TYPE_CHECKING, ClassVar, Protocol | ||
|
||
from narwhals._utils import CompliantT_co, _StoresCompliant | ||
|
||
if TYPE_CHECKING: | ||
from typing import Callable | ||
|
||
from narwhals._compliant.typing import Accessor | ||
from narwhals.typing import NonNestedLiteral, TimeUnit | ||
|
||
__all__ = [ | ||
"CatNamespace", | ||
"DateTimeNamespace", | ||
"ListNamespace", | ||
"NameNamespace", | ||
"NamespaceAccessor", | ||
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. Forgot to mention! I chose to invert the naming because we've kinda overloaded the term from narwhals._arrow.namespace import ArrowNamespace
from narwhals._compliant.any_namespace import (
NameNamespace,
# AccessorNamespace,
NamespaceAccessor,
StringNamespace,
StructNamespace,
)
from narwhals._compliant.expr import EagerExprCatNamespace
from narwhals._compliant.namespace import CompliantNamespace
from narwhals._namespace import Namespace |
||
"StringNamespace", | ||
"StructNamespace", | ||
] | ||
|
||
|
||
class CatNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
class NamespaceAccessor(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
_accessor: ClassVar[Accessor] | ||
|
||
|
||
class CatNamespace(NamespaceAccessor[CompliantT_co], Protocol[CompliantT_co]): | ||
_accessor: ClassVar[Accessor] = "cat" | ||
|
||
def get_categories(self) -> CompliantT_co: ... | ||
|
||
|
||
class DateTimeNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
_accessor: ClassVar[Accessor] = "dt" | ||
|
||
def to_string(self, format: str) -> CompliantT_co: ... | ||
def replace_time_zone(self, time_zone: str | None) -> CompliantT_co: ... | ||
def convert_time_zone(self, time_zone: str) -> CompliantT_co: ... | ||
|
@@ -52,15 +62,17 @@ def offset_by(self, by: str) -> CompliantT_co: ... | |
|
||
|
||
class ListNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
def get(self, index: int) -> CompliantT_co: ... | ||
_accessor: ClassVar[Accessor] = "list" | ||
|
||
def get(self, index: int) -> CompliantT_co: ... | ||
def len(self) -> CompliantT_co: ... | ||
|
||
def unique(self) -> CompliantT_co: ... | ||
def contains(self, item: NonNestedLiteral) -> CompliantT_co: ... | ||
|
||
|
||
class NameNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
_accessor: ClassVar[Accessor] = "name" | ||
|
||
def keep(self) -> CompliantT_co: ... | ||
def map(self, function: Callable[[str], str]) -> CompliantT_co: ... | ||
def prefix(self, prefix: str) -> CompliantT_co: ... | ||
|
@@ -70,6 +82,8 @@ def to_uppercase(self) -> CompliantT_co: ... | |
|
||
|
||
class StringNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
_accessor: ClassVar[Accessor] = "str" | ||
|
||
def len_chars(self) -> CompliantT_co: ... | ||
def replace( | ||
self, pattern: str, value: str, *, literal: bool, n: int | ||
|
@@ -91,4 +105,6 @@ def zfill(self, width: int) -> CompliantT_co: ... | |
|
||
|
||
class StructNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): | ||
_accessor: ClassVar[Accessor] = "struct" | ||
|
||
def field(self, name: str) -> CompliantT_co: ... |
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,25 +1,10 @@ | ||
from __future__ import annotations # pragma: no cover | ||
|
||
from typing import ( | ||
TYPE_CHECKING, # pragma: no cover | ||
Union, # pragma: no cover | ||
) | ||
from typing import TYPE_CHECKING # pragma: no cover | ||
|
||
if TYPE_CHECKING: | ||
import sys | ||
from typing import Literal, TypeVar | ||
|
||
if sys.version_info >= (3, 10): | ||
from typing import TypeAlias | ||
else: | ||
from typing_extensions import TypeAlias | ||
from typing import TypeVar | ||
|
||
from narwhals._polars.dataframe import PolarsDataFrame, PolarsLazyFrame | ||
from narwhals._polars.expr import PolarsExpr | ||
from narwhals._polars.series import PolarsSeries | ||
|
||
IntoPolarsExpr: TypeAlias = Union[PolarsExpr, PolarsSeries] | ||
FrameT = TypeVar("FrameT", PolarsDataFrame, PolarsLazyFrame) | ||
NativeAccessor: TypeAlias = Literal[ | ||
"arr", "cat", "dt", "list", "meta", "name", "str", "bin", "struct" | ||
] | ||
dangotbanned marked this conversation as resolved.
Show resolved
Hide resolved
|
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.