Skip to content

Commit 3b7a091

Browse files
committed
fix #676 : implemented ExcelReport class which generates an Excel file with multiple graphs
moved _positive_integer() from util/options.py to util/misc.py added get_example_templates_dir() function
1 parent 03b6fbf commit 3b7a091

23 files changed

+747
-14
lines changed

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include COPYING
2-
recursive-include larray/tests/data *.csv *.xlsx *.h5
2+
recursive-include larray/tests/data *.csv *.xlsx *.h5
3+
recursive-include larray/tests/excel_template *.crtx

doc/source/api.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,22 @@ Excel
675675
Workbook.close
676676
Workbook.app
677677

678+
ExcelReport
679+
===========
680+
681+
.. autosummary::
682+
:toctree: _generated/
683+
684+
ExcelReport
685+
ExcelReport.set_template_dir
686+
ExcelReport.set_graph_template
687+
ExcelReport.set_item_default_size
688+
ExcelReport.set_sheet
689+
ExcelReport.newline
690+
ExcelReport.add_title
691+
ExcelReport.add_graph
692+
ExcelReport.to_excel
693+
678694
.. _api-misc:
679695

680696
Miscellaneous
@@ -687,6 +703,7 @@ Miscellaneous
687703
from_frame
688704
from_series
689705
get_example_filepath
706+
get_example_templates_dir
690707
set_options
691708
get_options
692709
labels_array

larray/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from larray.inout.sas import read_sas
3131
from larray.inout.stata import read_stata
3232
from larray.inout.xw_excel import open_excel, Workbook
33+
from larray.inout.xw_reporting import ExcelReport
3334

3435
# just make sure handlers for .pkl and .pickle are initialized
3536
import larray.inout.pickle as _pkl
@@ -41,7 +42,7 @@
4142

4243
from larray.extra.ipfp import ipfp
4344

44-
from larray.example import get_example_filepath, load_example_data
45+
from larray.example import get_example_filepath, load_example_data, get_example_templates_dir
4546

4647
import larray.random
4748

@@ -75,15 +76,16 @@
7576
'real_if_close', 'interp', 'isnan', 'isinf', 'inverse',
7677
# inout
7778
'from_lists', 'from_string', 'from_frame', 'from_series', 'read_csv', 'read_tsv',
78-
'read_eurostat', 'read_excel', 'read_hdf', 'read_sas', 'read_stata', 'open_excel', 'Workbook',
79+
'read_eurostat', 'read_excel', 'read_hdf', 'read_sas', 'read_stata',
80+
'open_excel', 'Workbook', 'ExcelReport',
7981
# utils
8082
'get_options', 'set_options',
8183
# viewer
8284
'view', 'edit', 'compare',
8385
# ipfp
8486
'ipfp',
8587
# example
86-
'get_example_filepath', 'load_example_data',
88+
'get_example_filepath', 'load_example_data', 'get_example_templates_dir',
8789
]
8890

8991

larray/example.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
import larray as la
33

44

5-
EXAMPLE_FILES_DIR = os.path.dirname(__file__) + '/tests/data/'
5+
_TEST_DIR = os.path.join(os.path.dirname(__file__), 'tests')
6+
7+
EXAMPLE_FILES_DIR = os.path.join(_TEST_DIR, 'data')
8+
# TODO : replace 'demography.h5' by 'population_session.h5' and remove 'demo' ?
69
AVAILABLE_EXAMPLE_DATA = {
10+
'demo': os.path.join(EXAMPLE_FILES_DIR, 'population_session.h5'),
711
'demography': os.path.join(EXAMPLE_FILES_DIR, 'demography.h5')
812
}
913
AVAILABLE_EXAMPLE_FILES = os.listdir(EXAMPLE_FILES_DIR)
1014

15+
EXAMPLE_EXCEL_TEMPLATES_DIR = os.path.join(_TEST_DIR, 'excel_template')
16+
1117

1218
def get_example_filepath(fname):
1319
"""Return absolute path to an example file if exist.
@@ -77,3 +83,32 @@ def load_example_data(name):
7783
if name not in AVAILABLE_EXAMPLE_DATA.keys():
7884
raise ValueError("example_data must be chosen from list {}".format(list(AVAILABLE_EXAMPLE_DATA.keys())))
7985
return la.Session(AVAILABLE_EXAMPLE_DATA[name])
86+
87+
88+
def get_example_templates_dir():
89+
"""
90+
Return the path the directory containing example Excel template files.
91+
92+
Examples
93+
--------
94+
>>> tmpl_dir = get_example_templates_dir()
95+
96+
>>> # list of all available example templates
97+
>>> for template_file in sorted(os.listdir(tmpl_dir)):
98+
... print(template_file)
99+
Area.crtx
100+
Area_100Stacked.crtx
101+
Area_Stacked.crtx
102+
Bar_100Stacked.crtx
103+
Bar_Clustered.crtx
104+
Bar_Stacked.crtx
105+
Line.crtx
106+
Line_Comp_Proj.crtx
107+
Line_Marker.crtx
108+
Line_Marker_Comp_Proj.crtx
109+
Line_Marker_Proj.crtx
110+
Line_proj.crtx
111+
Pie.crtx
112+
Scat.crtx
113+
"""
114+
return EXAMPLE_EXCEL_TEMPLATES_DIR

0 commit comments

Comments
 (0)