Skip to content

Commit e55d6b2

Browse files
Merge pull request #22 from actuarialopensource/1.0_attempt_2
1.0 attempt 2
2 parents 8a2fdf6 + bcc6dc0 commit e55d6b2

31 files changed

Lines changed: 623 additions & 1243 deletions

.devcontainer/devcontainer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Python 3",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.7",
4+
"features": {
5+
"ghcr.io/devcontainers/features/node:1": {
6+
"version": "none"
7+
},
8+
"ghcr.io/devcontainers/features/docker-in-docker:1": {},
9+
"ghcr.io/dhoeric/features/act:1": {}
10+
}
11+
12+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
13+
// "forwardPorts": [],
14+
15+
// Use 'postCreateCommand' to run commands after the container is created.
16+
// "postCreateCommand": "pip3 install --user -r requirements.txt",
17+
18+
// Configure tool-specific properties.
19+
// "customizations": {},
20+
21+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
22+
// "remoteUser": "root"
23+
}

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
*.xml linguist-vendored
4+
*.ipynb linguist-prose

.github/workflows/learn-github-actions.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/pytest.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: run tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
pytest:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: actions/setup-python@v4
11+
with:
12+
python-version: "3.7.1"
13+
- name: Install poetry
14+
uses: abatilo/actions-poetry@v2
15+
with:
16+
poetry-version: 1.1.15
17+
- name: Install requirements
18+
run: poetry install
19+
- name: Install requirements
20+
run: poetry run pytest --cov=./ --cov-report=xml
21+
- name: Upload coverage reports to Codecov with GitHub Action
22+
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Byte-compiled / optimized / DLL files
2-
__pycache__/
2+
**/__pycache__/
33
*.py[cod]
44

55
# C extensions

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ xml = MortXML(3282)
2020

2121
This `MortXML` class is a wrapper around the [underlying XML](https://mort.soa.org/About.aspx). The autocompletions you get on attributes improve the developer experience over using the underlying XML directly.
2222

23-
![](./assets/auto.png)
23+
![autocompletions](./assets/auto.png)
2424

25-
### Examples
25+
Also, mortality rate tables are Pandas DataFrames.
26+
27+
![rate table as a dataframe](./assets/rate-table.png)
28+
29+
30+
## Accessing mortality rates
31+
32+
For a select and ultimate table we can retrieve rates as follows.
2633

2734
```py
2835
from pymort import MortXML
36+
# Table 3265 is 2015 VBT Smoker Distinct Male Non-Smoker ANB, see https://mort.soa.org/
2937
xml = MortXML(3265)
3038
# This is the select table as a MultiIndex (age/duration) DataFrame.
3139
xml.Tables[0].Values
@@ -37,7 +45,7 @@ xml.Tables[1].Values
3745

3846
## Usage with tensor libraries
3947

40-
Once we get the data from Pandas to NumPy it should be easy to get into JAX or any other tensor library.
48+
We can get the data from Pandas to NumPy.
4149

4250
```py
4351
select = MortXML(3265).Tables[0].Values.unstack().values
@@ -49,65 +57,3 @@ ultimate.shape # (103,) is age 18 to 120
4957
# Be careful when indexing into these, ultimate[0] is the rate at age 18!
5058
```
5159

52-
## Relational tables
53-
54-
Pymort provides **3 normalized tables** related by [primary/foreign keys](https://www.ibm.com/docs/en/ida/9.1.1?topic=entities-primary-foreign-keys), a design taken from relational databases.
55-
56-
Currently tables from 2015 VBT and 2017 CSO are supported. If you want support for tables from other studies, open an issue on GitHub.
57-
58-
XML files with multiple "select" (2-dimensional) or multiple "ultimate" (1-dimensional) tables like table [2636](https://mort.soa.org/ViewTable.aspx?&TableIdentity=2636) are not supported so that we can avoid adding another column.
59-
60-
### Metadata
61-
62-
Each table has a unique identifier called an `id`. There is information associated with this table like
63-
64-
- What is the name of the mortality study producing the table? (i.e. 2017 CSO vs. 2015 VBT)
65-
- Is there a grouping that the table belongs to within the study? (i.e. unloaded preferred_structure gender_distinct ANB vs. loaded smoker_distinct gender_blended ALB)
66-
- Gender (male vs. female)
67-
- Risk (smoker vs. nonsmoker)
68-
69-
We call this information about a table the `metadata` and store it as an attribute of our `Relational` object.
70-
71-
```py
72-
from pymort import Relational
73-
74-
db = Relational()
75-
76-
print(db.metadata)
77-
```
78-
79-
![](./assets/meta2.png)
80-
81-
### Select
82-
83-
Select tables depend on the issue age, and the years since issuing the contract.
84-
85-
```py
86-
print(db.select)
87-
```
88-
89-
![](./assets/sel2.png)
90-
91-
### Ultimate
92-
93-
Ultimate tables depend on the attained age only.
94-
95-
```py
96-
print(db.ultimate)
97-
```
98-
99-
![](./assets/ult2.png)
100-
101-
### Groupings
102-
103-
If you want to get the IDs for all tables having the same study and group there is a function for this, although you could do it yourself in Pandas.
104-
105-
```py
106-
from pymort import getIdGroup
107-
108-
getIdGroup(3265)
109-
```
110-
111-
This returns a dataclass representing the grouping.
112-
113-
![](./assets/grouping.png)
-175 KB
Binary file not shown.

assets/grouping.png

-86.8 KB
Binary file not shown.

assets/meta2.png

-127 KB
Binary file not shown.

0 commit comments

Comments
 (0)