Skip to content

Commit

Permalink
fix: fix refactor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhanunjaya-Elluri committed Jan 5, 2025
1 parent 137b1be commit 49eeb94
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions narwhals/_spark_like/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from narwhals._spark_like.utils import maybe_evaluate
from narwhals.typing import CompliantExpr
from narwhals.utils import Implementation
from narwhals.utils import get_module_version_as_tuple
from narwhals.utils import parse_version

if TYPE_CHECKING:
Expand All @@ -21,8 +20,6 @@
from narwhals._spark_like.namespace import SparkLikeNamespace
from narwhals.utils import Version

PYSPARK_VERSION: tuple[int, ...] = get_module_version_as_tuple("pyspark")


class SparkLikeExpr(CompliantExpr["Column"]):
_implementation = Implementation.PYSPARK
Expand Down Expand Up @@ -226,9 +223,10 @@ def mean(self) -> Self:

def median(self) -> Self:
def _median(_input: Column) -> Column:
import pyspark # ignore-banned-import
from pyspark.sql import functions as F # noqa: N812

if PYSPARK_VERSION < (3, 4):
if parse_version(pyspark.__version__) < (3, 4):
# Use percentile_approx with default accuracy parameter (10000)
return F.percentile_approx(_input.cast("double"), 0.5)

Expand Down
7 changes: 0 additions & 7 deletions narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,3 @@ def generate_repr(header: str, native_repr: str) -> str:
"| Use `.to_native` to see native output |\n└"
f"{'─' * 39}┘"
)


def get_module_version_as_tuple(module_name: str) -> tuple[int, ...]:
try:
return parse_version(__import__(module_name).__version__)
except ImportError:
return (0, 0, 0)
9 changes: 8 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@
from narwhals.typing import IntoDataFrame
from narwhals.typing import IntoFrame
from narwhals.utils import Implementation
from narwhals.utils import get_module_version_as_tuple
from narwhals.utils import parse_version

if sys.version_info >= (3, 10):
from typing import TypeAlias # pragma: no cover
else:
from typing_extensions import TypeAlias # pragma: no cover


def get_module_version_as_tuple(module_name: str) -> tuple[int, ...]:
try:
return parse_version(__import__(module_name).__version__)
except ImportError:
return (0, 0, 0)


IBIS_VERSION: tuple[int, ...] = get_module_version_as_tuple("ibis")
NUMPY_VERSION: tuple[int, ...] = get_module_version_as_tuple("numpy")
PANDAS_VERSION: tuple[int, ...] = get_module_version_as_tuple("pandas")
Expand Down
2 changes: 1 addition & 1 deletion tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from pandas.testing import assert_series_equal

import narwhals.stable.v1 as nw
from narwhals.utils import get_module_version_as_tuple
from tests.utils import PANDAS_VERSION
from tests.utils import get_module_version_as_tuple

if TYPE_CHECKING:
from narwhals.series import Series
Expand Down

0 comments on commit 49eeb94

Please sign in to comment.