Commit 01dead4
authored
SNOW-2435161: Replace importlib guard by sys.modules check in session initialization (#3907)
importlib.util.find_spec checks if a module can be imported in the current environment, while sys.modules checks whether a module was already imported. This check guards a session flag; if modin was already imported, then we need to import modin.config and set the value of the relevant configuration variable. The previous check would improperly import modin if it was present in the environment even if the user did not intend to do so; this triggered a bug in narwhals where the library checked whether "modin" in sys.modules was true instead of "modin.pandas" in sys.modules (code), causing an ImportError even if the user did not intend to use modin at all.
Relaxing our check to use sys.modules instead avoids unnecessarily polluting the namespace, avoiding this crash.
The narwhals bug that triggered this error was fixed in their codebase as well: narwhals-dev/narwhals#32191 parent dd49115 commit 01dead4
2 files changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
758 | | - | |
| 758 | + | |
759 | 759 | | |
760 | 760 | | |
761 | 761 | | |
| |||
0 commit comments