Skip to content

Commit 8bfc26d

Browse files
committed
reintroduced changes lost in rebase
1 parent 0046b5b commit 8bfc26d

File tree

1 file changed

+61
-69
lines changed

1 file changed

+61
-69
lines changed

pandas/core/generic.py

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6155,12 +6155,20 @@ def bfill(
61556155
method="bfill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
61566156
)
61576157

6158-
_shared_docs[
6159-
"replace"
6160-
] = """
6158+
@doc(klass=_shared_doc_kwargs["klass"])
6159+
def replace(
6160+
self,
6161+
to_replace=None,
6162+
value=None,
6163+
inplace=False,
6164+
limit=None,
6165+
regex=False,
6166+
method="pad",
6167+
):
6168+
"""
61616169
Replace values given in `to_replace` with `value`.
61626170
6163-
Values of the %(klass)s are replaced with other values dynamically.
6171+
Values of the {klass} are replaced with other values dynamically.
61646172
This differs from updating with ``.loc`` or ``.iloc``, which require
61656173
you to specify a location to update with some value.
61666174
@@ -6192,19 +6200,19 @@ def bfill(
61926200
61936201
- Dicts can be used to specify different replacement values
61946202
for different existing values. For example,
6195-
``{'a': 'b', 'y': 'z'}`` replaces the value 'a' with 'b' and
6203+
``{{'a': 'b', 'y': 'z'}}`` replaces the value 'a' with 'b' and
61966204
'y' with 'z'. To use a dict in this way the `value`
61976205
parameter should be `None`.
61986206
- For a DataFrame a dict can specify that different values
61996207
should be replaced in different columns. For example,
6200-
``{'a': 1, 'b': 'z'}`` looks for the value 1 in column 'a'
6208+
``{{'a': 1, 'b': 'z'}}`` looks for the value 1 in column 'a'
62016209
and the value 'z' in column 'b' and replaces these values
62026210
with whatever is specified in `value`. The `value` parameter
62036211
should not be ``None`` in this case. You can treat this as a
62046212
special case of passing two lists except that you are
62056213
specifying the column to search in.
62066214
- For a DataFrame nested dictionaries, e.g.,
6207-
``{'a': {'b': np.nan}}``, are read as follows: look in column
6215+
``{{'a': {{'b': np.nan}}}}``, are read as follows: look in column
62086216
'a' for the value 'b' and replace it with NaN. The `value`
62096217
parameter should be ``None`` to use a nested dict in this
62106218
way. You can nest regular expressions as well. Note that
@@ -6237,7 +6245,7 @@ def bfill(
62376245
string. Alternatively, this could be a regular expression or a
62386246
list, dict, or array of regular expressions in which case
62396247
`to_replace` must be ``None``.
6240-
method : {'pad', 'ffill', 'bfill', `None`}
6248+
method : {{'pad', 'ffill', 'bfill', `None`}}
62416249
The method to use when for replacement, when `to_replace` is a
62426250
scalar, list or tuple and `value` is ``None``.
62436251
@@ -6246,7 +6254,7 @@ def bfill(
62466254
62476255
Returns
62486256
-------
6249-
%(klass)s
6257+
{klass}
62506258
Object after replacement.
62516259
62526260
Raises
@@ -6272,8 +6280,8 @@ def bfill(
62726280
62736281
See Also
62746282
--------
6275-
%(klass)s.fillna : Fill NA values.
6276-
%(klass)s.where : Replace values based on boolean condition.
6283+
{klass}.fillna : Fill NA values.
6284+
{klass}.where : Replace values based on boolean condition.
62776285
Series.str.replace : Simple string replacement.
62786286
62796287
Notes
@@ -6305,9 +6313,9 @@ def bfill(
63056313
4 4
63066314
dtype: int64
63076315
6308-
>>> df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
6316+
>>> df = pd.DataFrame({{'A': [0, 1, 2, 3, 4],
63096317
... 'B': [5, 6, 7, 8, 9],
6310-
... 'C': ['a', 'b', 'c', 'd', 'e']})
6318+
... 'C': ['a', 'b', 'c', 'd', 'e']}})
63116319
>>> df.replace(0, 5)
63126320
A B C
63136321
0 5 5 a
@@ -6344,23 +6352,23 @@ def bfill(
63446352
63456353
**dict-like `to_replace`**
63466354
6347-
>>> df.replace({0: 10, 1: 100})
6355+
>>> df.replace({{0: 10, 1: 100}})
63486356
A B C
63496357
0 10 5 a
63506358
1 100 6 b
63516359
2 2 7 c
63526360
3 3 8 d
63536361
4 4 9 e
63546362
6355-
>>> df.replace({'A': 0, 'B': 5}, 100)
6363+
>>> df.replace({{'A': 0, 'B': 5}}, 100)
63566364
A B C
63576365
0 100 100 a
63586366
1 1 6 b
63596367
2 2 7 c
63606368
3 3 8 d
63616369
4 4 9 e
63626370
6363-
>>> df.replace({'A': {0: 100, 4: 400}})
6371+
>>> df.replace({{'A': {{0: 100, 4: 400}}}})
63646372
A B C
63656373
0 100 5 a
63666374
1 1 6 b
@@ -6370,15 +6378,15 @@ def bfill(
63706378
63716379
**Regular expression `to_replace`**
63726380
6373-
>>> df = pd.DataFrame({'A': ['bat', 'foo', 'bait'],
6374-
... 'B': ['abc', 'bar', 'xyz']})
6381+
>>> df = pd.DataFrame({{'A': ['bat', 'foo', 'bait'],
6382+
... 'B': ['abc', 'bar', 'xyz']}})
63756383
>>> df.replace(to_replace=r'^ba.$', value='new', regex=True)
63766384
A B
63776385
0 new abc
63786386
1 foo new
63796387
2 bait xyz
63806388
6381-
>>> df.replace({'A': r'^ba.$'}, {'A': 'new'}, regex=True)
6389+
>>> df.replace({{'A': r'^ba.$'}}, {{'A': 'new'}}, regex=True)
63826390
A B
63836391
0 new abc
63846392
1 foo bar
@@ -6390,7 +6398,7 @@ def bfill(
63906398
1 foo new
63916399
2 bait xyz
63926400
6393-
>>> df.replace(regex={r'^ba.$': 'new', 'foo': 'xyz'})
6401+
>>> df.replace(regex={{r'^ba.$': 'new', 'foo': 'xyz'}})
63946402
A B
63956403
0 new abc
63966404
1 xyz new
@@ -6406,9 +6414,9 @@ def bfill(
64066414
the data types in the `to_replace` parameter must match the data
64076415
type of the value being replaced:
64086416
6409-
>>> df = pd.DataFrame({'A': [True, False, True],
6410-
... 'B': [False, True, False]})
6411-
>>> df.replace({'a string': 'new value', True: False}) # raises
6417+
>>> df = pd.DataFrame({{'A': [True, False, True],
6418+
... 'B': [False, True, False]}})
6419+
>>> df.replace({{'a string': 'new value', True: False}}) # raises
64126420
Traceback (most recent call last):
64136421
...
64146422
TypeError: Cannot compare types 'ndarray(dtype=bool)' and 'str'
@@ -6427,7 +6435,7 @@ def bfill(
64276435
``s.replace({'a': None})`` is equivalent to
64286436
``s.replace(to_replace={'a': None}, value=None, method=None)``:
64296437
6430-
>>> s.replace({'a': None})
6438+
>>> s.replace({{'a': None}})
64316439
0 10
64326440
1 None
64336441
2 None
@@ -6450,17 +6458,6 @@ def bfill(
64506458
4 b
64516459
dtype: object
64526460
"""
6453-
6454-
@Appender(_shared_docs["replace"] % _shared_doc_kwargs)
6455-
def replace(
6456-
self,
6457-
to_replace=None,
6458-
value=None,
6459-
inplace=False,
6460-
limit=None,
6461-
regex=False,
6462-
method="pad",
6463-
):
64646461
if not (
64656462
is_scalar(to_replace)
64666463
or isinstance(to_replace, pd.Series)
@@ -8239,17 +8236,29 @@ def ranker(data):
82398236

82408237
return ranker(data)
82418238

8242-
_shared_docs[
8243-
"align"
8244-
] = """
8239+
@doc(**_shared_doc_kwargs)
8240+
def align(
8241+
self,
8242+
other,
8243+
join="outer",
8244+
axis=None,
8245+
level=None,
8246+
copy=True,
8247+
fill_value=None,
8248+
method=None,
8249+
limit=None,
8250+
fill_axis=0,
8251+
broadcast_axis=None,
8252+
):
8253+
"""
82458254
Align two objects on their axes with the specified join method.
82468255
82478256
Join method is specified for each axis Index.
82488257
82498258
Parameters
82508259
----------
82518260
other : DataFrame or Series
8252-
join : {'outer', 'inner', 'left', 'right'}, default 'outer'
8261+
join : {{'outer', 'inner', 'left', 'right'}}, default 'outer'
82538262
axis : allowed axis of the other object, default None
82548263
Align on index (0), columns (1), or both (None).
82558264
level : int or level name, default None
@@ -8261,7 +8270,7 @@ def ranker(data):
82618270
fill_value : scalar, default np.NaN
82628271
Value to use for missing values. Defaults to NaN, but can be any
82638272
"compatible" value.
8264-
method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None
8273+
method : {{'backfill', 'bfill', 'pad', 'ffill', None}}, default None
82658274
Method to use for filling holes in reindexed Series:
82668275
82678276
- pad / ffill: propagate last valid observation forward to next valid.
@@ -8274,32 +8283,18 @@ def ranker(data):
82748283
be partially filled. If method is not specified, this is the
82758284
maximum number of entries along the entire axis where NaNs will be
82768285
filled. Must be greater than 0 if not None.
8277-
fill_axis : %(axes_single_arg)s, default 0
8286+
fill_axis : {axes_single_arg}, default 0
82788287
Filling axis, method and limit.
8279-
broadcast_axis : %(axes_single_arg)s, default None
8288+
broadcast_axis : {axes_single_arg}, default None
82808289
Broadcast values along this axis, if aligning two objects of
82818290
different dimensions.
82828291
82838292
Returns
82848293
-------
8285-
(left, right) : (%(klass)s, type of other)
8294+
(left, right) : ({klass}, type of other)
82868295
Aligned objects.
82878296
"""
82888297

8289-
@Appender(_shared_docs["align"] % _shared_doc_kwargs)
8290-
def align(
8291-
self,
8292-
other,
8293-
join="outer",
8294-
axis=None,
8295-
level=None,
8296-
copy=True,
8297-
fill_value=None,
8298-
method=None,
8299-
limit=None,
8300-
fill_axis=0,
8301-
broadcast_axis=None,
8302-
):
83038298
method = missing.clean_fill_method(method)
83048299

83058300
if broadcast_axis == 1 and self.ndim != other.ndim:
@@ -8836,9 +8831,11 @@ def mask(
88368831
errors=errors,
88378832
)
88388833

8839-
_shared_docs[
8840-
"shift"
8841-
] = """
8834+
@doc(klass=_shared_doc_kwargs["klass"])
8835+
def shift(
8836+
self: FrameOrSeries, periods=1, freq=None, axis=0, fill_value=None
8837+
) -> FrameOrSeries:
8838+
"""
88428839
Shift index by desired number of periods with an optional time `freq`.
88438840
88448841
When `freq` is not passed, shift the index without realigning the data.
@@ -8855,7 +8852,7 @@ def mask(
88558852
If `freq` is specified then the index values are shifted but the
88568853
data is not realigned. That is, use `freq` if you would like to
88578854
extend the index when shifting and preserve the original data.
8858-
axis : {0 or 'index', 1 or 'columns', None}, default None
8855+
axis : {{0 or 'index', 1 or 'columns', None}}, default None
88598856
Shift direction.
88608857
fill_value : object, optional
88618858
The scalar value to use for newly introduced missing values.
@@ -8868,7 +8865,7 @@ def mask(
88688865
88698866
Returns
88708867
-------
8871-
%(klass)s
8868+
{klass}
88728869
Copy of input object, shifted.
88738870
88748871
See Also
@@ -8881,9 +8878,9 @@ def mask(
88818878
88828879
Examples
88838880
--------
8884-
>>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
8881+
>>> df = pd.DataFrame({{'Col1': [10, 20, 15, 30, 45],
88858882
... 'Col2': [13, 23, 18, 33, 48],
8886-
... 'Col3': [17, 27, 22, 37, 52]})
8883+
... 'Col3': [17, 27, 22, 37, 52]}})
88878884
88888885
>>> df.shift(periods=3)
88898886
Col1 Col2 Col3
@@ -8909,11 +8906,6 @@ def mask(
89098906
3 10 13 17
89108907
4 20 23 27
89118908
"""
8912-
8913-
@Appender(_shared_docs["shift"] % _shared_doc_kwargs)
8914-
def shift(
8915-
self: FrameOrSeries, periods=1, freq=None, axis=0, fill_value=None
8916-
) -> FrameOrSeries:
89178909
if periods == 0:
89188910
return self.copy()
89198911

0 commit comments

Comments
 (0)