17
17
18
18
import argparse
19
19
import doctest
20
- import glob
21
20
import importlib
21
+ import io
22
22
import json
23
- import os
23
+ import pathlib
24
24
import subprocess
25
25
import sys
26
26
import tempfile
27
27
28
- try :
29
- from io import StringIO
30
- except ImportError :
31
- from cStringIO import StringIO
28
+ import matplotlib
29
+ import matplotlib .pyplot as plt
30
+ import numpy
31
+ from numpydoc .validate import (
32
+ Docstring ,
33
+ validate ,
34
+ )
32
35
33
- # Template backend makes matplotlib to not plot anything. This is useful
34
- # to avoid that plot windows are open from the doctests while running the
35
- # script. Setting here before matplotlib is loaded.
36
- # We don't warn for the number of open plots, as none is actually being opened
37
- os .environ ["MPLBACKEND" ] = "Template"
38
- import matplotlib # isort:skip
36
+ import pandas
39
37
40
- matplotlib .rc ("figure" , max_open_warning = 10000 )
41
-
42
- import numpy # isort:skip
43
-
44
- BASE_PATH = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
45
-
46
- sys .path .insert (0 , os .path .join (BASE_PATH ))
47
- import pandas # isort:skip
48
-
49
- sys .path .insert (1 , os .path .join (BASE_PATH , "doc" , "sphinxext" ))
50
- from numpydoc .validate import validate , Docstring # isort:skip
38
+ # With template backend, matplotlib plots nothing
39
+ matplotlib .use ("template" )
51
40
52
41
53
42
PRIVATE_CLASSES = ["NDFrame" , "IndexOpsMixin" ]
@@ -157,7 +146,7 @@ def examples_errors(self):
157
146
context = {"np" : numpy , "pd" : pandas }
158
147
error_msgs = ""
159
148
for test in finder .find (self .raw_doc , self .name , globs = context ):
160
- f = StringIO ()
149
+ f = io . StringIO ()
161
150
runner .run (test , out = f .write )
162
151
error_msgs += f .getvalue ()
163
152
return error_msgs
@@ -263,6 +252,7 @@ def pandas_validate(func_name: str):
263
252
if doc .non_hyphenated_array_like ():
264
253
result ["errors" ].append (pandas_error ("GL05" ))
265
254
255
+ plt .close ("all" )
266
256
return result
267
257
268
258
@@ -288,13 +278,14 @@ def validate_all(prefix, ignore_deprecated=False):
288
278
result = {}
289
279
seen = {}
290
280
291
- api_doc_fnames = os .path .join (BASE_PATH , "doc" , "source" , "reference" , "*.rst" )
281
+ base_path = pathlib .Path (__file__ ).parent .parent
282
+ api_doc_fnames = pathlib .Path (base_path , "doc" , "source" , "reference" )
292
283
api_items = []
293
- for api_doc_fname in glob .glob (api_doc_fnames ):
284
+ for api_doc_fname in api_doc_fnames .glob ("*.rst" ):
294
285
with open (api_doc_fname ) as f :
295
286
api_items += list (get_api_items (f ))
296
287
297
- for func_name , func_obj , section , subsection in api_items :
288
+ for func_name , _ , section , subsection in api_items :
298
289
if prefix and not func_name .startswith (prefix ):
299
290
continue
300
291
doc_info = pandas_validate (func_name )
0 commit comments