@@ -181,14 +181,19 @@ def _function(self, name: str, *args: NativeExprT | PythonLiteral) -> NativeExpr
181181 def _lit (self , value : Any ) -> NativeExprT :
182182 return self .__narwhals_namespace__ ()._lit (value )
183183
184- def _when (self , condition : NativeExprT , value : NativeExprT ) -> NativeExprT :
185- return self .__narwhals_namespace__ ()._when (condition , value )
186-
187184 def _coalesce (self , * expr : NativeExprT ) -> NativeExprT :
188185 return self .__narwhals_namespace__ ()._coalesce (* expr )
189186
190187 def _count_star (self ) -> NativeExprT : ...
191188
189+ def _when (
190+ self ,
191+ condition : NativeExprT ,
192+ value : NativeExprT ,
193+ otherwise : NativeExprT | None = None ,
194+ ) -> NativeExprT :
195+ return self .__narwhals_namespace__ ()._when (condition , value , otherwise )
196+
192197 def _window_expression (
193198 self ,
194199 expr : NativeExprT ,
@@ -492,6 +497,16 @@ def round(self, decimals: int) -> Self:
492497 lambda expr : self ._function ("round" , expr , self ._lit (decimals ))
493498 )
494499
500+ def sqrt (self ) -> Self :
501+ def _sqrt (expr : NativeExprT ) -> NativeExprT :
502+ return self ._when (
503+ expr < self ._lit (0 ), # type: ignore[operator]
504+ self ._lit (float ("nan" )),
505+ self ._function ("sqrt" , expr ),
506+ )
507+
508+ return self ._with_elementwise (_sqrt )
509+
495510 def exp (self ) -> Self :
496511 return self ._with_elementwise (lambda expr : self ._function ("exp" , expr ))
497512
0 commit comments