Skip to content

Commit 35ec9fe

Browse files
authored
fix: Fix CI for PySpark 4.0 (#2601)
1 parent f54dc25 commit 35ec9fe

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

narwhals/_spark_like/namespace.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,21 @@ def func(df: SparkLikeLazyFrame) -> list[Column]:
131131
def mean_horizontal(self, *exprs: SparkLikeExpr) -> SparkLikeExpr:
132132
def func(df: SparkLikeLazyFrame) -> list[Column]:
133133
cols = [c for _expr in exprs for c in _expr(df)]
134+
F = exprs[0]._F # noqa: N806
135+
# PySpark before 3.5 doesn't have `try_divide`, SQLFrame doesn't have it.
136+
divide = getattr(F, "try_divide", operator.truediv)
134137
return [
135-
(
138+
divide(
136139
reduce(
137140
operator.add, (df._F.coalesce(col, df._F.lit(0)) for col in cols)
138-
)
139-
/ reduce(
141+
),
142+
reduce(
140143
operator.add,
141144
(
142145
col.isNotNull().cast(df._native_dtypes.IntegerType())
143146
for col in cols
144147
),
145-
)
148+
),
146149
)
147150
]
148151

0 commit comments

Comments
 (0)