Skip to content

Commit ce358e6

Browse files
jordan-d-murphypmhatre1
authored andcommitted
DOC: fix PR02 errors in docstring for pandas.Series.str.wrap (pandas-dev#57321)
* DOC: fix PR02 errors in docstring for pandas.Series.str.wrap * change signature of wrap to include kwargs as explicit parameters * fixing call to _str_wrap() * Added all textwrap.TextWrapper parameters * update width argument to remain positional by default
1 parent 0adf3cc commit ce358e6

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8080
pandas.Series.dt.ceil\
8181
pandas.Series.dt.month_name\
8282
pandas.Series.dt.day_name\
83-
pandas.Series.str.wrap\
8483
pandas.Series.cat.rename_categories\
8584
pandas.Series.cat.reorder_categories\
8685
pandas.Series.cat.add_categories\

pandas/core/strings/accessor.py

+63-4
Original file line numberDiff line numberDiff line change
@@ -2232,26 +2232,66 @@ def removesuffix(self, suffix: str):
22322232
return self._wrap_result(result)
22332233

22342234
@forbid_nonstring_types(["bytes"])
2235-
def wrap(self, width: int, **kwargs):
2235+
def wrap(
2236+
self,
2237+
width: int,
2238+
expand_tabs: bool = True,
2239+
tabsize: int = 8,
2240+
replace_whitespace: bool = True,
2241+
drop_whitespace: bool = True,
2242+
initial_indent: str = "",
2243+
subsequent_indent: str = "",
2244+
fix_sentence_endings: bool = False,
2245+
break_long_words: bool = True,
2246+
break_on_hyphens: bool = True,
2247+
max_lines: int | None = None,
2248+
placeholder: str = " [...]",
2249+
):
22362250
r"""
22372251
Wrap strings in Series/Index at specified line width.
22382252
22392253
This method has the same keyword parameters and defaults as
2240-
:class:`textwrap.TextWrapper`.
2254+
:class:`textwrap.TextWrapper`.
22412255
22422256
Parameters
22432257
----------
2244-
width : int
2258+
width : int, optional
22452259
Maximum line width.
22462260
expand_tabs : bool, optional
22472261
If True, tab characters will be expanded to spaces (default: True).
2262+
tabsize : int, optional
2263+
If expand_tabs is true, then all tab characters in text will be
2264+
expanded to zero or more spaces, depending on the current column
2265+
and the given tab size (default: 8).
22482266
replace_whitespace : bool, optional
22492267
If True, each whitespace character (as defined by string.whitespace)
22502268
remaining after tab expansion will be replaced by a single space
22512269
(default: True).
22522270
drop_whitespace : bool, optional
22532271
If True, whitespace that, after wrapping, happens to end up at the
22542272
beginning or end of a line is dropped (default: True).
2273+
initial_indent : str, optional
2274+
String that will be prepended to the first line of wrapped output.
2275+
Counts towards the length of the first line. The empty string is
2276+
not indented (default: '').
2277+
subsequent_indent : str, optional
2278+
String that will be prepended to all lines of wrapped output except
2279+
the first. Counts towards the length of each line except the first
2280+
(default: '').
2281+
fix_sentence_endings : bool, optional
2282+
If true, TextWrapper attempts to detect sentence endings and ensure
2283+
that sentences are always separated by exactly two spaces. This is
2284+
generally desired for text in a monospaced font. However, the sentence
2285+
detection algorithm is imperfect: it assumes that a sentence ending
2286+
consists of a lowercase letter followed by one of '.', '!', or '?',
2287+
possibly followed by one of '"' or "'", followed by a space. One
2288+
problem with this algorithm is that it is unable to detect the
2289+
difference between “Dr.” in `[...] Dr. Frankenstein's monster [...]`
2290+
and “Spot.” in `[...] See Spot. See Spot run [...]`
2291+
Since the sentence detection algorithm relies on string.lowercase
2292+
for the definition of “lowercase letter”, and a convention of using
2293+
two spaces after a period to separate sentences on the same line,
2294+
it is specific to English-language texts (default: False).
22552295
break_long_words : bool, optional
22562296
If True, then words longer than width will be broken in order to ensure
22572297
that no lines are longer than width. If it is false, long words will
@@ -2262,6 +2302,12 @@ def wrap(self, width: int, **kwargs):
22622302
only whitespaces will be considered as potentially good places for line
22632303
breaks, but you need to set break_long_words to false if you want truly
22642304
insecable words (default: True).
2305+
max_lines : int, optional
2306+
If not None, then the output will contain at most max_lines lines, with
2307+
placeholder appearing at the end of the output (default: None).
2308+
placeholder : str, optional
2309+
String that will appear at the end of the output text if it has been
2310+
truncated (default: ' [...]').
22652311
22662312
Returns
22672313
-------
@@ -2287,7 +2333,20 @@ def wrap(self, width: int, **kwargs):
22872333
1 another line\nto be\nwrapped
22882334
dtype: object
22892335
"""
2290-
result = self._data.array._str_wrap(width, **kwargs)
2336+
result = self._data.array._str_wrap(
2337+
width=width,
2338+
expand_tabs=expand_tabs,
2339+
tabsize=tabsize,
2340+
replace_whitespace=replace_whitespace,
2341+
drop_whitespace=drop_whitespace,
2342+
initial_indent=initial_indent,
2343+
subsequent_indent=subsequent_indent,
2344+
fix_sentence_endings=fix_sentence_endings,
2345+
break_long_words=break_long_words,
2346+
break_on_hyphens=break_on_hyphens,
2347+
max_lines=max_lines,
2348+
placeholder=placeholder,
2349+
)
22912350
return self._wrap_result(result)
22922351

22932352
@forbid_nonstring_types(["bytes"])

0 commit comments

Comments
 (0)