-
Notifications
You must be signed in to change notification settings - Fork 170
fix(typing): Overhaul @overloads in nw.from_native
#3125
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
d5a126d
39bb6b3
c7cf5ae
6f56dc0
d72ce2d
94029ed
0358cc9
43ceb3f
ceaf9e7
d988a24
cc5588b
1cab6d0
ff6258d
a0095b1
06d74a3
c02ab37
5b6ca5f
4142e43
2e7a0ae
435beb4
0605936
67bb52f
fd7ab16
9a8c025
c61af03
252bcdb
c887618
99527d5
1dc56f0
10e7ddf
1c498aa
4e37df6
f372696
459598f
58590e4
bd90c1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,13 +35,19 @@ def columns(self) -> Any: ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def join(self, *args: Any, **kwargs: Any) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class NativeDataFrame(Sized, NativeFrame, Protocol): ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class NativeDataFrame(Sized, NativeFrame, Protocol): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def drop(self, *args: Any, **kwargs: Any) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class NativeLazyFrame(NativeFrame, Protocol): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def explain(self, *args: Any, **kwargs: Any) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Needs to have something `NativeDataFrame` doesn't? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class NativeSeries(Sized, Iterable[Any], Protocol): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def filter(self, *args: Any, **kwargs: Any) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # `pd.DataFrame` has this - the others don't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def value_counts(self, *args: Any, **kwargs: Any) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # `pl.DataFrame` has this - the others don't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def unique(self, *args: Any, **kwargs: Any) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_from_native_series_exhaustive() -> None: # noqa: PLR0914, PLR0915 | |
| pytest.importorskip("polars") | |
| pytest.importorskip("pandas") | |
| pytest.importorskip("pyarrow") | |
| pytest.importorskip("typing_extensions") | |
| import pandas as pd | |
| import polars as pl | |
| import pyarrow as pa | |
| from typing_extensions import assert_type | |
| pl_ser = pl.Series([1, 2, 3]) | |
| pd_ser = cast("pd.Series[Any]", pd.Series([1, 2, 3])) | |
| pa_ser = cast("pa.ChunkedArray[Any]", pa.chunked_array([pa.array([1])])) # type: ignore[redundant-cast] | |
| pl_1 = nw.from_native(pl_ser, series_only=True) | |
| pl_2 = nw.from_native(pl_ser, allow_series=True) | |
| pl_3 = nw.from_native(pl_ser, eager_only=True, series_only=True) | |
| pl_4 = nw.from_native(pl_ser, eager_only=True, series_only=True, allow_series=True) | |
| pl_5 = nw.from_native(pl_ser, eager_only=True, allow_series=True) | |
| pl_6 = nw.from_native(pl_ser, series_only=True, allow_series=True) | |
| pl_7 = nw.from_native(pl_ser, series_only=True, pass_through=True) | |
| pl_8 = nw.from_native(pl_ser, allow_series=True, pass_through=True) | |
| pl_9 = nw.from_native(pl_ser, eager_only=True, series_only=True, pass_through=True) | |
| pl_10 = nw.from_native( | |
| pl_ser, eager_only=True, series_only=True, allow_series=True, pass_through=True | |
| ) | |
| pl_11 = nw.from_native(pl_ser, eager_only=True, allow_series=True, pass_through=True) | |
| pl_12 = nw.from_native(pl_ser, series_only=True, allow_series=True, pass_through=True) | |
| pls = pl_1, pl_2, pl_3, pl_4, pl_5, pl_6, pl_7, pl_8, pl_9, pl_10, pl_11, pl_12 | |
| assert_type(pl_1, nw.Series[pl.Series]) | |
| assert_type(pl_2, nw.Series[pl.Series]) | |
| assert_type(pl_3, nw.Series[pl.Series]) | |
| assert_type(pl_4, nw.Series[pl.Series]) | |
| assert_type(pl_5, nw.Series[pl.Series]) | |
| assert_type(pl_6, nw.Series[pl.Series]) | |
| assert_type(pl_7, nw.Series[pl.Series]) | |
| assert_type(pl_8, nw.Series[pl.Series]) | |
| assert_type(pl_9, nw.Series[pl.Series]) | |
| assert_type(pl_10, nw.Series[pl.Series]) | |
| assert_type(pl_11, nw.Series[pl.Series]) | |
| assert_type(pl_12, nw.Series[pl.Series]) | |
| pd_1 = nw.from_native(pd_ser, series_only=True) | |
| pd_2 = nw.from_native(pd_ser, allow_series=True) | |
| pd_3 = nw.from_native(pd_ser, eager_only=True, series_only=True) | |
| pd_4 = nw.from_native(pd_ser, eager_only=True, series_only=True, allow_series=True) | |
| pd_5 = nw.from_native(pd_ser, eager_only=True, allow_series=True) | |
| pd_6 = nw.from_native(pd_ser, series_only=True, allow_series=True) | |
| pd_7 = nw.from_native(pd_ser, series_only=True, pass_through=True) | |
| pd_8 = nw.from_native(pd_ser, allow_series=True, pass_through=True) | |
| pd_9 = nw.from_native(pd_ser, eager_only=True, series_only=True, pass_through=True) | |
| pd_10 = nw.from_native( | |
| pd_ser, eager_only=True, series_only=True, allow_series=True, pass_through=True | |
| ) | |
| pd_11 = nw.from_native(pd_ser, eager_only=True, allow_series=True, pass_through=True) | |
| pd_12 = nw.from_native(pd_ser, series_only=True, allow_series=True, pass_through=True) | |
| pds = pd_1, pd_2, pd_3, pd_4, pd_5, pd_6, pd_7, pd_8, pd_9, pd_10, pd_11, pd_12 | |
| assert_type(pd_1, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_2, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_3, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_4, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_5, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_6, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_7, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_8, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_9, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_10, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_11, nw.Series["pd.Series[Any]"]) | |
| assert_type(pd_12, nw.Series["pd.Series[Any]"]) | |
| pa_1 = nw.from_native(pa_ser, series_only=True) | |
| pa_2 = nw.from_native(pa_ser, allow_series=True) | |
| pa_3 = nw.from_native(pa_ser, eager_only=True, series_only=True) | |
| pa_4 = nw.from_native(pa_ser, eager_only=True, series_only=True, allow_series=True) | |
| pa_5 = nw.from_native(pa_ser, eager_only=True, allow_series=True) | |
| pa_6 = nw.from_native(pa_ser, series_only=True, allow_series=True) | |
| pa_7 = nw.from_native(pa_ser, series_only=True, pass_through=True) | |
| pa_8 = nw.from_native(pa_ser, allow_series=True, pass_through=True) | |
| pa_9 = nw.from_native(pa_ser, eager_only=True, series_only=True, pass_through=True) | |
| pa_10 = nw.from_native( | |
| pa_ser, eager_only=True, series_only=True, allow_series=True, pass_through=True | |
| ) | |
| pa_11 = nw.from_native(pa_ser, eager_only=True, allow_series=True, pass_through=True) | |
| pa_12 = nw.from_native(pa_ser, series_only=True, allow_series=True, pass_through=True) | |
| pas = pa_1, pa_2, pa_3, pa_4, pa_5, pa_6, pa_7, pa_8, pa_9, pa_10, pa_11, pa_12 | |
| assert_type(pa_1, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_2, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_3, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_4, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_5, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_6, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_7, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_8, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_9, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_10, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_11, nw.Series["pa.ChunkedArray[Any]"]) | |
| assert_type(pa_12, nw.Series["pa.ChunkedArray[Any]"]) | |
| for series in chain(pls, pds, pas): | |
| assert isinstance(series, nw.Series) |
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.
Issue 2
There's too many combinations we need to account for in
@overloads.native_objects...allow_series: bool | Nonejust adds to itSo instead of that:
TypedDictUnpackandRequiredto merge a whole bunch of them