69
69
}
70
70
ALL_ERRORS = set (NUMPYDOC_ERROR_MSGS ).union (set (ERROR_MSGS ))
71
71
duplicated_errors = set (NUMPYDOC_ERROR_MSGS ).intersection (set (ERROR_MSGS ))
72
- assert not duplicated_errors , (f"Errors { duplicated_errors } exist in both pandas "
73
- "and numpydoc, should they be removed from pandas?" )
72
+ assert not duplicated_errors , (
73
+ f"Errors { duplicated_errors } exist in both pandas "
74
+ "and numpydoc, should they be removed from pandas?"
75
+ )
74
76
75
77
76
78
def pandas_error (code , ** kwargs ):
@@ -245,7 +247,13 @@ def pandas_validate(func_name: str):
245
247
# Some objects are instances, e.g. IndexSlice, which numpydoc can't validate
246
248
doc_obj = get_doc_object (func_obj , doc = func_obj .__doc__ )
247
249
doc = PandasDocstring (func_name , doc_obj )
248
- result = validate (doc_obj )
250
+ if func_obj .__doc__ is not None :
251
+ result = validate (doc_obj )
252
+ else :
253
+ result = {
254
+ "docstring" : "" ,
255
+ "errors" : [("GL08" , "The object does not have a docstring" )],
256
+ }
249
257
mentioned_errs = doc .mentioned_private_classes
250
258
if mentioned_errs :
251
259
result ["errors" ].append (
@@ -257,7 +265,7 @@ def pandas_validate(func_name: str):
257
265
pandas_error (
258
266
"SA05" ,
259
267
reference_name = rel_name ,
260
- right_reference = rel_name [len ("pandas." ):],
268
+ right_reference = rel_name [len ("pandas." ) :],
261
269
)
262
270
for rel_name in doc .see_also
263
271
if rel_name .startswith ("pandas." )
@@ -365,12 +373,13 @@ def print_validate_all_results(
365
373
for func_name , res in result .items ():
366
374
error_messages = dict (res ["errors" ])
367
375
actual_failures = set (error_messages )
368
- expected_failures = (ignore_errors .get (func_name , set ())
369
- | ignore_errors .get (None , set ()))
376
+ expected_failures = ignore_errors .get (func_name , set ()) | ignore_errors .get (
377
+ None , set ()
378
+ )
370
379
for err_code in actual_failures - expected_failures :
371
380
sys .stdout .write (
372
381
f'{ prefix } { res ["file" ]} :{ res ["file_line" ]} :'
373
- f' { err_code } :{ func_name } :{ error_messages [err_code ]} \n '
382
+ f" { err_code } :{ func_name } :{ error_messages [err_code ]} \n "
374
383
)
375
384
exit_status += 1
376
385
for err_code in ignore_errors .get (func_name , set ()) - actual_failures :
@@ -384,8 +393,9 @@ def print_validate_all_results(
384
393
return exit_status
385
394
386
395
387
- def print_validate_one_results (func_name : str ,
388
- ignore_errors : dict [str , set [str ]]) -> int :
396
+ def print_validate_one_results (
397
+ func_name : str , ignore_errors : dict [str , set [str ]]
398
+ ) -> int :
389
399
def header (title , width = 80 , char = "#" ) -> str :
390
400
full_line = char * width
391
401
side_len = (width - len (title ) - 2 ) // 2
@@ -396,8 +406,11 @@ def header(title, width=80, char="#") -> str:
396
406
397
407
result = pandas_validate (func_name )
398
408
399
- result ["errors" ] = [(code , message ) for code , message in result ["errors" ]
400
- if code not in ignore_errors .get (None , set ())]
409
+ result ["errors" ] = [
410
+ (code , message )
411
+ for code , message in result ["errors" ]
412
+ if code not in ignore_errors .get (None , set ())
413
+ ]
401
414
402
415
sys .stderr .write (header (f"Docstring ({ func_name } )" ))
403
416
sys .stderr .write (f"{ result ['docstring' ]} \n " )
@@ -431,14 +444,16 @@ def _format_ignore_errors(raw_ignore_errors):
431
444
raise ValueError (
432
445
f"Object `{ obj_name } ` is present in more than one "
433
446
"--ignore_errors argument. Please use it once and specify "
434
- "the errors separated by commas." )
447
+ "the errors separated by commas."
448
+ )
435
449
ignore_errors [obj_name ] = set (error_codes .split ("," ))
436
450
437
451
unknown_errors = ignore_errors [obj_name ] - ALL_ERRORS
438
452
if unknown_errors :
439
453
raise ValueError (
440
454
f"Object `{ obj_name } ` is ignoring errors { unknown_errors } "
441
- f"which are not known. Known errors are: { ALL_ERRORS } " )
455
+ f"which are not known. Known errors are: { ALL_ERRORS } "
456
+ )
442
457
443
458
# global errors "PR02,ES01"
444
459
else :
@@ -448,27 +463,19 @@ def _format_ignore_errors(raw_ignore_errors):
448
463
if unknown_errors :
449
464
raise ValueError (
450
465
f"Unknown errors { unknown_errors } specified using --ignore_errors "
451
- "Known errors are: {ALL_ERRORS}" )
466
+ "Known errors are: {ALL_ERRORS}"
467
+ )
452
468
453
469
return ignore_errors
454
470
455
471
456
- def main (
457
- func_name ,
458
- output_format ,
459
- prefix ,
460
- ignore_deprecated ,
461
- ignore_errors
462
- ):
472
+ def main (func_name , output_format , prefix , ignore_deprecated , ignore_errors ):
463
473
"""
464
474
Main entry point. Call the validation for one or for all docstrings.
465
475
"""
466
476
if func_name is None :
467
477
return print_validate_all_results (
468
- output_format ,
469
- prefix ,
470
- ignore_deprecated ,
471
- ignore_errors
478
+ output_format , prefix , ignore_deprecated , ignore_errors
472
479
)
473
480
else :
474
481
return print_validate_one_results (func_name , ignore_errors )
@@ -524,10 +531,11 @@ def main(
524
531
args = argparser .parse_args (sys .argv [1 :])
525
532
526
533
sys .exit (
527
- main (args .function ,
528
- args .format ,
529
- args .prefix ,
530
- args .ignore_deprecated ,
531
- _format_ignore_errors (args .ignore_errors ),
532
- )
534
+ main (
535
+ args .function ,
536
+ args .format ,
537
+ args .prefix ,
538
+ args .ignore_deprecated ,
539
+ _format_ignore_errors (args .ignore_errors ),
540
+ )
533
541
)
0 commit comments