Skip to content

Commit 1332d40

Browse files
authored
Revert "patch: allow lit to broadcast as left operand (#854)"
This reverts commit ad7e6fe.
1 parent baa84b8 commit 1332d40

File tree

3 files changed

+6
-28
lines changed

3 files changed

+6
-28
lines changed

narwhals/_arrow/namespace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ def all(self) -> ArrowExpr:
147147
)
148148

149149
def lit(self, value: Any, dtype: dtypes.DType | None) -> ArrowExpr:
150-
def _lit_arrow_series(df: ArrowDataFrame) -> ArrowSeries:
150+
def _lit_arrow_series(_: ArrowDataFrame) -> ArrowSeries:
151151
arrow_series = ArrowSeries._from_iterable(
152-
data=[value] * len(df),
152+
data=[value],
153153
name="lit",
154154
backend_version=self._backend_version,
155155
)

narwhals/_pandas_like/namespace.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from narwhals._pandas_like.utils import create_native_series
1616
from narwhals._pandas_like.utils import horizontal_concat
1717
from narwhals._pandas_like.utils import vertical_concat
18-
from narwhals.utils import Implementation
1918

2019
if TYPE_CHECKING:
2120
from narwhals._pandas_like.typing import IntoPandasLikeExpr
21+
from narwhals.utils import Implementation
2222

2323

2424
class PandasLikeNamespace:
@@ -130,17 +130,11 @@ def all(self) -> PandasLikeExpr:
130130
)
131131

132132
def lit(self, value: Any, dtype: dtypes.DType | None) -> PandasLikeExpr:
133-
if self._implementation is Implementation.CUDF: # pragma: no cover
134-
import cupy as np # ignore-banned-import
135-
else:
136-
import numpy as np # ignore-banned-import
137-
138133
def _lit_pandas_series(df: PandasLikeDataFrame) -> PandasLikeSeries:
139-
native_frame = df._native_frame
140134
pandas_series = PandasLikeSeries._from_iterable(
141-
data=np.full(native_frame.shape[0], value),
135+
data=[value],
142136
name="lit",
143-
index=native_frame.index,
137+
index=df._native_frame.index[0:1],
144138
implementation=self._implementation,
145139
backend_version=self._backend_version,
146140
)

tests/frame/lit_test.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_lit(
2424
request.applymarker(pytest.mark.xfail)
2525
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
2626
df_raw = constructor(data)
27-
df = nw.from_native(df_raw)
27+
df = nw.from_native(df_raw).lazy()
2828
result = df.with_columns(nw.lit(2, dtype).alias("lit"))
2929
expected = {
3030
"a": [1, 3, 2],
@@ -35,22 +35,6 @@ def test_lit(
3535
compare_dicts(result, expected)
3636

3737

38-
def test_lit_operation(constructor: Any) -> None:
39-
data = {"a": [1, 3, 2]}
40-
df_raw = constructor(data)
41-
df = nw.from_native(df_raw)
42-
43-
result = df.select(
44-
left_lit=nw.lit(1) + nw.col("a"),
45-
right_lit=nw.col("a") - nw.lit(1),
46-
)
47-
expected = {
48-
"left_lit": [2, 4, 3],
49-
"right_lit": [0, 2, 1],
50-
}
51-
compare_dicts(result, expected)
52-
53-
5438
def test_lit_error(constructor: Any) -> None:
5539
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
5640
df_raw = constructor(data)

0 commit comments

Comments
 (0)