Skip to content

Commit 3bd7775

Browse files
committed
chore(typing): Follup-up fix _from_array_like
Have a better understanding *now* of what the issue is in (https://github.com/narwhals-dev/narwhals/actions/runs/13577097131/job/37955718895). - This patch is *functionally* the same - but removes the need for ignoring a (typing) warning following (narwhals-dev/narwhals@62f8a1f). - Should also mean we don't need to bump our `narwhals` minimum [again](#3807 (comment)). - **Bonus**: reduced overhead for `<3.11` (python/cpython#84403) ## Related - narwhals-dev/narwhals#2110 - #3811 - narwhals-dev/narwhals#2110 (comment) - narwhals-dev/narwhals#2110 (comment) - narwhals-dev/narwhals#2111
1 parent c0956c5 commit 3bd7775

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

altair/utils/schemapi.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
cast,
2828
overload,
2929
)
30-
from typing_extensions import TypeAlias
3130

3231
import jsonschema
3332
import jsonschema.exceptions
3433
import jsonschema.validators
3534
import narwhals.stable.v1 as nw
35+
from narwhals.stable.v1.dependencies import is_narwhals_series
3636
from packaging.version import Version
3737

3838
if sys.version_info >= (3, 12):
@@ -58,6 +58,11 @@
5858
from typing import Never, Self
5959
else:
6060
from typing_extensions import Never, Self
61+
if sys.version_info >= (3, 10):
62+
from typing import TypeAlias
63+
else:
64+
from typing_extensions import TypeAlias
65+
6166
_OptionalModule: TypeAlias = "ModuleType | None"
6267

6368
ValidationErrorList: TypeAlias = list[jsonschema.exceptions.ValidationError]
@@ -493,11 +498,10 @@ def _subclasses(cls: type[Any]) -> Iterator[type[Any]]:
493498

494499

495500
def _from_array_like(obj: Iterable[Any], /) -> list[Any]:
496-
try:
497-
ser = nw.from_native(obj, series_only=True)
498-
return ser.to_list()
499-
except TypeError:
500-
return list(obj)
501+
# TODO @dangotbanned: Review after available (https://github.com/narwhals-dev/narwhals/pull/2110)
502+
# See for what this silences for `narwhals` CI (https://github.com/narwhals-dev/narwhals/pull/2110#issuecomment-2687936504)
503+
maybe_ser: Any = nw.from_native(obj, pass_through=True)
504+
return maybe_ser.to_list() if is_narwhals_series(maybe_ser) else list(obj)
501505

502506

503507
def _from_date_datetime(obj: dt.date | dt.datetime, /) -> dict[str, Any]:

tools/schemapi/schemapi.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
cast,
2626
overload,
2727
)
28-
from typing_extensions import TypeAlias
2928

3029
import jsonschema
3130
import jsonschema.exceptions
3231
import jsonschema.validators
3332
import narwhals.stable.v1 as nw
33+
from narwhals.stable.v1.dependencies import is_narwhals_series
3434
from packaging.version import Version
3535

3636
if sys.version_info >= (3, 12):
@@ -56,6 +56,11 @@
5656
from typing import Never, Self
5757
else:
5858
from typing_extensions import Never, Self
59+
if sys.version_info >= (3, 10):
60+
from typing import TypeAlias
61+
else:
62+
from typing_extensions import TypeAlias
63+
5964
_OptionalModule: TypeAlias = "ModuleType | None"
6065

6166
ValidationErrorList: TypeAlias = list[jsonschema.exceptions.ValidationError]
@@ -491,11 +496,10 @@ def _subclasses(cls: type[Any]) -> Iterator[type[Any]]:
491496

492497

493498
def _from_array_like(obj: Iterable[Any], /) -> list[Any]:
494-
try:
495-
ser = nw.from_native(obj, series_only=True)
496-
return ser.to_list()
497-
except TypeError:
498-
return list(obj)
499+
# TODO @dangotbanned: Review after available (https://github.com/narwhals-dev/narwhals/pull/2110)
500+
# See for what this silences for `narwhals` CI (https://github.com/narwhals-dev/narwhals/pull/2110#issuecomment-2687936504)
501+
maybe_ser: Any = nw.from_native(obj, pass_through=True)
502+
return maybe_ser.to_list() if is_narwhals_series(maybe_ser) else list(obj)
499503

500504

501505
def _from_date_datetime(obj: dt.date | dt.datetime, /) -> dict[str, Any]:

0 commit comments

Comments
 (0)