-
Notifications
You must be signed in to change notification settings - Fork 185
[Doc]: Linting the example from the README gives an error when using ty. #3493
Copy link
Copy link
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationtyping
Description
What type of report is this?
Correction
Please describe the issue.
Recall the example from the README:
import narwhals as nw
from narwhals.typing import IntoFrameT
def agnostic_function(
df_native: IntoFrameT,
date_column: str,
price_column: str,
) -> IntoFrameT:
return (
nw.from_native(df_native)
.group_by(nw.col(date_column).dt.truncate("1mo"))
.agg(nw.col(price_column).mean())
.sort(date_column)
.to_native()
)When I check this with ty via uvx -w narwhals ty check tmp1.py, I get:
uvx -w narwhals ty check tmp1.py
error[unresolved-attribute]: Attribute `group_by` is not defined on `Series[Unknown]` in union `DataFrame[Unknown] | Series[Unknown]`
--> tmp1.py:11:9
|
9 | ) -> IntoFrameT:
10 | return (
11 | / nw.from_native(df_native)
12 | | .group_by(nw.col(date_column).dt.truncate("1mo"))
| |_________________^
13 | .agg(nw.col(price_column).mean())
14 | .sort(date_column)
|
info: rule `unresolved-attribute` is enabled by default
Found 1 diagnostic
Whereas if I rewrite this by replacing IntoFrameT with IntoDataFrameT, all checks pass.
import narwhals as nw
from narwhals.typing import IntoDataFrameT
def agnostic_function(
df_native: IntoDataFrameT,
date_column: str,
price_column: str,
) -> IntoDataFrameT:
return (
nw.from_native(df_native)
.group_by(nw.col(date_column).dt.truncate("1mo"))
.agg(nw.col(price_column).mean())
.sort(date_column)
.to_native()
)No issues here:
uvx -w narwhals ty check tmp2.py
All checks passed!
If you have a suggestion on how it should be, add it below.
I'd expect the example in the README to pass a check from ty. I am not sure if this is as simple as just swapping IntoFrameT with IntoDataFrameT in the README, of if this is deeper, underlying problem.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationtyping