Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1c43663
Reorganize tests and create a Makefile
benjello Aug 10, 2015
0e519f7
Add travis configuration
benjello Aug 10, 2015
48b4b03
Fix Travis tests
cbenz Aug 11, 2015
38dc325
Build cython extensions "inplace"
cbenz Aug 11, 2015
a57b64d
Add clean-build target
cbenz Aug 11, 2015
961f812
Correct deprecated assignment outside function
benjello Aug 11, 2015
7a4924e
Update imported1.yml
benjello Aug 11, 2015
61e6940
Update .gitignore
benjello Aug 11, 2015
a74d144
Update test_liam2.py
benjello Aug 11, 2015
f72491d
Re-raise exception instead of printing it
cbenz Aug 11, 2015
f898d18
Update requirements
cbenz Aug 11, 2015
c5467ce
Install pytables with pip
cbenz Aug 11, 2015
fd57fc9
Add build-dep for pytables
cbenz Aug 11, 2015
617e6f3
Add matplotlib for Travis
cbenz Aug 11, 2015
257b051
Add python-sip to travis
benjello Aug 11, 2015
683e225
Improving tests
benjello Aug 27, 2015
4f7697e
Add bcolz install to travis config
benjello Aug 27, 2015
b42da95
Remove cruft in importer.py
benjello Aug 28, 2015
326a471
Use bcolz 0.7 to make travis-ci work (hopefully)
benjello Aug 28, 2015
34afd0a
Deal with bcolz absence in importer.py
benjello Sep 11, 2015
1f88444
Remove bcolz since it is now completely optional
benjello Sep 11, 2015
6621eb7
Add some produced .h5 files
benjello Sep 11, 2015
17cb61e
Modification after rebase
benjello Sep 11, 2015
c82f440
make tests travis aware
benjello Sep 13, 2015
511b86b
Add long to list of accepted numerical types
benjello Sep 13, 2015
250fb47
Amend test_liam2 to ignore static.yml and generate.yml
benjello Sep 13, 2015
f3b8584
Allow small.h5 to be commited for travis test sake
benjello Sep 13, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ doc/usersguide/build/
liam2/build
liam2/*.c
build
tests/functional/error.log
tests/functional/person_*.csv
tests/functional/*.h5
tests/functional/*.png
tests/functional/*.pdf
tests/functional/empty_file.csv
tests/examples/simulation.h5
tests/examples/demography_*.png
tests/examples/error.log
tests/examples/person_*.csv
liam2/tests/functional/*.h5
!liam2/tests/functional/small.h5
liam2/tests/output/error.log
liam2/tests/output/person_*.csv
liam2/tests/output/*.h5
liam2/tests/output/*.png
liam2/tests/output/*.pdf
liam2/tests/output/empty_file.csv
liam2/tests/output/simulation.h5
liam2/tests/output/demography_*.png
liam2/tests/output/demography_*.csv
doc/website/blog
doc/website/objects.inv
doc/website/pages/download.rst
Expand Down
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
env:
- USE_TRAVIS=true
language: python
python: "2.7"
virtualenv:
system_site_packages: true
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq cython python-matplotlib python-numexpr python-numpy python-yaml python-sip
- sudo apt-get build-dep python-tables
install:
- pip install flake8 # Not yet available in Debian stable
- pip install tables # For version > 3
- pip install -e .
- python setup.py build_ext --inplace
script: make test-ci
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LIAM2 uses a number of other open-source packages.
Required dependencies:
- Python 2.7.x (32b or 64b) - http://www.python.org/
- Numpy 1.7.0 or later - http://www.numpy.org/
- PyTables 2.2.1 or later - http://www.pytables.org
- PyTables 3 or later - http://www.pytables.org
- Numexpr 2.0 or later - https://github.com/pydata/numexpr
- PyYAML 3.0.8 or later - http://pyyaml.org

Expand Down
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
TESTS_DIR=liam2/tests

all: flake8 test

check-syntax-errors:
@# This is a hack around flake8 not displaying E910 errors with the select option.
@# Do not analyse .gitignored files.
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
test -z "`flake8 --first $(shell git ls-files | grep "\.py$$") | grep E901`"

clean: clean-build clean-cython clean-pyc

clean-build:
rm -rf build

clean-cython:
rm liam2/cpartition.c liam2/cutils.c cpartition.so cutils.so

clean-pyc:
find . -name '*.pyc' -exec rm \{\} \;

ctags:
ctags --recurse=yes .

flake8: clean-pyc
flake8

test: check-syntax-errors
nosetests $(TESTS_DIR) --exe --stop --with-doctest

test-ci: check-syntax-errors
nosetests $(TESTS_DIR) --exe --with-doctest

test-with-coverage:
nosetests $(TESTS_DIR) --exe --stop --with-coverage --cover-package=openfisca_france --cover-erase --cover-branches --cover-html
10 changes: 5 additions & 5 deletions doc/usersguide/source/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ file.

entities:
household:
path: input\household.csv
path: input/household.csv

person:
path: input\person.csv
path: input/person.csv

This will try to load all the fields of the household and person entities in
"*household.csv*" and "person.csv" in the "input" sub-directory of the
Expand All @@ -198,10 +198,10 @@ directory where the description file is.

entities:
household:
path: input\household.csv
path: input/household.csv

person:
path: input\person.csv
path: input/person.csv
fields:
- age: int
- gender: bool
Expand Down Expand Up @@ -245,7 +245,7 @@ If the fields of an entity are scattered in several files, you can use the
value: workstate
# person.csv should have at least 4 columns:
# period, id, age and gender
- param\person.csv:
- param/person.csv:
newnames:
# we override the "global" renaming
period: period
Expand Down
2 changes: 1 addition & 1 deletion liam2/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def evaluate(expr, globals_dict, locals_dict=None, **kwargs):
timings = Counter()

type_to_idx = {bool: 0, np.bool_: 0,
int: 1, np.int8: 1, np.int16: 1, np.int32: 1, np.int64: 1, np.intc: 1, np.longlong: 1,
int: 1, np.int8: 1, np.int16: 1, np.int32: 1, np.int64: 1, np.intc: 1, np.long: 1, np.longlong: 1,
float: 2, np.float64: 2}
idx_to_type = [bool, int, float]

Expand Down
17 changes: 10 additions & 7 deletions liam2/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ def union1d(arrays):


def interpolate(target, arrays, id_periods, fields):
assert bcolz is not None, 'bcolz package is required to use interpolate'
print(" * indexing...")
periods = np.unique(id_periods['period'])
max_id = np.max(id_periods['id'])
Expand Down Expand Up @@ -412,11 +411,15 @@ def interpolate(target, arrays, id_periods, fields):
del lastrow_for_id

size = sum(row_for_id[period].nbytes for period in periods)
print(" * compressing index (%.2f Mb)..." % (size / MB), end=' ')
for period in periods:
row_for_id[period] = bcolz.carray(row_for_id[period])
csize = sum(row_for_id[period].cbytes for period in periods)
print("done. (%.2f Mb)" % (csize / MB))

if bcolz is not None:
print(" * compressing index (%.2f Mb)..." % (size / MB), end=' ')
for period in periods:
row_for_id[period] = bcolz.carray(row_for_id[period])
csize = sum(row_for_id[period].cbytes for period in periods)
print("done. (%.2f Mb)" % (csize / MB))
else:
print('bcolz package not found (bcolz is required to use compression in interpolate)')

print(" * interpolating...")
for values in arrays:
Expand Down Expand Up @@ -685,7 +688,7 @@ def load_def(localdir, ent_name, section_def, required_fields):
return 'table', (target_fields, total_lines, iter(target), None)


def csv2h5(fpath, buffersize=10 * 2 ** 20):
def csv2h5(fpath = None, buffersize=10 * 2 ** 20):
with open(fpath) as f:
content = yaml.load(f)

Expand Down
Empty file added liam2/tests/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ output: simple2001.h5

globals:
periodic:
path: input\globals_transposed.csv
path: input/globals_transposed.csv
transposed: True

entities:
household:
path: input\household.csv
path: input/household.csv
# if fields are not specified, they are all imported

person:
path: input\person.csv
path: input/person.csv
fields:
# period and id are implicit
- age: int
Expand Down
File renamed without changes.
Binary file added liam2/tests/examples/simple2001.h5
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ output: small.h5

globals:
ARRAY:
path: param\mig.csv
path: param/mig.csv
type: float

othertable_noperiod:
path: param\othertable.csv
path: param/othertable.csv
fields:
# PERIOD is *not* implicit
- INTFIELD: int
- FLOATFIELD: float

entities:
region:
path: param\region.csv
path: param/region.csv

household:
path: param\household.csv
path: param/household.csv

person:
fields:
Expand All @@ -35,7 +35,7 @@ entities:

# deprecated? no, let's just say it's a shortcut if there is only one
# file. And it could serve as a prefix for individual files path.
path: param\person.csv
path: param/person.csv

# deprecated? no. it could be useful even in the case of several files
# if you want fields renamed the same way across all files
Expand All @@ -54,16 +54,16 @@ entities:
## transposed: True
#
files:
- param\person.csv:
- param/person.csv:
# oldnames:
# period: period
# dead: co_alive
newnames:
period: period
co_alive: dead

- param\p_age.txt: {}
- param\p_work.txt: {}
- param/p_age.txt: {}
- param/p_work.txt: {}

# interpolate:
# work: previous_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ output: import_issue154.h5

entities:
dummy:
path: param\period0.csv
path: param/period0.csv
fields:
# period and id are implicit
- period: int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ entities:
- imported_field1: {type: int, initialdata: False}

macros:
IMPORTED_MACRO: imported_field1 == 1
IMPORTED_MACRO: imported_field1 == 1
ISCHILD: age < 17

processes:
agegroup: trunc(age / 10)
compute_agegroup:
- agegroup: trunc(age / 10)

imported_process:
- imported_field1: age + 1

simulation:
# overridden by simulation.yml
processes:
- person: [agegroup, imported_process]
- person: [compute_agegroup, imported_process]

periods: 55

Expand All @@ -31,4 +32,3 @@ simulation:
# not overridden (present in neither imported2.yml nor simulation.yml)
input:
file: small.h5

Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ entities:
- imported_field2: {type: int, initialdata: False}

macros:
IMPORTED_MACRO: imported_field2 == 2
IMPORTED_MACRO: imported_field2 == 2
ISCHILD: age < 16

processes:
agegroup: trunc(age / 20)
compute_agegroup:
- agegroup: trunc(age / 20)

imported_process:
- imported_field2: age + 2

simulation:
# overrides imported1.yml and is overridden by simulation.yml
periods: 1

# overrides imported1.yml and is not overridden
start_period: 2002 # first simulated period
default_entity: person

# not defined elsewhere thus not overridden
random_seed: 0
random_seed: 0
File renamed without changes.
File renamed without changes.
Loading