Report class

class araucaria.main.report.Report(name=None, sep=2, sdigits=5, marker='=')[source]

Report class.

Stores user-defined information for print to sys.stdout.

Parameters
  • name (Optional[str]) – Name of the instance.

  • sep (int) – Separation between printed columns. The default is 2.

  • sdigits (int) – Significant digits for printed floats. The default is 5.

  • marker (str) – Character for header and endrule. The default is ‘=’.

Example

>>> from araucaria import Report
>>> report = Report()
>>> type(report)
<class 'araucaria.main.report.Report'>
>>> report.sep
2
>>> report.sdigits
5
>>> report.marker
'='
set_columns(names)[source]

Sets parameters for each printed column.

Parameters

names (list) – List with the names for each column field.

Return type

None

Returns

Example

>>> from araucaria import Report
>>> report = Report()
>>> names  = ['Name', 'Description']
>>> report.set_columns(names)
>>> report.names
['Name', 'Description']
add_row(row)[source]

Adds a row of content to the report.

Content can be accesed through the self.content attribute.

Parameters

row (list) – List with values for each column in a single report row.

Return type

None

Returns

Raises

Example

>>> from araucaria import Report
>>> report = Report()
>>> names  = ['Name', 'Description']
>>> report.set_columns(names)
>>> report.add_row(['filename 1', 'a single scan'])
>>> report.content
array(['filename 1', 'a single scan'], dtype=object)
add_midrule(marker='-')[source]

Adds a midrule to the report.

Parameters

marker (str) – Character for the midrule. The default is ‘-‘.

Return type

None

Returns

Example

>>> from araucaria import Report
>>> report = Report()
>>> names  = ['Name', 'Description']
>>> report.set_columns(names)
>>> report.add_midrule()
>>> report.content
array(['-', '-'], dtype=object)
get_cols(names=['all'], astype=<class 'object'>)[source]

Returns columns of the report by name.

Parameters
  • names (list) – List with names of columns to return. The default is [‘all’], which returns the entire report content.

  • astype (dtype) – Data type conversion for the returned array. The default is object.

Return type

ndarray

Returns

Array with the requested columns.

Raises

ValueError – If names does not contain valid column names.

Example

>>> import random
>>> from araucaria import Report
>>> random.seed(1111)
>>> report = Report()
>>> names  = ['Name', 'Value']
>>> report.set_columns(names)
>>> for i in range(1,4):
...     report.add_row(['filename %s'% i, random.random()])
>>> col = report.get_cols(names=['Value',])
>>> print(col)
['0.2176' '0.34438' '0.64225']
>>> # returning column as float
>>> col = report.get_cols(names=['Value',], astype=float)
>>> print(col)
[0.2176  0.34438 0.64225]
>>> print(col.dtype)
float64
get_rows(index=['all'], astype=<class 'object'>)[source]

Returns rows of the report by index.

Parameters
  • index (list) – List with indexes of rows to return. The default is [‘all’], which returns the entire report content.

  • astype (dtype) – Data type conversion for the returned array. The default is object.

Return type

ndarray

Returns

Array with the requested rows.

Example

>>> import random
>>> from araucaria import Report
>>> random.seed(1111)
>>> report = Report()
>>> names  = ['Name', 'Value']
>>> report.set_columns(names)
>>> for i in range(1,4):
...     report.add_row(['filename %s'% i, random.random()])
>>> row = report.get_rows(index=[1,])
>>> print(row)
['filename 2' '0.34438']
show(header=True, endrule=True, print_report=True)[source]

Returns the formatted report.

Parameters
  • header (bool) – Prints a header rule and column names. The default is True.

  • endrule (bool) – Prints an end rule. The default is True.

  • print_report (bool) – Prints the report to sys.stdout. If False the formatted report is returned as a str The default is True.

Return type

Optional[str]

Returns

Formatted report. Returned only if print_report=False.

Example

>>> import random
>>> from araucaria import Report
>>> random.seed(1111)
>>> report = Report()
>>> names  = ['Name', 'Value']
>>> report.set_columns(names)
>>> for i in range(1,4):
...     report.add_row(['filename %s'% i, random.random()])
>>> report.show()
=====================
Name        Value
=====================
filename 1  0.2176
filename 2  0.34438
filename 3  0.64225
=====================