forked from statsmodels/statsmodels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset_rst.py
executable file
·54 lines (44 loc) · 1.39 KB
/
dataset_rst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env python
"""
Run this script to convert dataset documentation to ReST files. Relies
on the meta-information from the datasets of the currently installed version.
Ie., it imports the datasets package to scrape the meta-information.
"""
import statsmodels.api as sm
import os
from os.path import join
import inspect
from string import Template
datasets = dict(inspect.getmembers(sm.datasets, inspect.ismodule))
datasets.pop('datautils')
datasets.pop('nile') #TODO: fix docstring in nile
doc_template = Template(u"""$TITLE
$title_
Description
-----------
$DESCRIPTION
Notes
-----
$NOTES
Source
------
$SOURCE
Copyright
---------
$COPYRIGHT
""")
for dataset in datasets:
write_pth = join('../docs/source/datasets/generated',
dataset+'.rst')
data_mod = datasets[dataset]
with open(os.path.realpath(write_pth), 'w') as rst_file:
title = getattr(data_mod,'TITLE')
descr = getattr(data_mod, 'DESCRLONG')
copyr = getattr(data_mod, 'COPYRIGHT')
notes = getattr(data_mod, 'NOTE')
source = getattr(data_mod, 'SOURCE')
write_file = doc_template.substitute(TITLE=title,
title_='='*len(title),
DESCRIPTION=descr, NOTES=notes,
SOURCE=source, COPYRIGHT=copyr)
rst_file.write(write_file)