@@ -6162,12 +6162,20 @@ def bfill(
6162
6162
method = "bfill" , axis = axis , inplace = inplace , limit = limit , downcast = downcast
6163
6163
)
6164
6164
6165
- _shared_docs [
6166
- "replace"
6167
- ] = """
6165
+ @doc (klass = _shared_doc_kwargs ["klass" ])
6166
+ def replace (
6167
+ self ,
6168
+ to_replace = None ,
6169
+ value = None ,
6170
+ inplace = False ,
6171
+ limit = None ,
6172
+ regex = False ,
6173
+ method = "pad" ,
6174
+ ):
6175
+ """
6168
6176
Replace values given in `to_replace` with `value`.
6169
6177
6170
- Values of the %( klass)s are replaced with other values dynamically.
6178
+ Values of the { klass} are replaced with other values dynamically.
6171
6179
This differs from updating with ``.loc`` or ``.iloc``, which require
6172
6180
you to specify a location to update with some value.
6173
6181
@@ -6199,19 +6207,19 @@ def bfill(
6199
6207
6200
6208
- Dicts can be used to specify different replacement values
6201
6209
for different existing values. For example,
6202
- ``{'a': 'b', 'y': 'z'}`` replaces the value 'a' with 'b' and
6210
+ ``{{ 'a': 'b', 'y': 'z'} }`` replaces the value 'a' with 'b' and
6203
6211
'y' with 'z'. To use a dict in this way the `value`
6204
6212
parameter should be `None`.
6205
6213
- For a DataFrame a dict can specify that different values
6206
6214
should be replaced in different columns. For example,
6207
- ``{'a': 1, 'b': 'z'}`` looks for the value 1 in column 'a'
6215
+ ``{{ 'a': 1, 'b': 'z'} }`` looks for the value 1 in column 'a'
6208
6216
and the value 'z' in column 'b' and replaces these values
6209
6217
with whatever is specified in `value`. The `value` parameter
6210
6218
should not be ``None`` in this case. You can treat this as a
6211
6219
special case of passing two lists except that you are
6212
6220
specifying the column to search in.
6213
6221
- For a DataFrame nested dictionaries, e.g.,
6214
- ``{'a': {'b': np.nan}}``, are read as follows: look in column
6222
+ ``{{ 'a': {{ 'b': np.nan}} }}``, are read as follows: look in column
6215
6223
'a' for the value 'b' and replace it with NaN. The `value`
6216
6224
parameter should be ``None`` to use a nested dict in this
6217
6225
way. You can nest regular expressions as well. Note that
@@ -6244,7 +6252,7 @@ def bfill(
6244
6252
string. Alternatively, this could be a regular expression or a
6245
6253
list, dict, or array of regular expressions in which case
6246
6254
`to_replace` must be ``None``.
6247
- method : {'pad', 'ffill', 'bfill', `None`}
6255
+ method : {{ 'pad', 'ffill', 'bfill', `None`} }
6248
6256
The method to use when for replacement, when `to_replace` is a
6249
6257
scalar, list or tuple and `value` is ``None``.
6250
6258
@@ -6253,7 +6261,7 @@ def bfill(
6253
6261
6254
6262
Returns
6255
6263
-------
6256
- %( klass)s
6264
+ { klass}
6257
6265
Object after replacement.
6258
6266
6259
6267
Raises
@@ -6279,8 +6287,8 @@ def bfill(
6279
6287
6280
6288
See Also
6281
6289
--------
6282
- %( klass)s .fillna : Fill NA values.
6283
- %( klass)s .where : Replace values based on boolean condition.
6290
+ { klass} .fillna : Fill NA values.
6291
+ { klass} .where : Replace values based on boolean condition.
6284
6292
Series.str.replace : Simple string replacement.
6285
6293
6286
6294
Notes
@@ -6312,9 +6320,9 @@ def bfill(
6312
6320
4 4
6313
6321
dtype: int64
6314
6322
6315
- >>> df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
6323
+ >>> df = pd.DataFrame({{ 'A': [0, 1, 2, 3, 4],
6316
6324
... 'B': [5, 6, 7, 8, 9],
6317
- ... 'C': ['a', 'b', 'c', 'd', 'e']})
6325
+ ... 'C': ['a', 'b', 'c', 'd', 'e']}} )
6318
6326
>>> df.replace(0, 5)
6319
6327
A B C
6320
6328
0 5 5 a
@@ -6351,23 +6359,23 @@ def bfill(
6351
6359
6352
6360
**dict-like `to_replace`**
6353
6361
6354
- >>> df.replace({0: 10, 1: 100})
6362
+ >>> df.replace({{ 0: 10, 1: 100} })
6355
6363
A B C
6356
6364
0 10 5 a
6357
6365
1 100 6 b
6358
6366
2 2 7 c
6359
6367
3 3 8 d
6360
6368
4 4 9 e
6361
6369
6362
- >>> df.replace({'A': 0, 'B': 5}, 100)
6370
+ >>> df.replace({{ 'A': 0, 'B': 5} }, 100)
6363
6371
A B C
6364
6372
0 100 100 a
6365
6373
1 1 6 b
6366
6374
2 2 7 c
6367
6375
3 3 8 d
6368
6376
4 4 9 e
6369
6377
6370
- >>> df.replace({'A': {0: 100, 4: 400}})
6378
+ >>> df.replace({{ 'A': {{ 0: 100, 4: 400}} }})
6371
6379
A B C
6372
6380
0 100 5 a
6373
6381
1 1 6 b
@@ -6377,15 +6385,15 @@ def bfill(
6377
6385
6378
6386
**Regular expression `to_replace`**
6379
6387
6380
- >>> df = pd.DataFrame({'A': ['bat', 'foo', 'bait'],
6381
- ... 'B': ['abc', 'bar', 'xyz']})
6388
+ >>> df = pd.DataFrame({{ 'A': ['bat', 'foo', 'bait'],
6389
+ ... 'B': ['abc', 'bar', 'xyz']}} )
6382
6390
>>> df.replace(to_replace=r'^ba.$', value='new', regex=True)
6383
6391
A B
6384
6392
0 new abc
6385
6393
1 foo new
6386
6394
2 bait xyz
6387
6395
6388
- >>> df.replace({'A': r'^ba.$'}, {'A': 'new'}, regex=True)
6396
+ >>> df.replace({{ 'A': r'^ba.$'}} , {{ 'A': 'new'} }, regex=True)
6389
6397
A B
6390
6398
0 new abc
6391
6399
1 foo bar
@@ -6397,7 +6405,7 @@ def bfill(
6397
6405
1 foo new
6398
6406
2 bait xyz
6399
6407
6400
- >>> df.replace(regex={r'^ba.$': 'new', 'foo': 'xyz'})
6408
+ >>> df.replace(regex={{ r'^ba.$': 'new', 'foo': 'xyz'} })
6401
6409
A B
6402
6410
0 new abc
6403
6411
1 xyz new
@@ -6413,28 +6421,28 @@ def bfill(
6413
6421
the data types in the `to_replace` parameter must match the data
6414
6422
type of the value being replaced:
6415
6423
6416
- >>> df = pd.DataFrame({'A': [True, False, True],
6417
- ... 'B': [False, True, False]})
6418
- >>> df.replace({'a string': 'new value', True: False}) # raises
6424
+ >>> df = pd.DataFrame({{ 'A': [True, False, True],
6425
+ ... 'B': [False, True, False]}} )
6426
+ >>> df.replace({{ 'a string': 'new value', True: False} }) # raises
6419
6427
Traceback (most recent call last):
6420
6428
...
6421
6429
TypeError: Cannot compare types 'ndarray(dtype=bool)' and 'str'
6422
6430
6423
6431
This raises a ``TypeError`` because one of the ``dict`` keys is not of
6424
6432
the correct type for replacement.
6425
6433
6426
- Compare the behavior of ``s.replace({'a': None})`` and
6434
+ Compare the behavior of ``s.replace({{ 'a': None} })`` and
6427
6435
``s.replace('a', None)`` to understand the peculiarities
6428
6436
of the `to_replace` parameter:
6429
6437
6430
6438
>>> s = pd.Series([10, 'a', 'a', 'b', 'a'])
6431
6439
6432
6440
When one uses a dict as the `to_replace` value, it is like the
6433
6441
value(s) in the dict are equal to the `value` parameter.
6434
- ``s.replace({'a': None})`` is equivalent to
6435
- ``s.replace(to_replace={'a': None}, value=None, method=None)``:
6442
+ ``s.replace({{ 'a': None} })`` is equivalent to
6443
+ ``s.replace(to_replace={{ 'a': None} }, value=None, method=None)``:
6436
6444
6437
- >>> s.replace({'a': None})
6445
+ >>> s.replace({{ 'a': None} })
6438
6446
0 10
6439
6447
1 None
6440
6448
2 None
@@ -6457,17 +6465,6 @@ def bfill(
6457
6465
4 b
6458
6466
dtype: object
6459
6467
"""
6460
-
6461
- @Appender (_shared_docs ["replace" ] % _shared_doc_kwargs )
6462
- def replace (
6463
- self ,
6464
- to_replace = None ,
6465
- value = None ,
6466
- inplace = False ,
6467
- limit = None ,
6468
- regex = False ,
6469
- method = "pad" ,
6470
- ):
6471
6468
if not (
6472
6469
is_scalar (to_replace )
6473
6470
or is_re_compilable (to_replace )
@@ -8246,17 +8243,29 @@ def ranker(data):
8246
8243
8247
8244
return ranker (data )
8248
8245
8249
- _shared_docs [
8250
- "align"
8251
- ] = """
8246
+ @doc (** _shared_doc_kwargs )
8247
+ def align (
8248
+ self ,
8249
+ other ,
8250
+ join = "outer" ,
8251
+ axis = None ,
8252
+ level = None ,
8253
+ copy = True ,
8254
+ fill_value = None ,
8255
+ method = None ,
8256
+ limit = None ,
8257
+ fill_axis = 0 ,
8258
+ broadcast_axis = None ,
8259
+ ):
8260
+ """
8252
8261
Align two objects on their axes with the specified join method.
8253
8262
8254
8263
Join method is specified for each axis Index.
8255
8264
8256
8265
Parameters
8257
8266
----------
8258
8267
other : DataFrame or Series
8259
- join : {'outer', 'inner', 'left', 'right'}, default 'outer'
8268
+ join : {{ 'outer', 'inner', 'left', 'right'} }, default 'outer'
8260
8269
axis : allowed axis of the other object, default None
8261
8270
Align on index (0), columns (1), or both (None).
8262
8271
level : int or level name, default None
@@ -8268,7 +8277,7 @@ def ranker(data):
8268
8277
fill_value : scalar, default np.NaN
8269
8278
Value to use for missing values. Defaults to NaN, but can be any
8270
8279
"compatible" value.
8271
- method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None
8280
+ method : {{ 'backfill', 'bfill', 'pad', 'ffill', None} }, default None
8272
8281
Method to use for filling holes in reindexed Series:
8273
8282
8274
8283
- pad / ffill: propagate last valid observation forward to next valid.
@@ -8281,32 +8290,18 @@ def ranker(data):
8281
8290
be partially filled. If method is not specified, this is the
8282
8291
maximum number of entries along the entire axis where NaNs will be
8283
8292
filled. Must be greater than 0 if not None.
8284
- fill_axis : %( axes_single_arg)s , default 0
8293
+ fill_axis : { axes_single_arg} , default 0
8285
8294
Filling axis, method and limit.
8286
- broadcast_axis : %( axes_single_arg)s , default None
8295
+ broadcast_axis : { axes_single_arg} , default None
8287
8296
Broadcast values along this axis, if aligning two objects of
8288
8297
different dimensions.
8289
8298
8290
8299
Returns
8291
8300
-------
8292
- (left, right) : (%( klass)s , type of other)
8301
+ (left, right) : ({ klass} , type of other)
8293
8302
Aligned objects.
8294
8303
"""
8295
8304
8296
- @Appender (_shared_docs ["align" ] % _shared_doc_kwargs )
8297
- def align (
8298
- self ,
8299
- other ,
8300
- join = "outer" ,
8301
- axis = None ,
8302
- level = None ,
8303
- copy = True ,
8304
- fill_value = None ,
8305
- method = None ,
8306
- limit = None ,
8307
- fill_axis = 0 ,
8308
- broadcast_axis = None ,
8309
- ):
8310
8305
method = missing .clean_fill_method (method )
8311
8306
8312
8307
if broadcast_axis == 1 and self .ndim != other .ndim :
@@ -8850,9 +8845,11 @@ def mask(
8850
8845
errors = errors ,
8851
8846
)
8852
8847
8853
- _shared_docs [
8854
- "shift"
8855
- ] = """
8848
+ @doc (klass = _shared_doc_kwargs ["klass" ])
8849
+ def shift (
8850
+ self : FrameOrSeries , periods = 1 , freq = None , axis = 0 , fill_value = None
8851
+ ) -> FrameOrSeries :
8852
+ """
8856
8853
Shift index by desired number of periods with an optional time `freq`.
8857
8854
8858
8855
When `freq` is not passed, shift the index without realigning the data.
@@ -8869,7 +8866,7 @@ def mask(
8869
8866
If `freq` is specified then the index values are shifted but the
8870
8867
data is not realigned. That is, use `freq` if you would like to
8871
8868
extend the index when shifting and preserve the original data.
8872
- axis : {0 or 'index', 1 or 'columns', None}, default None
8869
+ axis : {{ 0 or 'index', 1 or 'columns', None} }, default None
8873
8870
Shift direction.
8874
8871
fill_value : object, optional
8875
8872
The scalar value to use for newly introduced missing values.
@@ -8882,7 +8879,7 @@ def mask(
8882
8879
8883
8880
Returns
8884
8881
-------
8885
- %( klass)s
8882
+ { klass}
8886
8883
Copy of input object, shifted.
8887
8884
8888
8885
See Also
@@ -8895,9 +8892,9 @@ def mask(
8895
8892
8896
8893
Examples
8897
8894
--------
8898
- >>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
8895
+ >>> df = pd.DataFrame({{ 'Col1': [10, 20, 15, 30, 45],
8899
8896
... 'Col2': [13, 23, 18, 33, 48],
8900
- ... 'Col3': [17, 27, 22, 37, 52]})
8897
+ ... 'Col3': [17, 27, 22, 37, 52]}} )
8901
8898
8902
8899
>>> df.shift(periods=3)
8903
8900
Col1 Col2 Col3
@@ -8922,12 +8919,7 @@ def mask(
8922
8919
2 0 0 0
8923
8920
3 10 13 17
8924
8921
4 20 23 27
8925
- """
8926
-
8927
- @Appender (_shared_docs ["shift" ] % _shared_doc_kwargs )
8928
- def shift (
8929
- self : FrameOrSeries , periods = 1 , freq = None , axis = 0 , fill_value = None
8930
- ) -> FrameOrSeries :
8922
+ """
8931
8923
if periods == 0 :
8932
8924
return self .copy ()
8933
8925
0 commit comments