MCPcopy Index your code
hub / github.com/pydata/xarray / format

Method format

xarray/core/accessor_str.py:586–669  ·  view source on GitHub ↗

Perform python string formatting on each element of the DataArray. This is equivalent to calling `str.format` on every element of the DataArray. The replacement values can either be a string-like scalar or array-like of string-like values. If array-like, the

(
        self,
        *args: Any,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

584 return start.str.cat(*others, sep=sep)
585
586 def format(
587 self,
588 *args: Any,
589 **kwargs: Any,
590 ) -> T_DataArray:
591 """
592 Perform python string formatting on each element of the DataArray.
593
594 This is equivalent to calling `str.format` on every element of the
595 DataArray. The replacement values can either be a string-like
596 scalar or array-like of string-like values. If array-like,
597 the values will be broadcast and applied elementwiseto the input
598 DataArray.
599
600 .. note::
601 Array-like values provided as `*args` will have their
602 dimensions added even if those arguments are not used in any
603 string formatting.
604
605 .. warning::
606 Array-like arguments are only applied elementwise for `*args`.
607 For `**kwargs`, values are used as-is.
608
609 Parameters
610 ----------
611 *args : str or bytes or array-like of str or bytes
612 Values for positional formatting.
613 If array-like, the values are broadcast and applied elementwise.
614 The dimensions will be placed at the end of the output array dimensions
615 in the order they are provided.
616 **kwargs : str or bytes or array-like of str or bytes
617 Values for keyword-based formatting.
618 These are **not** broadcast or applied elementwise.
619
620 Returns
621 -------
622 formatted : same type as values
623
624 Examples
625 --------
626 Create an array to format.
627
628 >>> values = xr.DataArray(
629 ... ["{} is {adj0}", "{} and {} are {adj1}"],
630 ... dims=["X"],
631 ... )
632
633 Set the values to fill.
634
635 >>> noun0 = xr.DataArray(
636 ... ["spam", "egg"],
637 ... dims=["Y"],
638 ... )
639 >>> noun1 = xr.DataArray(
640 ... ["lancelot", "arthur"],
641 ... dims=["ZZ"],
642 ... )
643 >>> adj0 = "unexpected"

Callers 5

_inject_docstringFunction · 0.45
inject_reduce_methodsFunction · 0.45
_reduce_methodMethod · 0.45
RollingClass · 0.45

Calls 3

_stringifyMethod · 0.95
_applyMethod · 0.95
itemsMethod · 0.80

Tested by

no test coverage detected