-
Notifications
You must be signed in to change notification settings - Fork 170
feat: introduce (experimental) plugin system #2978
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
Changes from 24 commits
6d36b4e
1062d99
8d4cda6
cfd156f
e3a2f3b
f65d7bf
a133796
eee9068
c3a8c4d
ca01346
c4611fe
90ad973
76232df
ebc1a8f
15d9c8c
16832f9
9e11a8f
d8663d8
34e7fb6
8a2b019
f92cdbf
54509d2
941edc4
72a5df4
e783af7
4cf2f96
a52a6bb
a4e539a
aca8cc4
02d544a
0952cd9
de0e5ce
9dfcd09
b999e9a
3460f4e
1c246dc
ab8303d
a8501f5
19dc900
42f2df8
d6a384a
9cf290d
bdd71e7
bde288f
7035533
4868aab
afd8620
b09d3ad
1a73ab8
1481d48
59589c1
6888f78
8f22fdb
b3f2b60
422ec70
b0b524b
0960d69
3207de1
d951220
ea28de2
b563ace
9847793
1f38e31
5dee0bb
c508ab0
f2d6e57
6c65fd4
b26d7d4
22362ad
d22f046
028e473
87e67bf
5c16c7f
e00c7c6
0c69762
f7765e8
e3e5ec7
0cd5f2f
d511fc0
6dd4d1c
8a96d84
1944e47
ce712e0
7bcec61
9bbc0a6
0f65066
8ad25ea
21aab4a
0138803
fa09ba6
213cc31
da2d115
3a10b68
2d3f034
547db41
afd4d83
910a31e
f227c13
3ef415d
793a1cd
c0d9d00
725ce3c
bd95e6d
150dc52
dc82860
41a64c0
242d8dd
62ea8c9
29d7b8e
1b877d4
f7e5ae9
ee37848
28ca7fd
19d08e1
840c65f
4550ed3
79ce894
a49e214
b980628
0cdb198
4a3f43b
3f06f3a
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import datetime as dt | ||
| import sys | ||
| from decimal import Decimal | ||
| from functools import wraps | ||
| from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, overload | ||
|
|
@@ -532,6 +533,27 @@ def _from_native_impl( # noqa: C901, PLR0911, PLR0912, PLR0915 | |
| raise TypeError(msg) | ||
| return Version.V1.dataframe(InterchangeFrame(native_object), level="interchange") | ||
|
|
||
| from importlib.metadata import entry_points | ||
|
|
||
| discovered_plugins = entry_points(group="narwhals.plugins") | ||
|
|
||
| if sys.version_info >= (3, 10): | ||
| for plugin in discovered_plugins: | ||
| obj = plugin.load() # pragma: no cover | ||
|
|
||
| try: | ||
| df_compliant = obj.from_native( # pragma: no cover | ||
| native_object, eager_only=False, series_only=False | ||
| ) | ||
| except Exception as e: | ||
| if "daft" in str(type(native_object)): # pragma: no cover | ||
| msg = "Hint: you might be missing the `narwhals-daft` plugin" | ||
| raise Exception(msg) from e # noqa: TRY002 | ||
| # continue looping over the plugins | ||
| continue # pragma: no cover | ||
|
||
| else: | ||
| return df_compliant.to_narwhals() # pragma: no cover | ||
|
|
||
| if not pass_through: | ||
| msg = f"Expected pandas-like dataframe, Polars dataframe, or Polars lazyframe, got: {type(native_object)}" | ||
| raise TypeError(msg) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I've sprinkled # pragma: no cover rather liberally, hoped this would prevent the tests from running.
Plus I thought the if statement (if sys.version_info >= (3, 10):) would prevent lower versions from testing for the plugin - do the test failures indicate this still runs? I.e. the references to 3.9, have I got that right?
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.
no coverprevents the lines from being reported in the coverage report, but the tests still get executedthe problematic part for python 3.9 is
entry_points(group="narwhals.plugins")so you'll need to put that inside theif sys.version_infoblock