chore(typing): fix/ignore utils, tpch warnings#2426
Conversation
`pyright` did a good job spotting that one
Fixes 2/6 errors and shrinks the script
These have been popping up and bugging me for 2 weeks 🙈 #2351 (comment)
These are all the same issue, can be fixed with a constrained `TypeVar`
|
Hmmm, not sure what's going on in ci 🤔 This is working for me locally: from __future__ import annotations
from typing import Any
from typing import Iterator
import narwhals as nw
def _is_public_method_or_property(obj: Any) -> bool:
return (
(inspect.isfunction(obj) or isinstance(obj, property))
and not obj.__name__[0].isupper()
and obj.__name__[0] != "_"
)
def iter_api_reference_names(tp: type[Any]) -> Iterator[str]:
for name, _ in inspect.getmembers(tp, _is_public_method_or_property):
yield name
it = iter_api_reference_names(nw.DataFrame)
>>> list(it)Output
['clone',
'collect_schema',
'columns',
'drop',
'drop_nulls',
'estimated_size',
'explode',
'filter',
'gather_every',
'get_column',
'group_by',
'head',
'implementation',
'is_duplicated',
'is_empty',
'is_unique',
'item',
'iter_columns',
'iter_rows',
'join',
'join_asof',
'lazy',
'null_count',
'pipe',
'pivot',
'rename',
'row',
'rows',
'sample',
'schema',
'select',
'shape',
'sort',
'tail',
'to_arrow',
'to_dict',
'to_native',
'to_numpy',
'to_pandas',
'to_polars',
'unique',
'unpivot',
'with_columns',
'with_row_index',
'write_csv',
'write_parquet']Update 1Ah there's the issue https://github.com/python/typeshed/blob/ae57d69c9354147bcf7086d6db47af8f8c82bf7b/stdlib/builtins.pyi#L1266-L1272 class property:
fget: Callable[[Any], Any] | None
fset: Callable[[Any, Any], None] | None
fdel: Callable[[Any], None] | None
__isabstractmethod__: bool
if sys.version_info >= (3, 13):
__name__: strUpdate 2Fixed in (86dda9b) 🥳 |
Following where `__name__` used to be sourced from - python/cpython#101876
The rest seem pretty unavoidable
MarcoGorelli
left a comment
There was a problem hiding this comment.
thanks - should we also run mypy on these folders in ci if the types are fixed?
| from narwhals import DataFrame | ||
| from narwhals import LazyFrame | ||
|
|
||
| FrameT = TypeVar("FrameT", DataFrame[Any], LazyFrame[Any]) |
There was a problem hiding this comment.
what's the issue with importing FrameT from narwhals._typing?
There was a problem hiding this comment.
@MarcoGorelli it is the same problem from
- (b28da50)
- (feat: Allow expressions as
group_bykeys #2325 (comment)) - (feat: Allow expressions as
group_bykeys #2325 (comment)) - (https://github.com/narwhals-dev/narwhals/actions/runs/14551438598/job/40823080572?pr=2325)
We're seeing it a lot more in the tpch tests since they do multiple transformations on FrameT
Thanks @MarcoGorelli I suppose we could do! Generally, I think it would be a positive step forwards to enable |
|
separately, this makes me wonder if we need to redefine |

What type of PR is this? (check all applicable)
Related issues
overstatements, nested aggregations, filtrations on aggregations, document expression metadata better #2351 (comment)Checklist
If you have comments or can explain your changes, please do so below