Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/pyspark/pandas/numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@
.otherwise(F.lit(1.0)),
"hypot": F.hypot,
"lcm": pandas_udf(lambda s1, s2: np.lcm(s1, s2), DoubleType()), # type: ignore[call-overload]
"ldexp": lambda c1, c2: c1.cast("double") * F.pow(F.lit(2.0), c2),
"ldexp": lambda c1, c2: F.when(
c1.cast("double").isin(0.0, float("-inf"), float("inf")),
c1.cast("double"),
).otherwise(c1.cast("double") * F.pow(F.lit(2.0), c2)),
# F.shiftleft accepts literal counts only; call_function also accepts a column.
# NumPy returns zero for counts outside an int64's bit width, unlike JVM shifts.
"left_shift": lambda c1, c2: F.when((c2 < 0) | (c2 >= 64), F.lit(0)).otherwise(
Expand Down
29 changes: 27 additions & 2 deletions python/pyspark/pandas/tests/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,38 @@ def test_np_ldexp(self):
1.0,
1.0,
1.0,
0.0,
-0.0,
np.inf,
-np.inf,
],
"exp": [
2,
3,
-2,
-3,
-3,
0,
-2,
2,
2,
2,
-1074,
-1075,
1024,
1024,
1024,
-1075,
-1075,
],
"exp": [2, 3, -2, -3, -3, 0, -2, 2, 2, 2, -1074, -1075, 1024],
}
)
psdf = ps.from_pandas(pdf)

self.assert_eq(np.ldexp(psdf.x, psdf.exp), np.ldexp(pdf.x, pdf.exp), almost=True)
result = np.ldexp(psdf.x, psdf.exp)
expected = np.ldexp(pdf.x, pdf.exp)
self.assert_eq(result, expected, almost=True)
self.assert_eq(np.signbit(result.to_pandas()), np.signbit(expected))

def test_np_fmax_fmin(self):
for pdf in (
Expand Down