Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tidying-a-file.rst to tutorial section to walk users
through an example of test driven data-wrangling.
- Loading branch information
1 parent
fdc5988
commit a8a0789
Showing
5 changed files
with
566 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
from datatest import working_directory | ||
from datatest import Selector | ||
from datatest import validate | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
@working_directory(__file__) | ||
def users(): | ||
return Selector('users.csv') | ||
|
||
|
||
def test_columns(users): | ||
validate(users.fieldnames, {'user_id', 'active'}) | ||
|
||
|
||
def test_user_id(users): | ||
|
||
def is_wellformed(x): # <- Helper function. | ||
return x[:-1].isdigit() and x[-1:].isupper() | ||
|
||
validate(users('user_id'), is_wellformed) | ||
|
||
|
||
def test_active(users): | ||
validate(users({'active'}), {'Y', 'N'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from datatest import working_directory | ||
from datatest import Selector | ||
from datatest import DataTestCase | ||
|
||
|
||
def setUpModule(): | ||
global users | ||
with working_directory(__file__): | ||
users = Selector('users.csv') | ||
|
||
|
||
class TestUserData(DataTestCase): | ||
|
||
def test_columns(self): | ||
self.assertValid(users.fieldnames, {'user_id', 'active'}) | ||
|
||
def test_user_id(self): | ||
|
||
def is_wellformed(x): # <- Helper function. | ||
return x[:-1].isdigit() and x[-1:].isupper() | ||
|
||
self.assertValid(users('user_id'), is_wellformed) | ||
|
||
def test_active(self): | ||
self.assertValid(users({'active'}), {'Y', 'N'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
USER_ID,ACTIVE | ||
0999F,Y | ||
1000C,Y | ||
1001C,n | ||
1002A,n | ||
1003C,Y | ||
1004E,Y | ||
1005H,Y | ||
1006E,n | ||
1007H,Y | ||
1008A,Y | ||
1009F,n | ||
1010D,n | ||
1011H,Y | ||
1012H,Y | ||
1013E,Y | ||
1014D,Y | ||
1015C,Y | ||
1016H,Y | ||
1017G,Y | ||
1018A,Y | ||
1019H,Y | ||
1020E,Y | ||
1021H,n | ||
1022A,n | ||
1023B,Y | ||
1024D,n | ||
1025C,Y | ||
1026B,Y | ||
1027H,Y | ||
1028B,n | ||
1029A,n | ||
1030H,n | ||
1031A,n | ||
1032G,y | ||
1033H,y | ||
1034F,y | ||
1035F,n | ||
1036E,y | ||
1037E,y | ||
1038G,y | ||
1039G,y | ||
1040A,n | ||
1041A,Y | ||
1042H,Y | ||
1043B,Y | ||
1044G,n | ||
1045A,n | ||
1046A,Y | ||
1047H,Y | ||
1048D,n | ||
1049A,n | ||
1050H,n | ||
1051A,n | ||
1052E,Y | ||
1053A,Y | ||
1054G,Y | ||
1055C,Y | ||
1056a,Y | ||
1057F,Y | ||
1058D,Y | ||
1059H,Y | ||
1060A,YES | ||
1061D,YES | ||
1062E,NO | ||
1063C,NO | ||
1064H,YES | ||
1065A,YES | ||
1066F,YES | ||
1067A,YES | ||
1068F,YES | ||
1069D,YES | ||
1070H,YES | ||
1071E,YES | ||
1072G,YES | ||
1073B,YES | ||
1074B,NO | ||
1075B,Y | ||
1076A,Y | ||
1077A,n | ||
1078H,Y | ||
1079C,Y | ||
1080F,Y | ||
1081B,n | ||
1082F,Y | ||
1083F,Y | ||
1084F,n | ||
1085H,n | ||
1086G,Y | ||
1087C,Y | ||
1088A,Y | ||
1089A,Y | ||
1090E,Y | ||
1091B,n | ||
1092C,Y | ||
1093G,n | ||
1094B,n | ||
1095C,Y | ||
1096A,n | ||
1097E,Y | ||
1098C,Y | ||
1099b,n | ||
1100G,n | ||
1101B,Y | ||
1102C,Y | ||
1103A,Y | ||
1104H,Y | ||
1105H,Y | ||
1106A,n | ||
1107E,n | ||
1108E,Y | ||
1109G,Y | ||
1110B,Y | ||
1111F,n | ||
1112D,n | ||
1113B,Y | ||
1114H,Y | ||
1115A,Y | ||
1116B,Y | ||
1117B,Y | ||
1118D,n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ Tutorials | |
|
||
introduction | ||
querying-data | ||
Tidying a File <tidying-a-file.rst> | ||
|
Oops, something went wrong.