|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import warnings |
4 | | -from importlib import import_module |
5 | 4 | from typing import TYPE_CHECKING |
6 | 5 | from typing import Any |
7 | 6 | from typing import Iterator |
8 | 7 | from typing import Literal |
9 | 8 | from typing import Sequence |
10 | 9 |
|
11 | 10 | from narwhals._spark_like.utils import evaluate_exprs |
| 11 | +from narwhals._spark_like.utils import import_functions |
| 12 | +from narwhals._spark_like.utils import import_native_dtypes |
| 13 | +from narwhals._spark_like.utils import import_window |
12 | 14 | from narwhals._spark_like.utils import native_to_narwhals_dtype |
13 | 15 | from narwhals.exceptions import InvalidOperationError |
14 | 16 | from narwhals.typing import CompliantDataFrame |
@@ -70,51 +72,30 @@ def _F(self: Self): # type: ignore[no-untyped-def] # noqa: ANN202, N802 |
70 | 72 |
|
71 | 73 | return functions |
72 | 74 | else: |
73 | | - if self._implementation is Implementation.SQLFRAME: |
74 | | - from sqlframe.base.session import _BaseSession |
75 | | - |
76 | | - return import_module( |
77 | | - f"sqlframe.{_BaseSession().execution_dialect_name}.functions" |
78 | | - ) |
79 | | - |
80 | | - from pyspark.sql import functions |
81 | | - |
82 | | - return functions |
| 75 | + return import_functions(self._implementation) |
83 | 76 |
|
84 | 77 | @property |
85 | 78 | def _native_dtypes(self: Self): # type: ignore[no-untyped-def] # noqa: ANN202 |
86 | 79 | if TYPE_CHECKING: |
87 | 80 | from sqlframe.base import types |
88 | 81 |
|
89 | 82 | return types |
90 | | - |
91 | | - if self._implementation is Implementation.SQLFRAME: |
92 | | - from sqlframe.base.session import _BaseSession |
93 | | - |
94 | | - return import_module( |
95 | | - f"sqlframe.{_BaseSession().execution_dialect_name}.types" |
96 | | - ) |
97 | | - |
98 | | - from pyspark.sql import types # type: ignore[no-redef] |
99 | | - |
100 | | - return types |
| 83 | + else: |
| 84 | + return import_native_dtypes(self._implementation) |
101 | 85 |
|
102 | 86 | @property |
103 | 87 | def _Window(self: Self) -> type[Window]: # noqa: N802 |
104 | | - if self._implementation is Implementation.SQLFRAME: |
105 | | - from sqlframe.base.session import _BaseSession |
106 | | - |
107 | | - _window = import_module( |
108 | | - f"sqlframe.{_BaseSession().execution_dialect_name}.window" |
109 | | - ) |
110 | | - return _window.Window |
111 | | - |
112 | | - from pyspark.sql import Window |
| 88 | + if TYPE_CHECKING: |
| 89 | + from sqlframe.base.window import Window |
113 | 90 |
|
114 | | - return Window |
| 91 | + return Window |
| 92 | + else: |
| 93 | + return import_window(self._implementation) |
115 | 94 |
|
116 | 95 | @property |
117 | 96 | def _session(self: Self) -> SQLFrameSession: |
| 97 | + if TYPE_CHECKING: |
| 98 | + return self._native_frame.session |
118 | 99 | if self._implementation is Implementation.SQLFRAME: |
119 | 100 | return self._native_frame.session |
120 | 101 |
|
|
0 commit comments