Skip to content

Commit aeba238

Browse files
committed
Fix unnecesary dic call pandas/core/strings/accesory.py pandas-dev#38138
1 parent 5a13697 commit aeba238

File tree

1 file changed

+68
-52
lines changed

1 file changed

+68
-52
lines changed

pandas/core/strings/accessor.py

Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from pandas.core.base import NoNewAttributesMixin
2828

29-
_shared_docs: Dict[str, str] = dict()
29+
_shared_docs: Dict[str, str] = {}
3030
_cpython_optimized_encoders = (
3131
"utf-8",
3232
"utf8",
@@ -1446,17 +1446,17 @@ def pad(self, width, side="left", fillchar=" "):
14461446
filled : Series/Index of objects.
14471447
"""
14481448

1449-
@Appender(_shared_docs["str_pad"] % dict(side="left and right", method="center"))
1449+
@Appender(_shared_docs["str_pad"] % {"side": "left and right", "method": "center"})
14501450
@forbid_nonstring_types(["bytes"])
14511451
def center(self, width, fillchar=" "):
14521452
return self.pad(width, side="both", fillchar=fillchar)
14531453

1454-
@Appender(_shared_docs["str_pad"] % dict(side="right", method="ljust"))
1454+
@Appender(_shared_docs["str_pad"] % {"side": "right", "method": "ljust"})
14551455
@forbid_nonstring_types(["bytes"])
14561456
def ljust(self, width, fillchar=" "):
14571457
return self.pad(width, side="right", fillchar=fillchar)
14581458

1459-
@Appender(_shared_docs["str_pad"] % dict(side="left", method="rjust"))
1459+
@Appender(_shared_docs["str_pad"] % {"side": "left", "method": "rjust"})
14601460
@forbid_nonstring_types(["bytes"])
14611461
def rjust(self, width, fillchar=" "):
14621462
return self.pad(width, side="left", fillchar=fillchar)
@@ -1790,9 +1790,11 @@ def encode(self, encoding, errors="strict"):
17901790

17911791
@Appender(
17921792
_shared_docs["str_strip"]
1793-
% dict(
1794-
side="left and right sides", method="strip", position="leading and trailing"
1795-
)
1793+
% {
1794+
"side": "left and right sides",
1795+
"method": "strip",
1796+
"position": "leading and trailing"
1797+
}
17961798
)
17971799
@forbid_nonstring_types(["bytes"])
17981800
def strip(self, to_strip=None):
@@ -1801,7 +1803,11 @@ def strip(self, to_strip=None):
18011803

18021804
@Appender(
18031805
_shared_docs["str_strip"]
1804-
% dict(side="left side", method="lstrip", position="leading")
1806+
% {
1807+
"side": "left side",
1808+
"method": "lstrip",
1809+
"position": "leading"
1810+
}
18051811
)
18061812
@forbid_nonstring_types(["bytes"])
18071813
def lstrip(self, to_strip=None):
@@ -1810,7 +1816,11 @@ def lstrip(self, to_strip=None):
18101816

18111817
@Appender(
18121818
_shared_docs["str_strip"]
1813-
% dict(side="right side", method="rstrip", position="trailing")
1819+
% {
1820+
"side": "right side",
1821+
"method": "rstrip",
1822+
"position": "trailing"
1823+
}
18141824
)
18151825
@forbid_nonstring_types(["bytes"])
18161826
def rstrip(self, to_strip=None):
@@ -2412,11 +2422,11 @@ def extractall(self, pat, flags=0):
24122422

24132423
@Appender(
24142424
_shared_docs["find"]
2415-
% dict(
2416-
side="lowest",
2417-
method="find",
2418-
also="rfind : Return highest indexes in each strings.",
2419-
)
2425+
% {
2426+
"side": "lowest",
2427+
"method": "find",
2428+
"also": "rfind : Return highest indexes in each strings."
2429+
}
24202430
)
24212431
@forbid_nonstring_types(["bytes"])
24222432
def find(self, sub, start=0, end=None):
@@ -2429,11 +2439,11 @@ def find(self, sub, start=0, end=None):
24292439

24302440
@Appender(
24312441
_shared_docs["find"]
2432-
% dict(
2433-
side="highest",
2434-
method="rfind",
2435-
also="find : Return lowest indexes in each strings.",
2436-
)
2442+
% {
2443+
"side": "highest",
2444+
"method": "rfind",
2445+
"also": "find : Return lowest indexes in each strings."
2446+
}
24372447
)
24382448
@forbid_nonstring_types(["bytes"])
24392449
def rfind(self, sub, start=0, end=None):
@@ -2495,12 +2505,12 @@ def normalize(self, form):
24952505

24962506
@Appender(
24972507
_shared_docs["index"]
2498-
% dict(
2499-
side="lowest",
2500-
similar="find",
2501-
method="index",
2502-
also="rindex : Return highest indexes in each strings.",
2503-
)
2508+
% {
2509+
"side": "lowest",
2510+
"similar": "find",
2511+
"method": "index",
2512+
"also": "rindex : Return highest indexes in each strings."
2513+
}
25042514
)
25052515
@forbid_nonstring_types(["bytes"])
25062516
def index(self, sub, start=0, end=None):
@@ -2513,12 +2523,12 @@ def index(self, sub, start=0, end=None):
25132523

25142524
@Appender(
25152525
_shared_docs["index"]
2516-
% dict(
2517-
side="highest",
2518-
similar="rfind",
2519-
method="rindex",
2520-
also="index : Return lowest indexes in each strings.",
2521-
)
2526+
% {
2527+
"side": "highest",
2528+
"similar": "rfind",
2529+
"method": "rindex",
2530+
"also": "index : Return lowest indexes in each strings."
2531+
}
25222532
)
25232533
@forbid_nonstring_types(["bytes"])
25242534
def rindex(self, sub, start=0, end=None):
@@ -2653,18 +2663,24 @@ def len(self):
26532663
# isalpha, isnumeric isalnum isdigit isdecimal isspace islower isupper istitle
26542664
# _doc_args holds dict of strings to use in substituting casemethod docs
26552665
_doc_args: Dict[str, Dict[str, str]] = {}
2656-
_doc_args["lower"] = dict(type="lowercase", method="lower", version="")
2657-
_doc_args["upper"] = dict(type="uppercase", method="upper", version="")
2658-
_doc_args["title"] = dict(type="titlecase", method="title", version="")
2659-
_doc_args["capitalize"] = dict(
2660-
type="be capitalized", method="capitalize", version=""
2661-
)
2662-
_doc_args["swapcase"] = dict(type="be swapcased", method="swapcase", version="")
2663-
_doc_args["casefold"] = dict(
2664-
type="be casefolded",
2665-
method="casefold",
2666-
version="\n .. versionadded:: 0.25.0\n",
2667-
)
2666+
_doc_args["lower"] = {"type": "lowercase", "method": "lower", "version": ""}
2667+
_doc_args["upper"] = {"type": "uppercase", "method": "upper", "version": ""}
2668+
_doc_args["title"] = {"type": "titlecase", "method": "title", "version": ""}
2669+
_doc_args["capitalize"] = {
2670+
"type": "be capitalized",
2671+
"method": "capitalize",
2672+
"version": ""
2673+
}
2674+
_doc_args["swapcase"] = {
2675+
"type": "be swapcased",
2676+
"method": "swapcase",
2677+
"version": "",
2678+
}
2679+
_doc_args["casefold"] = {
2680+
"type": "be casefolded",
2681+
"method": "casefold",
2682+
"version": "\n .. versionadded:: 0.25.0\n",
2683+
}
26682684

26692685
@Appender(_shared_docs["casemethods"] % _doc_args["lower"])
26702686
@forbid_nonstring_types(["bytes"])
@@ -2844,15 +2860,15 @@ def casefold(self):
28442860
3 False
28452861
dtype: bool
28462862
"""
2847-
_doc_args["isalnum"] = dict(type="alphanumeric", method="isalnum")
2848-
_doc_args["isalpha"] = dict(type="alphabetic", method="isalpha")
2849-
_doc_args["isdigit"] = dict(type="digits", method="isdigit")
2850-
_doc_args["isspace"] = dict(type="whitespace", method="isspace")
2851-
_doc_args["islower"] = dict(type="lowercase", method="islower")
2852-
_doc_args["isupper"] = dict(type="uppercase", method="isupper")
2853-
_doc_args["istitle"] = dict(type="titlecase", method="istitle")
2854-
_doc_args["isnumeric"] = dict(type="numeric", method="isnumeric")
2855-
_doc_args["isdecimal"] = dict(type="decimal", method="isdecimal")
2863+
_doc_args["isalnum"] = {"type": "alphanumeric", "method": "isalnum"}
2864+
_doc_args["isalpha"] = {"type": "alphabetic", "method": "isalpha"}
2865+
_doc_args["isdigit"] = {"type": "digits", "method": "isdigit"}
2866+
_doc_args["isspace"] = {"type": "whitespace", "method": "isspace"}
2867+
_doc_args["islower"] = {"type": "lowercase", "method": "islower"}
2868+
_doc_args["isupper"] = {"type": "uppercase", "method": "isupper"}
2869+
_doc_args["istitle"] = {"type": "titlecase", "method": "istitle"}
2870+
_doc_args["isnumeric"] = {"type": "numeric", "method": "isnumeric"}
2871+
_doc_args["isdecimal"] = {"type": "decimal", "method": "isdecimal"}
28562872
# force _noarg_wrapper return type with dtype=np.dtype(bool) (GH 29624)
28572873

28582874
isalnum = _map_and_wrap(

0 commit comments

Comments
 (0)