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