Skip to content

Commit d5e3503

Browse files
authored
Merge branch 'master' into output_checker
2 parents 61a7d37 + 96f12ce commit d5e3503

File tree

15 files changed

+483
-92
lines changed

15 files changed

+483
-92
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behaviour:
15+
1. Use function XYZ() with inputs A, B and C.
16+
2. I get results R1 (or something else happens)...
17+
3. ...instead of R2 that was expected.
18+
19+
**Expected behaviour**
20+
A clear and concise description of what you expected to happen.
21+
22+
**Screenshots**
23+
If applicable, add screenshots to help explain your problem.
24+
25+
**System (please complete the following information):**
26+
- OS: [e.g. Windows 10]
27+
- Python: [e.g. ver 3.6.4]
28+
- Version [e.g. 0.1]
29+
30+
**Additional context**
31+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen and why.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ First off, thank you for taking the time to contribute! If you have a functional
1212

1313
We suggest you make sure all of your commits are atomic (one feature per commit). Please make sure that non-obvious lines of code are commented, and variable names are as clear as possible. Please do not send us undocumented code as we will not accept it. Including tests to your pull request will bring tears of joy to our eyes, and will also probably result in a faster merge.
1414

15+
1516
## Coding conventions
1617

1718
Start reading our code to get a feel for it:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
[![Build Status](https://travis-ci.com/codonlibrary/codonPython.svg?branch=master)](https://travis-ci.com/codonlibrary/codonPython)
44
[![codecov](https://codecov.io/gh/codonlibrary/codonPython/branch/master/graph/badge.svg)](https://codecov.io/gh/codonlibrary/codonPython)
55

6-
76
This is a simple example of a future package pulled from the DPS Core code base.
87
The package can be directly installed by typing in your terminal: `python -m pip install --user git+https://github.com/codonlibrary/codonPython.git`

codonPython/age_bands.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22

3-
def age_band_5_years(age: int)->str:
3+
4+
def age_band_5_years(age: int) -> str:
45
"""
56
Place age into appropriate 5 year band
67
@@ -31,7 +32,7 @@ def age_band_5_years(age: int)->str:
3132
return 'Age not known'
3233

3334
if age >= 90:
34-
if age >= 150:
35+
if age >= 150:
3536
raise ValueError("The age input: {} is too large.".format(age))
3637
else:
3738
return '90 and over'
@@ -43,7 +44,7 @@ def age_band_5_years(age: int)->str:
4344
return '{}-{}'.format(lowerbound, upperbound)
4445

4546

46-
def age_band_10_years(age: int)->str:
47+
def age_band_10_years(age: int) -> str:
4748
"""
4849
Place age into appropriate 10 year band
4950
@@ -74,7 +75,7 @@ def age_band_10_years(age: int)->str:
7475
return 'Age not known'
7576

7677
if age >= 90:
77-
if age >= 150:
78+
if age >= 150:
7879
raise ValueError("The age input: {} is too large.".format(age))
7980
else:
8081
return '90 and over'

codonPython/dateValidator.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import re
22

3-
def validDate(date_string: str)->bool:
3+
4+
def validDate(date_string: str) -> bool:
45
"""
56
Validates stringtype dates of type `dd/mm/yyyy`, `dd-mm-yyyy` or `dd.mm.yyyy` from
67
years 1900-9999. Leap year support included.
7-
8+
89
Parameters
910
----------
1011
date_string : str
@@ -24,11 +25,11 @@ def validDate(date_string: str)->bool:
2425
>>> validDate("43/01/1996")
2526
False
2627
"""
27-
28+
2829
# Let TypeError be.
2930

30-
# This regex string will validate dates of type `dd/mm/yyyy`, `dd-mm-yyyy` or `dd.mm.yyyy`
31-
# from years 1900 - 2049. Leap year support included. Original Regex string based on
31+
# This regex string will validate dates of type `dd/mm/yyyy`, `dd-mm-yyyy` or `dd.mm.yyyy`
32+
# from years 1900 - 2049. Leap year support included. Original Regex string based on
3233
# https://stackoverflow.com/questions/15491894/regex-to-validate-date-format-dd-mm-yyyy
3334
# modified to confine the year dates.
3435
if re.match(
@@ -38,7 +39,7 @@ def validDate(date_string: str)->bool:
3839
r"(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]" +
3940
r"|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4" +
4041
r"(?:(?:1[9]..|2[0][0-4].))$",
41-
date_string, flags=0):
42+
date_string, flags=0):
4243
return True
4344
else:
44-
return False
45+
return False

codonPython/nhsNumber.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33

44

5-
def nhsNumberValidator(number: int)->bool:
5+
def nhsNumberValidator(number: int) -> bool:
66
"""
77
Validate NHS Number according to modulus 11 checks as recorded in the data dictionary.
88
https://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp?shownav=1
@@ -26,26 +26,30 @@ def nhsNumberValidator(number: int)->bool:
2626
"""
2727

2828
if not isinstance(number, int):
29-
raise ValueError("Please input a positive 10 digit integer to validate.")
29+
raise ValueError(
30+
"Please input a positive 10 digit integer to validate.")
3031
if number < 0:
31-
raise ValueError("Please input a postitive 10 digit integer to validate.")
32+
raise ValueError(
33+
"Please input a postitive 10 digit integer to validate.")
3234
digits = [int(digit) for digit in str(number)]
3335
# NHS Numbers are 10 digits long.
3436
if not len(digits) == 10:
35-
raise ValueError("Please input a postitive 10 digit integer to validate.")
37+
raise ValueError(
38+
"Please input a postitive 10 digit integer to validate.")
3639
# Apply weighting to first 9 digits
37-
weighted_digits = np.dot(np.array(digits[:9]), np.arange(10,1,-1))
38-
# Validity is based on the check digit, which has to be equal to `remainder`
40+
weighted_digits = np.dot(np.array(digits[:9]), np.arange(10, 1, -1))
41+
# Validity is based on the check digit, which has to be equal to `remainder`
3942
remainder = weighted_digits % 11
4043
check_digit = 11 - remainder
4144
if check_digit == 11:
4245
check_digit = 0
4346
if check_digit == digits[-1]:
4447
return True
45-
else:
48+
else:
4649
return False
4750

48-
def nhsNumberGenerator(to_generate: int, random_state: int = None)->list:
51+
52+
def nhsNumberGenerator(to_generate: int, random_state: int = None) -> list:
4953
"""
5054
Generates up to 1M random NHS numbers compliant with modulus 11 checks as recorded
5155
in the data dictonary.
@@ -72,11 +76,13 @@ def nhsNumberGenerator(to_generate: int, random_state: int = None)->list:
7276
if random_state:
7377
random.seed(random_state)
7478
if not isinstance(to_generate, int):
75-
raise ValueError("Please input a positive integer to generate numbers.")
79+
raise ValueError(
80+
"Please input a positive integer to generate numbers.")
7681
if to_generate > 1000000:
7782
raise ValueError("More than one million values requested")
7883
if to_generate < 0:
79-
raise ValueError("Please input a postitive integer to generate numbers.")
84+
raise ValueError(
85+
"Please input a postitive integer to generate numbers.")
8086

8187
generated = []
8288
while len(generated) < to_generate:

codonPython/tableFromSql.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def tableFromSql(server: str, database: str, table_name: str, user: str = "", password: str = "", schema: str = None, index_col: str = None, coerce_float: bool = True, parse_dates: list = None, columns: list = None, chunksize: int = None):
77
'''
88
Returns a SQL table in a DataFrame.
9-
9+
1010
Convert a table stored in SQL Server 2016 into a pandas dataframe.
1111
Uses sqlalchemy and pandas.
1212
@@ -43,7 +43,7 @@ def tableFromSql(server: str, database: str, table_name: str, user: str = "", pa
4343
chunksize : int, default : None
4444
If specified, returns an iterator where chunksize is the number of rows to include
4545
in each chunk.
46-
46+
4747
Returns
4848
----------
4949
pd.DataFrame
@@ -58,9 +58,9 @@ def tableFromSql(server: str, database: str, table_name: str, user: str = "", pa
5858
'''
5959

6060
try:
61-
uri = "mssql+pyodbc://{}:{}@{}/{}?driver=SQL Server Native Client 11.0".format(user, password, server, database)
61+
uri = "mssql+pyodbc://{}:{}@{}/{}?driver=SQL Server Native Client 11.0".format(
62+
user, password, server, database)
6263
engine = create_engine(uri)
6364
return pd.read_sql_table(table_name, engine, schema=schema, index_col=index_col, coerce_float=coerce_float, parse_dates=parse_dates, columns=columns, chunksize=chunksize)
6465
except Exception as error:
6566
raise error
66-
Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from codonPython import age_bands
22
import numpy as np
33
import math
4-
import pytest
5-
4+
import pytest
5+
6+
67
@pytest.mark.parametrize("age, expected", [
78
(0, '0-4'),
89
(1, '0-4'),
@@ -17,29 +18,33 @@
1718
(90, '90 and over'),
1819
])
1920
def test_age_band_5_years_BAU(age, expected):
20-
assert expected == age_bands.age_band_5_years(age)
21+
assert expected == age_bands.age_band_5_years(age)
22+
2123

2224
def test_age_band_5_years_typeErrors():
23-
with pytest.raises(TypeError):
24-
age_bands.age_band_5_years("age")
25+
with pytest.raises(TypeError):
26+
age_bands.age_band_5_years("age")
27+
2528

2629
@pytest.mark.parametrize("age", [
27-
np.nan,
28-
math.inf,
29-
-3,
30-
343,
31-
-0.1
30+
np.nan,
31+
math.inf,
32+
-3,
33+
343,
34+
-0.1
3235
])
3336
def test_age_band_5_years_valueErrors(age):
34-
with pytest.raises(ValueError):
35-
age_bands.age_band_5_years(age)
37+
with pytest.raises(ValueError):
38+
age_bands.age_band_5_years(age)
39+
3640

3741
@pytest.mark.parametrize("age, expected", [
38-
(None, 'Age not known'),
42+
(None, 'Age not known'),
3943
])
4044
def test_age_band_5_years_edgeCases(age, expected):
41-
assert expected == age_bands.age_band_5_years(age)
42-
45+
assert expected == age_bands.age_band_5_years(age)
46+
47+
4348
@pytest.mark.parametrize("age, expected", [
4449
(0.1, '0-4'),
4550
(1.2, '0-4'),
@@ -54,7 +59,8 @@ def test_age_band_5_years_edgeCases(age, expected):
5459
(90.1, '90 and over'),
5560
])
5661
def test_age_band_5_years_BAU_floats(age, expected):
57-
assert expected == age_bands.age_band_5_years(age)
62+
assert expected == age_bands.age_band_5_years(age)
63+
5864

5965
@pytest.mark.parametrize("age, expected", [
6066
(0, '0-9'),
@@ -70,29 +76,33 @@ def test_age_band_5_years_BAU_floats(age, expected):
7076
(90, '90 and over'),
7177
])
7278
def test_age_band_10_years_BAU(age, expected):
73-
assert expected == age_bands.age_band_10_years(age)
79+
assert expected == age_bands.age_band_10_years(age)
80+
7481

7582
def test_age_band_10_years_typeErrors():
76-
with pytest.raises(TypeError):
77-
age_bands.age_band_10_years("age")
83+
with pytest.raises(TypeError):
84+
age_bands.age_band_10_years("age")
85+
7886

7987
@pytest.mark.parametrize("age", [
80-
np.nan,
81-
math.inf,
82-
-3,
83-
343,
84-
-0.1
88+
np.nan,
89+
math.inf,
90+
-3,
91+
343,
92+
-0.1
8593
])
8694
def test_age_band_10_years_valueErrors(age):
87-
with pytest.raises(ValueError):
88-
age_bands.age_band_10_years(age)
95+
with pytest.raises(ValueError):
96+
age_bands.age_band_10_years(age)
97+
8998

9099
@pytest.mark.parametrize("age, expected", [
91-
(None, 'Age not known'),
100+
(None, 'Age not known'),
92101
])
93102
def test_age_band_10_years_edgeCases(age, expected):
94-
assert expected == age_bands.age_band_10_years(age)
95-
103+
assert expected == age_bands.age_band_10_years(age)
104+
105+
96106
@pytest.mark.parametrize("age, expected", [
97107
(0.1, '0-9'),
98108
(1.2, '0-9'),
@@ -107,4 +117,4 @@ def test_age_band_10_years_edgeCases(age, expected):
107117
(90.1, '90 and over'),
108118
])
109119
def test_age_band_10_years_BAU_floats(age, expected):
110-
assert expected == age_bands.age_band_10_years(age)
120+
assert expected == age_bands.age_band_10_years(age)

0 commit comments

Comments
 (0)