14
14
@pf .register_series_method
15
15
def log (s : pd .Series , error : str = "warn" ) -> pd .Series :
16
16
"""
17
- Take natural logarithm of the Series
17
+ Take natural logarithm of the Series.
18
18
19
- :param s: Input Series
19
+ :param s: Input Series.
20
20
:param error: Determines behavior when taking the log of nonpositive
21
- entries. If " warn" then a RuntimeWarning is thrown. If " raise" ,
22
- then a RuntimeError is thrown. Otherwise, nothing is thrown and
23
- log of nonpositive values is np.nan; defaults to " warn"
21
+ entries. If `' warn'` then a ` RuntimeWarning` is thrown. If `' raise'` ,
22
+ then a ` RuntimeError` is thrown. Otherwise, nothing is thrown and
23
+ log of nonpositive values is ` np.nan` ; defaults to `' warn'`.
24
24
:raises RuntimeError: Raised when there are nonpositive values in the
25
- Series and error="raise"
26
- :return: Transformed Series
27
-
28
- .. # noqa: DAR103 error
25
+ Series and `error='raise'`.
26
+ :return: Transformed Series.
29
27
"""
30
28
s = s .copy ()
31
29
nonpositive = s <= 0
@@ -43,37 +41,46 @@ def log(s: pd.Series, error: str = "warn") -> pd.Series:
43
41
44
42
@pf .register_series_method
45
43
def exp (s : pd .Series ) -> pd .Series :
46
- """Take the exponential transform of the series"""
44
+ """
45
+ Take the exponential transform of the series.
46
+
47
+ :param s: Input Series.
48
+ :return: Transformed Series.
49
+ """
47
50
return np .exp (s )
48
51
49
52
50
53
@pf .register_series_method
51
54
def sigmoid (s : pd .Series ) -> pd .Series :
52
55
"""
53
- Take the sigmoid transform of the series where
56
+ Take the sigmoid transform of the series where:
57
+
58
+ ```python
54
59
sigmoid(x) = 1 / (1 + exp(-x))
60
+ ```
55
61
56
- .. # noqa: DAR101
57
- .. # noqa: DAR201
62
+ :param s: Input Series.
63
+ :return: Transformed Series.
58
64
"""
59
65
return expit (s )
60
66
61
67
62
68
@pf .register_series_method
63
69
def logit (s : pd .Series , error : str = "warn" ) -> pd .Series :
64
70
"""
65
- Take logit transform of the Series
66
- where logit(p) = log(p/(1-p))
67
-
68
- :param s: Input Series
69
- :param error: Determines behavior when s / (1-s) is outside of (0, 1). If
70
- "warn" then a RuntimeWarning is thrown. If "raise", then a RuntimeError
71
- is thrown. Otherwise, nothing is thrown and np.nan is returned
72
- for the problematic entries, defaults to "warn"
73
- :return: Transformed Series
74
- :raises RuntimeError: if `error` is set to `raise``.
75
-
76
- .. # noqa: DAR103 error
71
+ Take logit transform of the Series where:
72
+
73
+ ```python
74
+ logit(p) = log(p/(1-p))
75
+ ```
76
+
77
+ :param s: Input Series.
78
+ :param error: Determines behavior when `s / (1-s)` is outside of `(0, 1)`.
79
+ If `'warn'` then a `RuntimeWarning` is thrown. If `'raise'`, then a
80
+ `RuntimeError` is thrown. Otherwise, nothing is thrown and `np.nan`
81
+ is returned for the problematic entries; defaults to `'warn'`.
82
+ :return: Transformed Series.
83
+ :raises RuntimeError: if `error` is set to `'raise'`.
77
84
"""
78
85
s = s .copy ()
79
86
odds_ratio = s / (1 - s )
@@ -93,25 +100,28 @@ def logit(s: pd.Series, error: str = "warn") -> pd.Series:
93
100
94
101
@pf .register_series_method
95
102
def normal_cdf (s : pd .Series ) -> pd .Series :
96
- """Transforms the Series via the CDF of the Normal distribution"""
103
+ """
104
+ Transforms the Series via the CDF of the Normal distribution.
105
+
106
+ :param s: Input Series.
107
+ :return: Transformed Series.
108
+ """
97
109
return pd .Series (norm .cdf (s ), index = s .index )
98
110
99
111
100
112
@pf .register_series_method
101
113
def probit (s : pd .Series , error : str = "warn" ) -> pd .Series :
102
114
"""
103
- Transforms the Series via the inverse CDF of the Normal distribution
115
+ Transforms the Series via the inverse CDF of the Normal distribution.
104
116
105
- :param s: Input Series
106
- :param error: Determines behavior when s is outside of (0, 1). If
107
- " warn" then a RuntimeWarning is thrown. If " raise" , then a RuntimeError
108
- is thrown. Otherwise, nothing is thrown and np.nan is returned
109
- for the problematic entries, defaults to " warn"
117
+ :param s: Input Series.
118
+ :param error: Determines behavior when `s` is outside of ` (0, 1)`.
119
+ If `' warn'` then a ` RuntimeWarning` is thrown. If `' raise'` , then
120
+ a `RuntimeError` is thrown. Otherwise, nothing is thrown and ` np.nan`
121
+ is returned for the problematic entries; defaults to `' warn'`.
110
122
:raises RuntimeError: Raised when there are problematic values
111
- in the Series and error=" raise"
123
+ in the Series and ` error=' raise'`.
112
124
:return: Transformed Series
113
-
114
- .. # noqa: DAR103 error
115
125
"""
116
126
s = s .copy ()
117
127
outside_support = (s <= 0 ) | (s >= 1 )
@@ -136,18 +146,20 @@ def z_score(
136
146
keys : Tuple [str , str ] = ("mean" , "std" ),
137
147
) -> pd .Series :
138
148
"""
139
- Transforms the Series into z-scores
149
+ Transforms the Series into z-scores where:
140
150
141
- :param s: Input Series
142
- :param moments_dict: If not None, then the mean and standard
143
- deviation used to compute the z-score transformation is
144
- saved as entries in moments_dict with keys determined by
145
- the keys argument, defaults to None
146
- :param keys: Determines the keys saved in moments_dict
147
- if moments are saved, defaults to ("mean", "std")
148
- :return: Transformed Series
151
+ ```python
152
+ z = (s - s.mean()) / s.std()
153
+ ```
149
154
150
- .. # noqa: DAR103 moments_dict
155
+ :param s: Input Series.
156
+ :param moments_dict: If not `None`, then the mean and standard
157
+ deviation used to compute the z-score transformation is
158
+ saved as entries in `moments_dict` with keys determined by
159
+ the `keys` argument; defaults to `None`.
160
+ :param keys: Determines the keys saved in `moments_dict`
161
+ if moments are saved; defaults to (`'mean'`, `'std'`).
162
+ :return: Transformed Series.
151
163
"""
152
164
mean = s .mean ()
153
165
std = s .std ()
@@ -166,26 +178,26 @@ def ecdf(s: pd.Series) -> Tuple[np.ndarray, np.ndarray]:
166
178
167
179
Intended to be used with the following pattern:
168
180
169
- .. code-block:: python
170
-
171
- df = pd.DataFrame(...)
181
+ ```python
182
+ df = pd.DataFrame(...)
172
183
173
- # Obtain ECDF values to be plotted
174
- x, y = df["column_name"].ecdf()
184
+ # Obtain ECDF values to be plotted
185
+ x, y = df["column_name"].ecdf()
175
186
176
- # Plot ECDF values
177
- plt.scatter(x, y)
187
+ # Plot ECDF values
188
+ plt.scatter(x, y)
189
+ ```
178
190
179
191
Null values must be dropped from the series,
180
192
otherwise a `ValueError` is raised.
181
193
182
- Also, if the dtype of the series is not numeric,
183
- a TypeError is raised.
194
+ Also, if the ` dtype` of the series is not numeric,
195
+ a ` TypeError` is raised.
184
196
185
- :param s: A pandas series. dtype should be numeric.
186
- :returns: (x, y).
187
- x : sorted array of values.
188
- y : cumulative fraction of data points with value `x` or lower.
197
+ :param s: A pandas series. ` dtype` should be numeric.
198
+ :returns: ` (x, y)` .
199
+ `x` : sorted array of values.
200
+ `y` : cumulative fraction of data points with value `x` or lower.
189
201
:raises TypeError: if series is not numeric.
190
202
:raises ValueError: if series contains nulls.
191
203
"""
0 commit comments