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

Method wrap

xarray/core/accessor_str.py:1645–1670  ·  view source on GitHub ↗

Wrap long strings in the array in paragraphs with length less than `width`. This method has the same keyword parameters and defaults as :class:`textwrap.TextWrapper`. If `width` is array-like, it is broadcast against the array and applied elementwise.

(self, width: int | Any, **kwargs)

Source from the content-addressed store, hash-verified

1643 return self.strip(to_strip, side="right")
1644
1645 def wrap(self, width: int | Any, **kwargs) -> T_DataArray:
1646 """
1647 Wrap long strings in the array in paragraphs with length less than `width`.
1648
1649 This method has the same keyword parameters and defaults as
1650 :class:`textwrap.TextWrapper`.
1651
1652 If `width` is array-like, it is broadcast against the array and applied
1653 elementwise.
1654
1655 Parameters
1656 ----------
1657 width : int or array-like of int
1658 Maximum line-width.
1659 If array-like, it is broadcast.
1660 **kwargs
1661 keyword arguments passed into :class:`textwrap.TextWrapper`.
1662
1663 Returns
1664 -------
1665 wrapped : same type as values
1666 """
1667 ifunc = lambda x: textwrap.TextWrapper(width=x, **kwargs)
1668 tw = StringAccessor(width)._apply(func=ifunc, dtype=np.object_) # type: ignore[type-var] # hack?
1669 func = lambda x, itw: "\n".join(itw.wrap(x))
1670 return self._apply(func=func, func_args=(tw,))
1671
1672 # Mapping is only covariant in its values, maybe use a custom CovariantMapping?
1673 def translate(self, table: Mapping[Any, str | bytes | int | None]) -> T_DataArray:

Callers 4

label_from_attrsFunction · 0.80
test_empty_str_methodsFunction · 0.80
test_wrapFunction · 0.80
test_wrap_kwargs_passedFunction · 0.80

Calls 3

_applyMethod · 0.95
StringAccessorClass · 0.85
joinMethod · 0.45

Tested by 3

test_empty_str_methodsFunction · 0.64
test_wrapFunction · 0.64
test_wrap_kwargs_passedFunction · 0.64