6
6
import operator
7
7
import pickle
8
8
import re
9
- from textwrap import dedent
10
9
from typing import (
11
10
TYPE_CHECKING ,
12
11
Any ,
101
100
from pandas .core .missing import find_valid_index
102
101
from pandas .core .ops import _align_method_FRAME
103
102
from pandas .core .shared_docs import _shared_docs
103
+ from pandas .core .window import Expanding , ExponentialMovingWindow , Rolling , Window
104
104
105
105
from pandas .io .formats import format as fmt
106
106
from pandas .io .formats .format import DataFrameFormatter , format_percentiles
107
107
from pandas .io .formats .printing import pprint_thing
108
108
109
109
if TYPE_CHECKING :
110
+ from pandas ._libs .tslibs import BaseOffset
111
+
110
112
from pandas .core .resample import Resampler
111
113
from pandas .core .series import Series # noqa: F401
114
+ from pandas .core .window .indexers import BaseIndexer
112
115
113
116
# goal is to be able to define the docs close to function, while still being
114
117
# able to share
118
+ _shared_docs = {** _shared_docs }
115
119
_shared_doc_kwargs = dict (
116
120
axes = "keywords for axes" ,
117
121
klass = "Series/DataFrame" ,
@@ -5128,51 +5132,6 @@ def pipe(self, func, *args, **kwargs):
5128
5132
"""
5129
5133
return com .pipe (self , func , * args , ** kwargs )
5130
5134
5131
- _shared_docs ["aggregate" ] = dedent (
5132
- """
5133
- Aggregate using one or more operations over the specified axis.
5134
- {versionadded}
5135
- Parameters
5136
- ----------
5137
- func : function, str, list or dict
5138
- Function to use for aggregating the data. If a function, must either
5139
- work when passed a {klass} or when passed to {klass}.apply.
5140
-
5141
- Accepted combinations are:
5142
-
5143
- - function
5144
- - string function name
5145
- - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
5146
- - dict of axis labels -> functions, function names or list of such.
5147
- {axis}
5148
- *args
5149
- Positional arguments to pass to `func`.
5150
- **kwargs
5151
- Keyword arguments to pass to `func`.
5152
-
5153
- Returns
5154
- -------
5155
- scalar, Series or DataFrame
5156
-
5157
- The return can be:
5158
-
5159
- * scalar : when Series.agg is called with single function
5160
- * Series : when DataFrame.agg is called with a single function
5161
- * DataFrame : when DataFrame.agg is called with several functions
5162
-
5163
- Return scalar, Series or DataFrame.
5164
- {see_also}
5165
- Notes
5166
- -----
5167
- `agg` is an alias for `aggregate`. Use the alias.
5168
-
5169
- In pandas, agg, as most operations just ignores the missing values,
5170
- and returns the operation only considering the values that are present.
5171
-
5172
- A passed user-defined-function will be passed a Series for evaluation.
5173
- {examples}"""
5174
- )
5175
-
5176
5135
# ----------------------------------------------------------------------
5177
5136
# Attribute access
5178
5137
@@ -7452,77 +7411,6 @@ def clip(
7452
7411
7453
7412
return result
7454
7413
7455
- _shared_docs [
7456
- "groupby"
7457
- ] = """
7458
- Group %(klass)s using a mapper or by a Series of columns.
7459
-
7460
- A groupby operation involves some combination of splitting the
7461
- object, applying a function, and combining the results. This can be
7462
- used to group large amounts of data and compute operations on these
7463
- groups.
7464
-
7465
- Parameters
7466
- ----------
7467
- by : mapping, function, label, or list of labels
7468
- Used to determine the groups for the groupby.
7469
- If ``by`` is a function, it's called on each value of the object's
7470
- index. If a dict or Series is passed, the Series or dict VALUES
7471
- will be used to determine the groups (the Series' values are first
7472
- aligned; see ``.align()`` method). If an ndarray is passed, the
7473
- values are used as-is determine the groups. A label or list of
7474
- labels may be passed to group by the columns in ``self``. Notice
7475
- that a tuple is interpreted as a (single) key.
7476
- axis : {0 or 'index', 1 or 'columns'}, default 0
7477
- Split along rows (0) or columns (1).
7478
- level : int, level name, or sequence of such, default None
7479
- If the axis is a MultiIndex (hierarchical), group by a particular
7480
- level or levels.
7481
- as_index : bool, default True
7482
- For aggregated output, return object with group labels as the
7483
- index. Only relevant for DataFrame input. as_index=False is
7484
- effectively "SQL-style" grouped output.
7485
- sort : bool, default True
7486
- Sort group keys. Get better performance by turning this off.
7487
- Note this does not influence the order of observations within each
7488
- group. Groupby preserves the order of rows within each group.
7489
- group_keys : bool, default True
7490
- When calling apply, add group keys to index to identify pieces.
7491
- squeeze : bool, default False
7492
- Reduce the dimensionality of the return type if possible,
7493
- otherwise return a consistent type.
7494
-
7495
- .. deprecated:: 1.1.0
7496
-
7497
- observed : bool, default False
7498
- This only applies if any of the groupers are Categoricals.
7499
- If True: only show observed values for categorical groupers.
7500
- If False: show all values for categorical groupers.
7501
-
7502
- .. versionadded:: 0.23.0
7503
- dropna : bool, default True
7504
- If True, and if group keys contain NA values, NA values together
7505
- with row/column will be dropped.
7506
- If False, NA values will also be treated as the key in groups
7507
-
7508
- .. versionadded:: 1.1.0
7509
-
7510
- Returns
7511
- -------
7512
- %(klass)sGroupBy
7513
- Returns a groupby object that contains information about the groups.
7514
-
7515
- See Also
7516
- --------
7517
- resample : Convenience method for frequency conversion and resampling
7518
- of time series.
7519
-
7520
- Notes
7521
- -----
7522
- See the `user guide
7523
- <https://pandas.pydata.org/pandas-docs/stable/groupby.html>`_ for more.
7524
- """
7525
-
7526
7414
def asfreq (
7527
7415
self : FrameOrSeries ,
7528
7416
freq ,
@@ -8431,35 +8319,6 @@ def ranker(data):
8431
8319
8432
8320
return ranker (data )
8433
8321
8434
- _shared_docs [
8435
- "compare"
8436
- ] = """
8437
- Compare to another %(klass)s and show the differences.
8438
-
8439
- .. versionadded:: 1.1.0
8440
-
8441
- Parameters
8442
- ----------
8443
- other : %(klass)s
8444
- Object to compare with.
8445
-
8446
- align_axis : {0 or 'index', 1 or 'columns'}, default 1
8447
- Determine which axis to align the comparison on.
8448
-
8449
- * 0, or 'index' : Resulting differences are stacked vertically
8450
- with rows drawn alternately from self and other.
8451
- * 1, or 'columns' : Resulting differences are aligned horizontally
8452
- with columns drawn alternately from self and other.
8453
-
8454
- keep_shape : bool, default False
8455
- If true, all rows and columns are kept.
8456
- Otherwise, only the ones with different values are kept.
8457
-
8458
- keep_equal : bool, default False
8459
- If true, the result keeps values that are equal.
8460
- Otherwise, equal values are shown as NaNs.
8461
- """
8462
-
8463
8322
@Appender (_shared_docs ["compare" ] % _shared_doc_kwargs )
8464
8323
def compare (
8465
8324
self ,
@@ -10589,45 +10448,21 @@ def mad(self, axis=None, skipna=None, level=None):
10589
10448
examples = _min_examples ,
10590
10449
)
10591
10450
10592
- @classmethod
10593
- def _add_series_or_dataframe_operations (cls ):
10594
- """
10595
- Add the series or dataframe only operations to the cls; evaluate
10596
- the doc strings again.
10597
- """
10598
- from pandas .core .window import (
10599
- Expanding ,
10600
- ExponentialMovingWindow ,
10601
- Rolling ,
10602
- Window ,
10603
- )
10604
-
10605
- @doc (Rolling )
10606
- def rolling (
10607
- self ,
10608
- window ,
10609
- min_periods = None ,
10610
- center = False ,
10611
- win_type = None ,
10612
- on = None ,
10613
- axis = 0 ,
10614
- closed = None ,
10615
- ):
10616
- axis = self ._get_axis_number (axis )
10617
-
10618
- if win_type is not None :
10619
- return Window (
10620
- self ,
10621
- window = window ,
10622
- min_periods = min_periods ,
10623
- center = center ,
10624
- win_type = win_type ,
10625
- on = on ,
10626
- axis = axis ,
10627
- closed = closed ,
10628
- )
10451
+ @doc (Rolling )
10452
+ def rolling (
10453
+ self ,
10454
+ window : "Union[int, timedelta, BaseOffset, BaseIndexer]" ,
10455
+ min_periods : Optional [int ] = None ,
10456
+ center : bool_t = False ,
10457
+ win_type : Optional [str ] = None ,
10458
+ on : Optional [str ] = None ,
10459
+ axis : Axis = 0 ,
10460
+ closed : Optional [str ] = None ,
10461
+ ):
10462
+ axis = self ._get_axis_number (axis )
10629
10463
10630
- return Rolling (
10464
+ if win_type is not None :
10465
+ return Window (
10631
10466
self ,
10632
10467
window = window ,
10633
10468
min_periods = min_periods ,
@@ -10638,53 +10473,59 @@ def rolling(
10638
10473
closed = closed ,
10639
10474
)
10640
10475
10641
- cls .rolling = rolling
10642
-
10643
- @doc (Expanding )
10644
- def expanding (self , min_periods = 1 , center = None , axis = 0 ):
10645
- axis = self ._get_axis_number (axis )
10646
- if center is not None :
10647
- warnings .warn (
10648
- "The `center` argument on `expanding` "
10649
- "will be removed in the future" ,
10650
- FutureWarning ,
10651
- stacklevel = 2 ,
10652
- )
10653
- else :
10654
- center = False
10476
+ return Rolling (
10477
+ self ,
10478
+ window = window ,
10479
+ min_periods = min_periods ,
10480
+ center = center ,
10481
+ win_type = win_type ,
10482
+ on = on ,
10483
+ axis = axis ,
10484
+ closed = closed ,
10485
+ )
10655
10486
10656
- return Expanding (self , min_periods = min_periods , center = center , axis = axis )
10487
+ @doc (Expanding )
10488
+ def expanding (
10489
+ self , min_periods : int = 1 , center : Optional [bool_t ] = None , axis : Axis = 0
10490
+ ) -> Expanding :
10491
+ axis = self ._get_axis_number (axis )
10492
+ if center is not None :
10493
+ warnings .warn (
10494
+ "The `center` argument on `expanding` will be removed in the future" ,
10495
+ FutureWarning ,
10496
+ stacklevel = 2 ,
10497
+ )
10498
+ else :
10499
+ center = False
10657
10500
10658
- cls . expanding = expanding
10501
+ return Expanding ( self , min_periods = min_periods , center = center , axis = axis )
10659
10502
10660
- @doc (ExponentialMovingWindow )
10661
- def ewm (
10503
+ @doc (ExponentialMovingWindow )
10504
+ def ewm (
10505
+ self ,
10506
+ com : Optional [float ] = None ,
10507
+ span : Optional [float ] = None ,
10508
+ halflife : Optional [Union [float , TimedeltaConvertibleTypes ]] = None ,
10509
+ alpha : Optional [float ] = None ,
10510
+ min_periods : int = 0 ,
10511
+ adjust : bool_t = True ,
10512
+ ignore_na : bool_t = False ,
10513
+ axis : Axis = 0 ,
10514
+ times : Optional [Union [str , np .ndarray , FrameOrSeries ]] = None ,
10515
+ ) -> ExponentialMovingWindow :
10516
+ axis = self ._get_axis_number (axis )
10517
+ return ExponentialMovingWindow (
10662
10518
self ,
10663
- com = None ,
10664
- span = None ,
10665
- halflife = None ,
10666
- alpha = None ,
10667
- min_periods = 0 ,
10668
- adjust = True ,
10669
- ignore_na = False ,
10670
- axis = 0 ,
10671
- times = None ,
10672
- ):
10673
- axis = self ._get_axis_number (axis )
10674
- return ExponentialMovingWindow (
10675
- self ,
10676
- com = com ,
10677
- span = span ,
10678
- halflife = halflife ,
10679
- alpha = alpha ,
10680
- min_periods = min_periods ,
10681
- adjust = adjust ,
10682
- ignore_na = ignore_na ,
10683
- axis = axis ,
10684
- times = times ,
10685
- )
10686
-
10687
- cls .ewm = ewm
10519
+ com = com ,
10520
+ span = span ,
10521
+ halflife = halflife ,
10522
+ alpha = alpha ,
10523
+ min_periods = min_periods ,
10524
+ adjust = adjust ,
10525
+ ignore_na = ignore_na ,
10526
+ axis = axis ,
10527
+ times = times ,
10528
+ )
10688
10529
10689
10530
@doc (klass = _shared_doc_kwargs ["klass" ], axis = "" )
10690
10531
def transform (self , func , * args , ** kwargs ):
0 commit comments