@@ -43,13 +43,15 @@ def check(varname: str, value, expected_types: list):
43
43
One-liner syntactic sugar for checking types.
44
44
It can also check callables.
45
45
46
- Should be used like this: :
46
+ Example usage :
47
47
48
- check('x', x, [int, float])
48
+ ```python
49
+ check('x', x, [int, float])
50
+ ```
49
51
50
52
:param varname: The name of the variable (for diagnostic error message).
51
- :param value: The value of the varname.
52
- :param expected_types: The types we expect the item to be.
53
+ :param value: The value of the ` varname` .
54
+ :param expected_types: The type(s) the item is expected to be.
53
55
:raises TypeError: if data is not the expected type.
54
56
"""
55
57
is_expected_type : bool = False
@@ -146,15 +148,17 @@ def _strip_underscores(
146
148
147
149
Underscores can be stripped from the beginning, end or both.
148
150
149
- .. code-block:: python
151
+ Example usage:
150
152
151
- df = _strip_underscores(df, strip_underscores='left')
153
+ ```
154
+ df = _strip_underscores(df, strip_underscores='left')
155
+ ```
152
156
153
157
:param df: The pandas DataFrame object.
154
158
:param strip_underscores: (optional) Removes the outer underscores from all
155
- column names. Default None keeps outer underscores. Values can be
156
- either 'left', 'right' or 'both' or the respective shorthand 'l', 'r'
157
- and True.
159
+ column names. Default ` None` keeps outer underscores. Values can be
160
+ either ` 'left'`, ` 'right'` or ` 'both'` or the respective shorthand
161
+ `'l'`, `'r'` and ` True` .
158
162
:returns: A pandas DataFrame with underscores removed.
159
163
"""
160
164
df = df .rename (
@@ -195,11 +199,11 @@ def import_message(
195
199
optional module / package that is not currently installed. Includes
196
200
installation instructions. Used in `chemistry.py` and `biology.py`.
197
201
198
- :param submodule: pyjanitor submodule that needs an external dependency.
202
+ :param submodule: ` pyjanitor` submodule that needs an external dependency.
199
203
:param package: External package this submodule relies on.
200
- :param conda_channel: Conda channel package can be installed from,
204
+ :param conda_channel: `conda` channel package can be installed from,
201
205
if at all.
202
- :param pip_install: Whether package can be installed via pip.
206
+ :param pip_install: Whether package can be installed via ` pip` .
203
207
"""
204
208
is_conda = os .path .exists (os .path .join (sys .prefix , "conda-meta" ))
205
209
installable = True
@@ -231,43 +235,41 @@ def import_message(
231
235
232
236
def idempotent (func : Callable , df : pd .DataFrame , * args , ** kwargs ):
233
237
"""
234
- Raises error if a function operating on a ` DataFrame` is not idempotent,
235
- that is, `func(func(df)) = func(df)` is not true for all `df`.
238
+ Raises an error if a function operating on a DataFrame is not idempotent.
239
+ That is, `func(func(df)) = func(df)` is not `True` for all `df`.
236
240
237
- :param func: A python method.
241
+ :param func: A Python method.
238
242
:param df: A pandas `DataFrame`.
239
243
:param args: Positional arguments supplied to the method.
240
244
:param kwargs: Keyword arguments supplied to the method.
241
245
:raises ValueError: If `func` is found to not be idempotent for the given
242
- ` DataFrame` `df`.
246
+ DataFrame ( `df`) .
243
247
"""
244
248
if not func (df , * args , ** kwargs ) == func (
245
249
func (df , * args , ** kwargs ), * args , ** kwargs
246
250
):
247
251
raise ValueError (
248
- "Supplied function is not idempotent for the given " " DataFrame."
252
+ "Supplied function is not idempotent for the given DataFrame."
249
253
)
250
254
251
255
252
256
def deprecated_alias (** aliases ) -> Callable :
253
257
"""
254
258
Used as a decorator when deprecating old function argument names, while
255
- keeping backwards compatibility.
256
-
257
- Implementation is inspired from `StackOverflow`_.
259
+ keeping backwards compatibility. Implementation is inspired from [`StackOverflow`][stack_link].
258
260
259
- .. _StackOverflow : https://stackoverflow.com/questions/49802412/how-to-implement-deprecation-in-python-with-argument-alias
261
+ [stack_link] : https://stackoverflow.com/questions/49802412/how-to-implement-deprecation-in-python-with-argument-alias
260
262
261
263
Functional usage example:
262
264
263
- .. code-block:: python
264
-
265
- @deprecated_alias(a=' alpha', b=' beta')
266
- def simple_sum( alpha, beta):
267
- return alpha + beta
265
+ ``` python
266
+ @deprecated_alias(a='alpha', b='beta')
267
+ def simple_sum( alpha, beta):
268
+ return alpha + beta
269
+ ```
268
270
269
271
:param aliases: Dictionary of aliases for a function's arguments.
270
- :return: Your original function wrapped with the kwarg redirection
272
+ :return: Your original function wrapped with the ` kwarg` redirection
271
273
function.
272
274
""" # noqa: E501
273
275
0 commit comments