MCPcopy
hub / github.com/pydata/xarray / __call__

Method __call__

xarray/tests/test_units.py:306–344  ·  view source on GitHub ↗
(self, obj, *args, **kwargs)

Source from the content-addressed store, hash-verified

304 self.kwargs = kwargs
305
306 def __call__(self, obj, *args, **kwargs):
307 from functools import partial
308
309 all_args = merge_args(self.args, args)
310 all_kwargs = {**self.kwargs, **kwargs}
311
312 from xarray.core.groupby import GroupBy
313
314 xarray_classes = (
315 xr.Variable,
316 xr.DataArray,
317 xr.Dataset,
318 GroupBy,
319 )
320
321 if not isinstance(obj, xarray_classes):
322 # remove typical xarray args like "dim"
323 exclude_kwargs = ("dim", "dims")
324 # TODO: figure out a way to replace dim / dims with axis
325 all_kwargs = {
326 key: value
327 for key, value in all_kwargs.items()
328 if key not in exclude_kwargs
329 }
330 if self.fallback is not None:
331 func = partial(self.fallback, obj)
332 else:
333 func_attr = getattr(obj, self.name, None)
334
335 if func_attr is None or not callable(func_attr):
336 # fall back to module level numpy functions
337 numpy_func = getattr(np, self.name)
338 func = partial(numpy_func, obj)
339 else:
340 func = func_attr
341 else:
342 func = getattr(obj, self.name)
343
344 return func(*all_args, **all_kwargs)
345
346 def __repr__(self):
347 return f"method_{self.name}"

Callers

nothing calls this directly

Calls 3

merge_argsFunction · 0.85
itemsMethod · 0.80
funcFunction · 0.70

Tested by

no test coverage detected