Skip to content

Commit 450384e

Browse files
authored
fix frame, generic, series.py (#38169)
1 parent ff78a02 commit 450384e

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

pandas/core/frame.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,27 @@
172172
# ---------------------------------------------------------------------
173173
# Docstring templates
174174

175-
_shared_doc_kwargs = dict(
176-
axes="index, columns",
177-
klass="DataFrame",
178-
axes_single_arg="{0 or 'index', 1 or 'columns'}",
179-
axis="""axis : {0 or 'index', 1 or 'columns'}, default 0
175+
_shared_doc_kwargs = {
176+
"axes": "index, columns",
177+
"klass": "DataFrame",
178+
"axes_single_arg": "{0 or 'index', 1 or 'columns'}",
179+
"axis": """axis : {0 or 'index', 1 or 'columns'}, default 0
180180
If 0 or 'index': apply function to each column.
181181
If 1 or 'columns': apply function to each row.""",
182-
optional_by="""
182+
"optional_by": """
183183
by : str or list of str
184184
Name or list of names to sort by.
185185
186186
- if `axis` is 0 or `'index'` then `by` may contain index
187187
levels and/or column labels.
188188
- if `axis` is 1 or `'columns'` then `by` may contain column
189189
levels and/or index labels.""",
190-
optional_labels="""labels : array-like, optional
190+
"optional_labels": """labels : array-like, optional
191191
New labels / index to conform the axis specified by 'axis' to.""",
192-
optional_axis="""axis : int or str, optional
192+
"optional_axis": """axis : int or str, optional
193193
Axis to target. Can be either the axis name ('index', 'columns')
194194
or number (0, 1).""",
195-
)
195+
}
196196

197197
_numeric_only_doc = """numeric_only : boolean, default None
198198
Include only float, int, boolean data. If None, will attempt to use
@@ -524,7 +524,7 @@ def __init__(
524524
return
525525

526526
mgr = self._init_mgr(
527-
data, axes=dict(index=index, columns=columns), dtype=dtype, copy=copy
527+
data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy
528528
)
529529

530530
elif isinstance(data, dict):
@@ -2902,7 +2902,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:
29022902
1 object
29032903
dtype: object
29042904
"""
2905-
nv.validate_transpose(args, dict())
2905+
nv.validate_transpose(args, {})
29062906
# construct the args
29072907

29082908
dtypes = list(self.dtypes)
@@ -7358,7 +7358,7 @@ def unstack(self, level=-1, fill_value=None):
73587358

73597359
return result.__finalize__(self, method="unstack")
73607360

7361-
@Appender(_shared_docs["melt"] % dict(caller="df.melt(", other="melt"))
7361+
@Appender(_shared_docs["melt"] % {"caller": "df.melt(", "other": "melt"})
73627362
def melt(
73637363
self,
73647364
id_vars=None,

pandas/core/generic.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@
128128
# goal is to be able to define the docs close to function, while still being
129129
# able to share
130130
_shared_docs = {**_shared_docs}
131-
_shared_doc_kwargs = dict(
132-
axes="keywords for axes",
133-
klass="Series/DataFrame",
134-
axes_single_arg="int or labels for object",
135-
args_transpose="axes to permute (int or label for object)",
136-
optional_by="""
131+
_shared_doc_kwargs = {
132+
"axes": "keywords for axes",
133+
"klass": "Series/DataFrame",
134+
"axes_single_arg": "int or labels for object",
135+
"args_transpose": "axes to permute (int or label for object)",
136+
"optional_by": """
137137
by : str or list of str
138138
Name or list of names to sort by""",
139-
)
139+
}
140140

141141

142142
bool_t = bool # Need alias because NDFrame has def bool:
@@ -484,7 +484,7 @@ def _get_block_manager_axis(cls, axis: Axis) -> int:
484484
def _get_axis_resolvers(self, axis: str) -> Dict[str, Union[Series, MultiIndex]]:
485485
# index or columns
486486
axis_index = getattr(self, axis)
487-
d = dict()
487+
d = {}
488488
prefix = axis[0]
489489

490490
for i, name in enumerate(axis_index.names):
@@ -1946,14 +1946,14 @@ def __array_ufunc__(
19461946
@final
19471947
def __getstate__(self) -> Dict[str, Any]:
19481948
meta = {k: getattr(self, k, None) for k in self._metadata}
1949-
return dict(
1950-
_mgr=self._mgr,
1951-
_typ=self._typ,
1952-
_metadata=self._metadata,
1953-
attrs=self.attrs,
1954-
_flags={k: self.flags[k] for k in self.flags._keys},
1949+
return {
1950+
"_mgr": self._mgr,
1951+
"_typ": self._typ,
1952+
"_metadata": self._metadata,
1953+
"attrs": self.attrs,
1954+
"_flags": {k: self.flags[k] for k in self.flags._keys},
19551955
**meta,
1956-
)
1956+
}
19571957

19581958
@final
19591959
def __setstate__(self, state):
@@ -1967,7 +1967,7 @@ def __setstate__(self, state):
19671967
if typ is not None:
19681968
attrs = state.get("_attrs", {})
19691969
object.__setattr__(self, "_attrs", attrs)
1970-
flags = state.get("_flags", dict(allows_duplicate_labels=True))
1970+
flags = state.get("_flags", {"allows_duplicate_labels": True})
19711971
object.__setattr__(self, "_flags", Flags(self, **flags))
19721972

19731973
# set in the order of internal names
@@ -7422,7 +7422,7 @@ def isna(self: FrameOrSeries) -> FrameOrSeries:
74227422
74237423
>>> df = pd.DataFrame(dict(age=[5, 6, np.NaN],
74247424
... born=[pd.NaT, pd.Timestamp('1939-05-27'),
7425-
... pd.Timestamp('1940-04-25')],
7425+
... pd.Timestamp('1940-04-25')],
74267426
... name=['Alfred', 'Batman', ''],
74277427
... toy=[None, 'Batmobile', 'Joker']))
74287428
>>> df
@@ -7489,7 +7489,7 @@ def notna(self: FrameOrSeries) -> FrameOrSeries:
74897489
74907490
>>> df = pd.DataFrame(dict(age=[5, 6, np.NaN],
74917491
... born=[pd.NaT, pd.Timestamp('1939-05-27'),
7492-
... pd.Timestamp('1940-04-25')],
7492+
... pd.Timestamp('1940-04-25')],
74937493
... name=['Alfred', 'Batman', ''],
74947494
... toy=[None, 'Batmobile', 'Joker']))
74957495
>>> df
@@ -8209,8 +8209,8 @@ def resample(
82098209
For DataFrame objects, the keyword `on` can be used to specify the
82108210
column instead of the index for resampling.
82118211
8212-
>>> d = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19],
8213-
... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]})
8212+
>>> d = {'price': [10, 11, 9, 13, 14, 18, 17, 19],
8213+
... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]}
82148214
>>> df = pd.DataFrame(d)
82158215
>>> df['week_starting'] = pd.date_range('01/01/2018',
82168216
... periods=8,
@@ -8235,8 +8235,8 @@ def resample(
82358235
specify on which level the resampling needs to take place.
82368236
82378237
>>> days = pd.date_range('1/1/2000', periods=4, freq='D')
8238-
>>> d2 = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19],
8239-
... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]})
8238+
>>> d2 = {'price': [10, 11, 9, 13, 14, 18, 17, 19],
8239+
... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]}
82408240
>>> df2 = pd.DataFrame(d2,
82418241
... index=pd.MultiIndex.from_product([days,
82428242
... ['morning',
@@ -10483,10 +10483,10 @@ def pct_change(
1048310483
Percentage change in French franc, Deutsche Mark, and Italian lira from
1048410484
1980-01-01 to 1980-03-01.
1048510485
10486-
>>> df = pd.DataFrame(dict(
10487-
... FR=[4.0405, 4.0963, 4.3149],
10488-
... GR=[1.7246, 1.7482, 1.8519],
10489-
... IT=[804.74, 810.01, 860.13]),
10486+
>>> df = pd.DataFrame({
10487+
... 'FR': [4.0405, 4.0963, 4.3149],
10488+
... 'GR': [1.7246, 1.7482, 1.8519],
10489+
... 'IT': [804.74, 810.01, 860.13]},
1049010490
... index=['1980-01-01', '1980-02-01', '1980-03-01'])
1049110491
>>> df
1049210492
FR GR IT
@@ -10503,10 +10503,10 @@ def pct_change(
1050310503
Percentage of change in GOOG and APPL stock volume. Shows computing
1050410504
the percentage change between columns.
1050510505
10506-
>>> df = pd.DataFrame(dict([
10507-
... ('2016', [1769950, 30586265]),
10508-
... ('2015', [1500923, 40912316]),
10509-
... ('2014', [1371819, 41403351])]),
10506+
>>> df = pd.DataFrame({
10507+
... '2016': [1769950, 30586265],
10508+
... '2015': [1500923, 40912316],
10509+
... '2014': [1371819, 41403351]},
1051010510
... index=['GOOG', 'APPL'])
1051110511
>>> df
1051210512
2016 2015 2014

pandas/core/series.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,21 @@
111111

112112
__all__ = ["Series"]
113113

114-
_shared_doc_kwargs = dict(
115-
axes="index",
116-
klass="Series",
117-
axes_single_arg="{0 or 'index'}",
118-
axis="""axis : {0 or 'index'}
114+
_shared_doc_kwargs = {
115+
"axes": "index",
116+
"klass": "Series",
117+
"axes_single_arg": "{0 or 'index'}",
118+
"axis": """axis : {0 or 'index'}
119119
Parameter needed for compatibility with DataFrame.""",
120-
inplace="""inplace : boolean, default False
120+
"inplace": """inplace : boolean, default False
121121
If True, performs operation inplace and returns None.""",
122-
unique="np.ndarray",
123-
duplicated="Series",
124-
optional_by="",
125-
optional_mapper="",
126-
optional_labels="",
127-
optional_axis="",
128-
)
122+
"unique": "np.ndarray",
123+
"duplicated": "Series",
124+
"optional_by": "",
125+
"optional_mapper": "",
126+
"optional_labels": "",
127+
"optional_axis": "",
128+
}
129129

130130

131131
def _coerce_method(converter):
@@ -1113,7 +1113,7 @@ def repeat(self, repeats, axis=None) -> "Series":
11131113
2 c
11141114
dtype: object
11151115
"""
1116-
nv.validate_repeat(tuple(), dict(axis=axis))
1116+
nv.validate_repeat(tuple(), {"axis": axis})
11171117
new_index = self.index.repeat(repeats)
11181118
new_values = self._values.repeat(repeats)
11191119
return self._constructor(new_values, index=new_index).__finalize__(

0 commit comments

Comments
 (0)