MCPcopy Create free account
hub / github.com/dask/dask / _wrap_expr_method_operator

Function _wrap_expr_method_operator

dask/dataframe/dask_expr/_collection.py:205–297  ·  view source on GitHub ↗

Add method operators to Series or DataFrame like DataFrame.add. _wrap_expr_method_operator("add", DataFrame)

(name, class_)

Source from the content-addressed store, hash-verified

203
204
205def _wrap_expr_method_operator(name, class_):
206 """
207 Add method operators to Series or DataFrame like DataFrame.add.
208 _wrap_expr_method_operator("add", DataFrame)
209 """
210 if class_ == DataFrame:
211
212 def method(self, other, axis="columns", level=None, fill_value=None):
213 if level is not None:
214 raise NotImplementedError("level must be None")
215
216 axis = _validate_axis(axis)
217
218 if (
219 is_dataframe_like(other)
220 or is_series_like(other)
221 and axis in (0, "index")
222 ) and not is_dask_collection(other):
223 other = self._create_alignable_frame(other)
224
225 if axis in (1, "columns"):
226 if isinstance(other, Series):
227 msg = f"Unable to {name} dd.Series with axis=1"
228 raise ValueError(msg)
229
230 frame = self
231 if isinstance(other, FrameBase) and not expr.are_co_aligned(
232 self.expr, other.expr
233 ):
234 return new_collection(
235 expr.MethodOperatorAlign(
236 op=name,
237 frame=frame,
238 other=other,
239 axis=axis,
240 level=level,
241 fill_value=fill_value,
242 )
243 )
244
245 return new_collection(
246 expr.MethodOperator(
247 name=name,
248 left=frame,
249 right=other,
250 axis=axis,
251 level=level,
252 fill_value=fill_value,
253 )
254 )
255
256 elif class_ == Series:
257
258 def method(self, other, level=None, fill_value=None, axis=0): # type: ignore[misc]
259 if level is not None:
260 raise NotImplementedError("level must be None")
261
262 axis = _validate_axis(axis)

Callers 1

_collection.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected