1
1
"""
2
- For compatibility with numpy libraries, pandas functions or
3
- methods have to accept '*args' and '**kwargs' parameters to
4
- accommodate numpy arguments that are not actually used or
5
- respected in the pandas implementation.
6
-
7
- To ensure that users do not abuse these parameters, validation
8
- is performed in 'validators.py' to make sure that any extra
9
- parameters passed correspond ONLY to those in the numpy signature.
10
- Part of that validation includes whether or not the user attempted
11
- to pass in non-default values for these extraneous parameters. As we
12
- want to discourage users from relying on these parameters when calling
13
- the pandas implementation, we want them only to pass in the default values
14
- for these parameters.
15
-
16
- This module provides a set of commonly used default arguments for functions
17
- and methods that are spread throughout the codebase. This module will make it
2
+ For compatibility with numpy libraries, pandas functions or methods have to
3
+ accept '*args' and '**kwargs' parameters to accommodate numpy arguments that
4
+ are not actually used or respected in the pandas implementation.
5
+
6
+ To ensure that users do not abuse these parameters, validation is performed in
7
+ 'validators.py' to make sure that any extra parameters passed correspond ONLY
8
+ to those in the numpy signature. Part of that validation includes whether or
9
+ not the user attempted to pass in non-default values for these extraneous
10
+ parameters. As we want to discourage users from relying on these parameters
11
+ when calling the pandas implementation, we want them only to pass in the
12
+ default values for these parameters.
13
+
14
+ This module provides a set of commonly used default arguments for functions and
15
+ methods that are spread throughout the codebase. This module will make it
18
16
easier to adjust to future upstream changes in the analogous numpy signatures.
19
17
"""
20
18
from distutils .version import LooseVersion
@@ -92,11 +90,10 @@ def process_skipna(skipna, args):
92
90
93
91
def validate_argmin_with_skipna (skipna , args , kwargs ):
94
92
"""
95
- If 'Series.argmin' is called via the 'numpy' library,
96
- the third parameter in its signature is 'out', which
97
- takes either an ndarray or 'None', so check if the
98
- 'skipna' parameter is either an instance of ndarray or
99
- is None, since 'skipna' itself should be a boolean
93
+ If 'Series.argmin' is called via the 'numpy' library, the third parameter
94
+ in its signature is 'out', which takes either an ndarray or 'None', so
95
+ check if the 'skipna' parameter is either an instance of ndarray or is
96
+ None, since 'skipna' itself should be a boolean
100
97
"""
101
98
skipna , args = process_skipna (skipna , args )
102
99
validate_argmin (args , kwargs )
@@ -105,11 +102,10 @@ def validate_argmin_with_skipna(skipna, args, kwargs):
105
102
106
103
def validate_argmax_with_skipna (skipna , args , kwargs ):
107
104
"""
108
- If 'Series.argmax' is called via the 'numpy' library,
109
- the third parameter in its signature is 'out', which
110
- takes either an ndarray or 'None', so check if the
111
- 'skipna' parameter is either an instance of ndarray or
112
- is None, since 'skipna' itself should be a boolean
105
+ If 'Series.argmax' is called via the 'numpy' library, the third parameter
106
+ in its signature is 'out', which takes either an ndarray or 'None', so
107
+ check if the 'skipna' parameter is either an instance of ndarray or is
108
+ None, since 'skipna' itself should be a boolean
113
109
"""
114
110
skipna , args = process_skipna (skipna , args )
115
111
validate_argmax (args , kwargs )
@@ -130,8 +126,8 @@ def validate_argmax_with_skipna(skipna, args, kwargs):
130
126
ARGSORT_DEFAULTS , fname = "argsort" , max_fname_arg_count = 0 , method = "both"
131
127
)
132
128
133
- # two different signatures of argsort, this second validation
134
- # for when the `kind` param is supported
129
+ # two different signatures of argsort, this second validation for when the
130
+ # `kind` param is supported
135
131
ARGSORT_DEFAULTS_KIND : Dict [str , Optional [int ]] = {}
136
132
ARGSORT_DEFAULTS_KIND ["axis" ] = - 1
137
133
ARGSORT_DEFAULTS_KIND ["order" ] = None
@@ -142,11 +138,10 @@ def validate_argmax_with_skipna(skipna, args, kwargs):
142
138
143
139
def validate_argsort_with_ascending (ascending , args , kwargs ):
144
140
"""
145
- If 'Categorical.argsort' is called via the 'numpy' library, the
146
- first parameter in its signature is 'axis', which takes either
147
- an integer or 'None', so check if the 'ascending' parameter has
148
- either integer type or is None, since 'ascending' itself should
149
- be a boolean
141
+ If 'Categorical.argsort' is called via the 'numpy' library, the first
142
+ parameter in its signature is 'axis', which takes either an integer or
143
+ 'None', so check if the 'ascending' parameter has either integer type or is
144
+ None, since 'ascending' itself should be a boolean
150
145
"""
151
146
if is_integer (ascending ) or ascending is None :
152
147
args = (ascending ,) + args
@@ -164,10 +159,10 @@ def validate_argsort_with_ascending(ascending, args, kwargs):
164
159
165
160
def validate_clip_with_axis (axis , args , kwargs ):
166
161
"""
167
- If 'NDFrame.clip' is called via the numpy library, the third
168
- parameter in its signature is 'out', which can takes an ndarray,
169
- so check if the 'axis' parameter is an instance of ndarray, since
170
- 'axis' itself should either be an integer or None
162
+ If 'NDFrame.clip' is called via the numpy library, the third parameter in
163
+ its signature is 'out', which can takes an ndarray, so check if the 'axis'
164
+ parameter is an instance of ndarray, since 'axis' itself should either be
165
+ an integer or None
171
166
"""
172
167
if isinstance (axis , ndarray ):
173
168
args = (axis ,) + args
@@ -190,10 +185,9 @@ def validate_clip_with_axis(axis, args, kwargs):
190
185
191
186
def validate_cum_func_with_skipna (skipna , args , kwargs , name ):
192
187
"""
193
- If this function is called via the 'numpy' library, the third
194
- parameter in its signature is 'dtype', which takes either a
195
- 'numpy' dtype or 'None', so check if the 'skipna' parameter is
196
- a boolean or not
188
+ If this function is called via the 'numpy' library, the third parameter in
189
+ its signature is 'dtype', which takes either a 'numpy' dtype or 'None', so
190
+ check if the 'skipna' parameter is a boolean or not
197
191
"""
198
192
if not is_bool (skipna ):
199
193
args = (skipna ,) + args
@@ -294,10 +288,9 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
294
288
295
289
def validate_take_with_convert (convert , args , kwargs ):
296
290
"""
297
- If this function is called via the 'numpy' library, the third
298
- parameter in its signature is 'axis', which takes either an
299
- ndarray or 'None', so check if the 'convert' parameter is either
300
- an instance of ndarray or is None
291
+ If this function is called via the 'numpy' library, the third parameter in
292
+ its signature is 'axis', which takes either an ndarray or 'None', so check
293
+ if the 'convert' parameter is either an instance of ndarray or is None
301
294
"""
302
295
if isinstance (convert , ndarray ) or convert is None :
303
296
args = (convert ,) + args
@@ -360,10 +353,9 @@ def validate_expanding_func(name, args, kwargs) -> None:
360
353
361
354
def validate_groupby_func (name , args , kwargs , allowed = None ) -> None :
362
355
"""
363
- 'args' and 'kwargs' should be empty, except for allowed
364
- kwargs because all of
365
- their necessary parameters are explicitly listed in
366
- the function signature
356
+ 'args' and 'kwargs' should be empty, except for allowed kwargs because all
357
+ of their necessary parameters are explicitly listed in the function
358
+ signature
367
359
"""
368
360
if allowed is None :
369
361
allowed = []
@@ -382,9 +374,8 @@ def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
382
374
383
375
def validate_resampler_func (method : str , args , kwargs ) -> None :
384
376
"""
385
- 'args' and 'kwargs' should be empty because all of
386
- their necessary parameters are explicitly listed in
387
- the function signature
377
+ 'args' and 'kwargs' should be empty because all of their necessary
378
+ parameters are explicitly listed in the function signature
388
379
"""
389
380
if len (args ) + len (kwargs ) > 0 :
390
381
if method in RESAMPLER_NUMPY_OPS :
@@ -398,8 +389,8 @@ def validate_resampler_func(method: str, args, kwargs) -> None:
398
389
399
390
def validate_minmax_axis (axis : Optional [int ]) -> None :
400
391
"""
401
- Ensure that the axis argument passed to min, max, argmin, or argmax is
402
- zero or None, as otherwise it will be incorrectly ignored.
392
+ Ensure that the axis argument passed to min, max, argmin, or argmax is zero
393
+ or None, as otherwise it will be incorrectly ignored.
403
394
404
395
Parameters
405
396
----------
0 commit comments