Skip to content

Commit afe3877

Browse files
author
Verweijen
committed
Improve docstrings
1 parent a924e4f commit afe3877

27 files changed

+134
-43
lines changed

docs/source/api.rst

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
1+
===
12
API
23
===
34

4-
InputData
5-
---------
6-
.. automodule:: piargus.inputdata
5+
Input Specification
6+
===================
7+
8+
Input data
9+
----------
10+
.. automodule:: piargus.inputspec
711
:members: InputData, MetaData, MicroData, TableData, CodeList
812
:show-inheritance:
913

1014
Hierarchies
1115
-----------
12-
.. automodule:: piargus.inputdata.hierarchy
13-
:members: Hierarchy, TreeHierarchy, FlatHierarchy, LevelHierarchy
16+
.. automodule:: piargus.inputspec.hierarchy
17+
:members: Hierarchy, TreeHierarchy, FlatHierarchy, LevelHierarchy, TreeHierarchyNode
1418
:show-inheritance:
1519

16-
Safety rule
17-
-----------
18-
.. automodule:: piargus
19-
:members: dominance_rule, percent_rule, frequency_rule, request_rule, zero_rule, missing_rule, weight_rule, manual_rule, p_rule, nk_rule,
20-
:show-inheritance:
20+
Output Specification
21+
====================
2122

22-
Output
23+
Tables
2324
------
25+
.. automodule:: piargus.outputspec
26+
:members: Table, Apriori, TreeRecode
27+
:show-inheritance:
2428

29+
Safety rule
30+
-----------
2531
.. automodule:: piargus
26-
:members: Table, Apriori, TreeRecode
32+
:members: dominance_rule, percent_rule, frequency_rule, request_rule, zero_rule, missing_rule, weight_rule, manual_rule, p_rule, nk_rule,
2733
:show-inheritance:
2834

29-
Jobs
30-
----
35+
Result
36+
======
3137
.. automodule:: piargus
32-
:members: Job, JobSetupError
38+
:members: ArgusReport, TableResult
3339
:show-inheritance:
3440

3541
Tau-Argus
36-
---------
42+
=========
3743
.. automodule:: piargus
38-
:members: TauArgus, BatchWriter
44+
:members: TauArgus, BatchWriter, Job, JobSetupError
3945
:show-inheritance:

src/piargus/__init__.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
from .argusreport import TauArgusException
21
from .batchwriter import BatchWriter
32
from .constants import *
4-
from .inputdata import InputData, MetaData, MicroData, TableData, CodeList
5-
from .inputdata.hierarchy import Hierarchy, FlatHierarchy, TreeHierarchy, \
3+
from .inputspec import InputData, MetaData, MicroData, TableData, CodeList
4+
from .inputspec.hierarchy import Hierarchy, FlatHierarchy, TreeHierarchy, \
65
TreeHierarchyNode, Node, LevelHierarchy
76
from .job import Job, JobSetupError
8-
from .table import Table, Apriori, TreeRecode
9-
from .table.safetyrule import *
7+
from .outputspec import Table, Apriori, TreeRecode
8+
from .outputspec.safetyrule import *
9+
from .result import TauArgusException, ArgusReport, TableResult
1010
from .tauargus import TauArgus
1111

1212
__version__ = "1.0.2"
1313

1414
__all__ = [
1515
"Apriori",
16+
"TauArgus",
1617
"TauArgusException",
1718
"BatchWriter",
1819
"CodeList",
1920
"TreeRecode",
21+
"Job",
22+
"JobSetupError",
23+
24+
# Inputdata
2025
"InputData",
2126
"MetaData",
2227
"MicroData",
2328
"TableData",
24-
"Job",
25-
"JobSetupError",
2629

2730
# Hierarchy
2831
"Hierarchy",
@@ -44,8 +47,13 @@
4447
"manual_rule",
4548
"p_rule",
4649
"nk_rule",
50+
51+
# Table
4752
"Table",
48-
"TauArgus",
53+
54+
# Result
55+
"ArgusReport",
56+
"TableResult",
4957

5058
# Constants
5159
"SAFE",

src/piargus/batchwriter.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .constants import FREQUENCY_RESPONSE
2-
from .table.safetyrule import make_safety_rule
3-
from .utils import format_argument
2+
from .outputspec.safetyrule import make_safety_rule
3+
from .helpers import format_argument
44

55

66
class BatchWriter:
@@ -22,19 +22,30 @@ def write_command(self, command, arg=None):
2222
return command, arg
2323

2424
def logbook(self, log_file):
25+
"""Write LOGBOOK to batch file."""
2526
self.write_command('LOGBOOK', format_argument(log_file))
2627

2728
def open_microdata(self, microdata):
29+
"""Write OPENMICRODATA to batch file."""
2830
return self.write_command("OPENMICRODATA", format_argument(microdata))
2931

3032
def open_tabledata(self, tabledata):
33+
"""Write OPENTABLEDATA to batch file."""
3134
return self.write_command("OPENTABLEDATA", format_argument(tabledata))
3235

3336
def open_metadata(self, metadata):
37+
"""Write METADATA to batch file."""
3438
return self.write_command("OPENMETADATA", format_argument(metadata))
3539

36-
def specify_table(self, explanatory, response=FREQUENCY_RESPONSE, shadow=None, cost=None,
37-
labda=None):
40+
def specify_table(
41+
self,
42+
explanatory,
43+
response=FREQUENCY_RESPONSE,
44+
shadow=None,
45+
cost=None,
46+
labda=None
47+
):
48+
"""Write SPECIFYTABLE to batch file."""
3849
explanatory_str = "".join([format_argument(v) for v in explanatory])
3950
response_str = format_argument(response)
4051
shadow_str = format_argument(shadow)
@@ -45,15 +56,18 @@ def specify_table(self, explanatory, response=FREQUENCY_RESPONSE, shadow=None, c
4556
return self.write_command('SPECIFYTABLE', options)
4657

4758
def read_microdata(self):
59+
"""Write READMICRODATA to batch file."""
4860
return self.write_command("READMICRODATA")
4961

5062
def read_table(self, compute_totals=None):
63+
"""Write READTABLE to batch file."""
5164
if compute_totals is None:
5265
return self.write_command("READTABLE")
5366
else:
5467
return self.write_command("READTABLE", int(compute_totals))
5568

5669
def apriori(self, filename, table, separator=',', ignore_error=False, expand_trivial=True):
70+
"""Write APRIORI to batch file."""
5771
filename = format_argument(filename)
5872
table = format_argument(table)
5973
separator = format_argument(separator)
@@ -63,32 +77,39 @@ def apriori(self, filename, table, separator=',', ignore_error=False, expand_tri
6377
return self.write_command("APRIORI", arg)
6478

6579
def recode(self, table, variable, file_or_treelevel):
80+
"""Write RECODE to batch file."""
6681
table = format_argument(table)
6782
variable = format_argument(variable)
6883
file_or_treelevel = format_argument(file_or_treelevel)
6984
arg = f"{table}, {variable}, {file_or_treelevel}"
7085
return self.write_command("RECODE", arg)
7186

7287
def safety_rule(self, rule="", /, *, individual="", holding=""):
88+
"""Write SAFETYRULE to batch file."""
7389
rule = make_safety_rule(rule, individual=individual, holding=holding)
7490
return self.write_command('SAFETYRULE', rule)
7591

7692
def suppress(self, method, table, *method_args):
93+
"""Write SUPPRESS to batch file."""
7794
args = ",".join(map(format_argument, [table, *method_args]))
7895
return self.write_command('SUPPRESS', f"{method}({args})")
7996

8097
def write_table(self, table, kind, options, filename):
98+
"""Write WRITETABLE to batch file."""
8199
if hasattr(options, 'items'):
82100
options = "".join([k + {True: "+", False: "-"}[v] for k, v in options.items()])
83101

84102
result = f"({table}, {kind}, {options}, {format_argument(filename)})"
85103
return self.write_command('WRITETABLE', result)
86104

87105
def version_info(self, filename):
106+
"""Write VERSIONINFO to batch file."""
88107
return self.write_command("VERSIONINFO", format_argument(filename))
89108

90109
def go_interactive(self):
110+
"""Write GOINTERACTIVE to batch file."""
91111
return self.write_command("GOINTERACTIVE")
92112

93113
def clear(self):
114+
"""Write CLEAR to batch file."""
94115
return self.write_command("CLEAR")
File renamed without changes.
File renamed without changes.

src/piargus/inputdata/codelist.py src/piargus/inputspec/codelist.py

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class CodeList:
1212

1313
@classmethod
1414
def from_cdl(cls, file):
15+
"""Read cdl file."""
1516
df = pd.read_csv(file, index_col=0, header=None)
1617
codelist = CodeList(df.iloc[:, 0])
1718
if isinstance(file, (str, Path)):
@@ -20,6 +21,7 @@ def from_cdl(cls, file):
2021
return codelist
2122

2223
def __init__(self, codes):
24+
"""Create a codelist."""
2325
if hasattr(codes, 'keys'):
2426
self._codes = pd.Series(codes)
2527
else:
@@ -35,9 +37,11 @@ def __str__(self):
3537
return self.to_cdl()
3638

3739
def __getitem__(self, key):
40+
"""Get label of a code."""
3841
return self._codes[key]
3942

4043
def __setitem__(self, key, value):
44+
"""Set label of a code."""
4145
self._codes[key] = value
4246

4347
def __iter__(self):
@@ -57,10 +61,12 @@ def keys(self):
5761
return self._codes.keys()
5862

5963
def iter_codes(self):
64+
"""Iterate through codes."""
6065
for code in self._codes.index:
6166
yield code
6267

6368
def to_cdl(self, file=None, length=0):
69+
"""Store codelist in cdl file."""
6470
codes = self._codes.copy()
6571
codes.index = codes.index.str.rjust(length)
6672
result = codes.to_csv(file, header=False)

src/piargus/inputdata/hierarchy/flathierarchy.py src/piargus/inputspec/hierarchy/flathierarchy.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FlatHierarchy(Hierarchy):
1212
is_hierarchical = False
1313

1414
def __init__(self, *, total_code=DEFAULT_TOTAL_CODE):
15+
"""Create a FlatHierarchy."""
1516
self.total_code = total_code
1617

1718
def __repr__(self):

src/piargus/inputdata/hierarchy/levelhierarchy.py src/piargus/inputspec/hierarchy/levelhierarchy.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class LevelHierarchy(Hierarchy):
1414
is_hierarchical = True
1515

1616
def __init__(self, levels, *, total_code: str = DEFAULT_TOTAL_CODE):
17+
"""Create a tree hierarchy."""
1718
self.levels = [int(level) for level in levels]
1819
self.total_code = total_code
1920

src/piargus/inputdata/hierarchy/treehierarchy.py src/piargus/inputspec/hierarchy/treehierarchy.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class TreeHierarchy(Hierarchy):
1818
is_hierarchical = True
1919

2020
def __init__(self, tree=None, *, total_code: str = DEFAULT_TOTAL_CODE, indent='@'):
21+
"""Create a tree hierarchy."""
2122
if not isinstance(tree, TreeHierarchyNode):
2223
tree = TreeHierarchyNode(total_code, tree)
2324
self.root = tree
@@ -40,18 +41,25 @@ def __hash__(self):
4041

4142
@property
4243
def total_code(self) -> str:
44+
"""The code used as a total."""
4345
return self.root.code
4446

4547
@total_code.setter
4648
def total_code(self, value):
4749
self.root.code = value
4850

4951
def get_node(self, path) -> Optional["TreeHierarchyNode"]:
50-
"""Return single Node, None if it doesn't exist, ValueError if path not unique."""
52+
"""Obtain a node within the hierarchy.
53+
54+
Return single Node, None if it doesn't exist, ValueError if path not unique."""
5155
return self.root.path.get(path)
5256

5357
def create_node(self, path) -> "TreeHierarchyNode":
54-
"""Return single Node, None if it doesn't exist, ValueError if path not unique."""
58+
"""Create a node within the hierarchy.
59+
60+
The newly created node is returned.
61+
If the node already existed, the existing one is returned.
62+
"""
5563
return self.root.path.create(path)
5664

5765
@property
@@ -71,6 +79,7 @@ def code_length(self):
7179

7280
@classmethod
7381
def from_hrc(cls, file, indent='@', total_code=DEFAULT_TOTAL_CODE):
82+
"""Create hierarchy from a hrc-file."""
7483
if isinstance(file, (str, Path)):
7584
with open(file) as reader:
7685
hierarchy = cls.from_hrc(reader, indent, total_code)
@@ -82,6 +91,7 @@ def from_hrc(cls, file, indent='@', total_code=DEFAULT_TOTAL_CODE):
8291
return cls(root, indent=indent)
8392

8493
def to_hrc(self, file=None, length=0):
94+
"""Write hierarchy to a hrc-file."""
8595
if file is None:
8696
file = io.StringIO(newline=os.linesep)
8797
self.to_hrc(file, length)
@@ -122,9 +132,11 @@ def to_relations(self, child_name="code", parent_name="parent"):
122132
return serializer.to_relations(self.root)
123133

124134
def to_image(self, **kwargs):
135+
"""Export the hierarchy file as an image."""
125136
return self.root.to_image(**kwargs)
126137

127138
def to_pillow(self, **kwargs):
139+
"""Export the hierarchy file as a Pillow image."""
128140
if hasattr(self.root, 'to_pillow'):
129141
# Newer versions
130142
return self.root.to_pillow(**kwargs)
@@ -151,6 +163,7 @@ def __init__(self, code=None, children=(), parent=None):
151163

152164
@property
153165
def code(self):
166+
"""Which code belongs to this node."""
154167
return self.identifier
155168

156169
@code.setter

src/piargus/inputdata/inputdata.py src/piargus/inputspec/inputdata.py

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262

6363
@abc.abstractmethod
6464
def to_csv(self, target):
65+
"""Save data to a file in the csv-format which tau-argus requires."""
6566
raise NotImplementedError
6667

6768
@abc.abstractmethod
@@ -106,6 +107,7 @@ def resolve_column_lengths(self, default=DEFAULT_COLUMN_LENGTH):
106107

107108
@property
108109
def hierarchies(self):
110+
"""The hierarchies attached to input data."""
109111
return self._hierarchies
110112

111113
@hierarchies.setter
@@ -115,6 +117,7 @@ def hierarchies(self, value):
115117

116118
@property
117119
def codelists(self):
120+
"""The codelists attached to input data."""
118121
return self._codelists
119122

120123
@codelists.setter

0 commit comments

Comments
 (0)