Skip to content

Add defaults to str accessor methods #1305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class Index(IndexOpsMixin[S1]):
Index[int],
Index[bytes],
Index[_str],
Index[type[object]],
Index,
]: ...
@final
def is_(self, other) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
Series[int],
Series[bytes],
Series[_str],
Series[type[object]],
Series,
]: ...
@property
def dt(self) -> CombinedDatetimelikeProperties: ...
Expand Down
197 changes: 95 additions & 102 deletions pandas-stubs/core/strings/accessor.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from builtins import slice as _slice
from collections.abc import (
Callable,
Hashable,
Mapping,
Sequence,
)
import re
from typing import (
Any,
Generic,
Literal,
TypeVar,
Expand All @@ -27,6 +28,7 @@ from pandas.core.base import NoNewAttributesMixin
from pandas._libs.tslibs.nattype import NaTType
from pandas._typing import (
AlignJoin,
DtypeObj,
Scalar,
T,
np_ndarray_bool,
Expand All @@ -45,7 +47,7 @@ _T_BYTES = TypeVar("_T_BYTES", bound=Series[bytes] | Index[bytes])
# Used for the result of str.decode
_T_STR = TypeVar("_T_STR", bound=Series[str] | Index[str])
# Used for the result of str.partition
_T_OBJECT = TypeVar("_T_OBJECT", bound=Series[type[object]] | Index[type[object]])
_T_OBJECT = TypeVar("_T_OBJECT", bound=Series | Index)

class StringMethods(
NoNewAttributesMixin,
Expand All @@ -57,163 +59,163 @@ class StringMethods(
@overload
def cat(
self,
*,
sep: str,
na_rep: str | None = ...,
join: AlignJoin = ...,
) -> str: ...
@overload
def cat(
self,
others: Literal[None] = ...,
*,
sep: str,
na_rep: str | None = ...,
join: AlignJoin = ...,
others: None = None,
sep: str | None = None,
na_rep: str | None = None,
join: AlignJoin = "left",
) -> str: ...
@overload
def cat(
self,
others: (
Series[str] | Index[str] | pd.DataFrame | npt.NDArray[np.str_] | list[str]
),
sep: str = ...,
na_rep: str | None = ...,
join: AlignJoin = ...,
sep: str | None = None,
na_rep: str | None = None,
join: AlignJoin = "left",
) -> _T_STR: ...
@overload
def split(
self,
pat: str | re.Pattern[str] = ...,
pat: str | re.Pattern[str] | None = None,
*,
n: int = ...,
n: int = -1,
expand: Literal[True],
regex: bool = ...,
regex: bool | None = None,
) -> _T_EXPANDING: ...
@overload
def split(
self,
pat: str | re.Pattern[str] = ...,
pat: str | re.Pattern[str] | None = None,
*,
n: int = ...,
expand: Literal[False] = ...,
regex: bool = ...,
n: int = -1,
expand: Literal[False] = False,
regex: bool | None = None,
) -> _T_LIST_STR: ...
@overload
def rsplit(
self, pat: str = ..., *, n: int = ..., expand: Literal[True]
self, pat: str | None = None, *, n: int = -1, expand: Literal[True]
) -> _T_EXPANDING: ...
@overload
def rsplit(
self, pat: str = ..., *, n: int = ..., expand: Literal[False] = ...
self, pat: str | None = None, *, n: int = -1, expand: Literal[False] = False
) -> _T_LIST_STR: ...
@overload
def partition(self, sep: str = ...) -> _T_EXPANDING: ...
@overload
def partition(self, *, expand: Literal[True]) -> _T_EXPANDING: ...
@overload
def partition(self, sep: str, expand: Literal[True]) -> _T_EXPANDING: ...
@overload
@overload # expand=True
def partition(
self, sep: str = " ", expand: Literal[True] = True
) -> _T_EXPANDING: ...
@overload # expand=False (positional argument)
def partition(self, sep: str, expand: Literal[False]) -> _T_OBJECT: ...
@overload
def partition(self, *, expand: Literal[False]) -> _T_OBJECT: ...
@overload
def rpartition(self, sep: str = ...) -> _T_EXPANDING: ...
@overload
def rpartition(self, *, expand: Literal[True]) -> _T_EXPANDING: ...
@overload
def rpartition(self, sep: str, expand: Literal[True]) -> _T_EXPANDING: ...
@overload
@overload # expand=False (keyword argument)
def partition(self, sep: str = " ", *, expand: Literal[False]) -> _T_OBJECT: ...
@overload # expand=True
def rpartition(
self, sep: str = " ", expand: Literal[True] = True
) -> _T_EXPANDING: ...
@overload # expand=False (positional argument)
def rpartition(self, sep: str, expand: Literal[False]) -> _T_OBJECT: ...
@overload
def rpartition(self, *, expand: Literal[False]) -> _T_OBJECT: ...
def get(self, i: int) -> _T_STR: ...
@overload # expand=False (keyword argument)
def rpartition(self, sep: str = " ", *, expand: Literal[False]) -> _T_OBJECT: ...
def get(self, i: int | Hashable) -> _T_STR: ...
def join(self, sep: str) -> _T_STR: ...
def contains(
self,
pat: str | re.Pattern[str],
case: bool = ...,
flags: int = ...,
case: bool = True,
flags: int = 0,
na: Scalar | NaTType | None = ...,
regex: bool = ...,
regex: bool = True,
) -> _T_BOOL: ...
def match(
self,
pat: str | re.Pattern[str],
case: bool = ...,
flags: int = ...,
na: Any = ...,
case: bool = True,
flags: int = 0,
na: Scalar | NaTType | None = ...,
) -> _T_BOOL: ...
def fullmatch(
self,
pat: str | re.Pattern[str],
case: bool = True,
flags: int = 0,
na: Scalar | NaTType | None = ...,
) -> _T_BOOL: ...
def replace(
self,
pat: str | re.Pattern[str],
repl: str | Callable[[re.Match[str]], str],
n: int = ...,
case: bool | None = ...,
flags: int = ...,
regex: bool = ...,
n: int = -1,
case: bool | None = None,
flags: int = 0,
regex: bool = False,
) -> _T_STR: ...
def repeat(self, repeats: int | Sequence[int]) -> _T_STR: ...
def pad(
self,
width: int,
side: Literal["left", "right", "both"] = ...,
fillchar: str = ...,
side: Literal["left", "right", "both"] = "left",
fillchar: str = " ",
) -> _T_STR: ...
def center(self, width: int, fillchar: str = ...) -> _T_STR: ...
def ljust(self, width: int, fillchar: str = ...) -> _T_STR: ...
def rjust(self, width: int, fillchar: str = ...) -> _T_STR: ...
def center(self, width: int, fillchar: str = " ") -> _T_STR: ...
def ljust(self, width: int, fillchar: str = " ") -> _T_STR: ...
def rjust(self, width: int, fillchar: str = " ") -> _T_STR: ...
def zfill(self, width: int) -> _T_STR: ...
def slice(
self, start: int | None = ..., stop: int | None = ..., step: int | None = ...
self, start: int | None = None, stop: int | None = None, step: int | None = None
) -> T: ...
def slice_replace(
self, start: int | None = ..., stop: int | None = ..., repl: str | None = ...
self, start: int | None = None, stop: int | None = None, repl: str | None = None
) -> _T_STR: ...
def decode(self, encoding: str, errors: str = ...) -> _T_STR: ...
def encode(self, encoding: str, errors: str = ...) -> _T_BYTES: ...
def strip(self, to_strip: str | None = ...) -> _T_STR: ...
def lstrip(self, to_strip: str | None = ...) -> _T_STR: ...
def rstrip(self, to_strip: str | None = ...) -> _T_STR: ...
def decode(
self, encoding: str, errors: str = "strict", dtype: str | DtypeObj | None = None
) -> _T_STR: ...
def encode(self, encoding: str, errors: str = "strict") -> _T_BYTES: ...
def strip(self, to_strip: str | None = None) -> _T_STR: ...
def lstrip(self, to_strip: str | None = None) -> _T_STR: ...
def rstrip(self, to_strip: str | None = None) -> _T_STR: ...
def removeprefix(self, prefix: str) -> _T_STR: ...
def removesuffix(self, suffix: str) -> _T_STR: ...
def wrap(
self,
width: int,
expand_tabs: bool | None = ...,
replace_whitespace: bool | None = ...,
drop_whitespace: bool | None = ...,
break_long_words: bool | None = ...,
break_on_hyphens: bool | None = ...,
*,
# kwargs passed to textwrap.TextWrapper
expand_tabs: bool = True,
replace_whitespace: bool = True,
drop_whitespace: bool = True,
break_long_words: bool = True,
break_on_hyphens: bool = True,
) -> _T_STR: ...
def get_dummies(self, sep: str = ...) -> _T_EXPANDING: ...
def translate(self, table: dict[int, int | str | None] | None) -> _T_STR: ...
def count(self, pat: str, flags: int = ...) -> _T_INT: ...
def startswith(self, pat: str | tuple[str, ...], na: Any = ...) -> _T_BOOL: ...
def endswith(self, pat: str | tuple[str, ...], na: Any = ...) -> _T_BOOL: ...
def findall(self, pat: str | re.Pattern[str], flags: int = ...) -> _T_LIST_STR: ...
@overload
def get_dummies(self, sep: str = "|") -> _T_EXPANDING: ...
def translate(self, table: Mapping[int, int | str | None] | None) -> _T_STR: ...
def count(self, pat: str, flags: int = 0) -> _T_INT: ...
def startswith(
self, pat: str | tuple[str, ...], na: Scalar | NaTType | None = ...
) -> _T_BOOL: ...
def endswith(
self, pat: str | tuple[str, ...], na: Scalar | NaTType | None = ...
) -> _T_BOOL: ...
def findall(self, pat: str | re.Pattern[str], flags: int = 0) -> _T_LIST_STR: ...
@overload # expand=True
def extract(
self,
pat: str | re.Pattern[str],
flags: int = ...,
*,
expand: Literal[True] = ...,
self, pat: str | re.Pattern[str], flags: int = 0, expand: Literal[True] = True
) -> pd.DataFrame: ...
@overload
@overload # expand=False (positional argument)
def extract(
self, pat: str | re.Pattern[str], flags: int, expand: Literal[False]
) -> _T_OBJECT: ...
@overload
@overload # expand=False (keyword argument)
def extract(
self, pat: str | re.Pattern[str], flags: int = ..., *, expand: Literal[False]
self, pat: str | re.Pattern[str], flags: int = 0, *, expand: Literal[False]
) -> _T_OBJECT: ...
def extractall(
self, pat: str | re.Pattern[str], flags: int = ...
self, pat: str | re.Pattern[str], flags: int = 0
) -> pd.DataFrame: ...
def find(self, sub: str, start: int = ..., end: int | None = ...) -> _T_INT: ...
def rfind(self, sub: str, start: int = ..., end: int | None = ...) -> _T_INT: ...
def find(self, sub: str, start: int = 0, end: int | None = None) -> _T_INT: ...
def rfind(self, sub: str, start: int = 0, end: int | None = None) -> _T_INT: ...
def normalize(self, form: Literal["NFC", "NFKC", "NFD", "NFKD"]) -> _T_STR: ...
def index(self, sub: str, start: int = ..., end: int | None = ...) -> _T_INT: ...
def rindex(self, sub: str, start: int = ..., end: int | None = ...) -> _T_INT: ...
def index(self, sub: str, start: int = 0, end: int | None = None) -> _T_INT: ...
def rindex(self, sub: str, start: int = 0, end: int | None = None) -> _T_INT: ...
def len(self) -> _T_INT: ...
def lower(self) -> _T_STR: ...
def upper(self) -> _T_STR: ...
Expand All @@ -230,12 +232,3 @@ class StringMethods(
def istitle(self) -> _T_BOOL: ...
def isnumeric(self) -> _T_BOOL: ...
def isdecimal(self) -> _T_BOOL: ...
def fullmatch(
self,
pat: str | re.Pattern[str],
case: bool = ...,
flags: int = ...,
na: Any = ...,
) -> _T_BOOL: ...
def removeprefix(self, prefix: str) -> _T_STR: ...
def removesuffix(self, suffix: str) -> _T_STR: ...
Loading
Loading