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

Function _wrap_expr_method_operator

dask/dataframe/dask_expr/_collection.py:197–289  ·  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

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

Callers 1

_collection.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected