{'from_name': None, 'to_name': 'date_laboratory', 'study_day_col': 'lab_study_day', 'study_day_ref': 'date_enrolment'}, ] # Data data = [ {'StudyNo': '32dx-001', 'DateEnrol': '2020/12/01', 'LabStudyDay': 1}, {'StudyNo': '32dx-002', 'DateEnrol': '2020/12/04', 'LabStudyDay': 5}, {'StudyNo': '32dx-003', 'DateEnrol': '2020/12/11', 'LabStudyDay': 10}, {'StudyNo': '32dx-004', 'DateEnrol': '2020/12/08 04:30', 'LabStudyDay': 0}, {'StudyNo': '32dx-005', 'LabStudyDay': 3}, {'StudyNo': '32dx-005', 'DateEnrol': '2020/12/07'} ] # Blender template bt = BlenderTemplate().fit(template) # Create data data = pd.DataFrame(data) # Create widgets and transform trans = RenameWidget().fit_transform(bt, data) trans = DateFromStudyDayWidget().fit_transform(bt, trans) # Show print("\nOriginal:") print(data) print("\nTransformed:") print(trans)
'hct': 4.0, 'wbc': 2.5 }, ] # Create templates dictionary templates = { 'EXAM': pd.DataFrame(template_exam), 'LAB': pd.DataFrame(template_lab) } # Create data dictionary data = {'EXAM': pd.DataFrame(data_exam), 'LAB': pd.DataFrame(data_lab)} # Create blender blender = Blender(widgets=[RenameWidget(), ReplaceWidget()]) # Fit blender to templates. blender = blender.fit(info=templates) # Transform data transformed = blender.transform(data) # Stack data stacked = blender.stack(transformed, index='pid') # Show print("\nOriginal:") for k, v in data.items(): print("\n%s:" % k) print(v)
def test_widget_rename(bt, data): """""" transformed = RenameWidget().fit_transform(bt, data) assert True
def test_widget_replace_from_dict(bt, data): """""" transformed = RenameWidget().fit_transform(bt, data) transformed = ReplaceWidget().fit_transform(bt, transformed) unique = set(transformed.gender.unique()) assert unique.issubset(set(['Male', 'Female']))
def test_widget_fit_from_json(bt_json): """""" widget = RenameWidget().fit(bt_json) assert isinstance(widget, BaseWidget)
def test_widget_raises_exception_on_missing_required_columns(bt_df): """""" bt_df = bt_df.drop(columns='to_name') bt = BlenderTemplate().fit(bt_df) with pytest.raises(MissingRequiredColumns): RenameWidget().fit(bt)
def test_widget_fit_from_df(bt_df): """""" widget = RenameWidget().fit(bt_df) assert isinstance(widget, BaseWidget)
def test_widget_raises_exception_on_None(): """""" with pytest.raises(TypeError): RenameWidget().fit(None)
'StudyNo': '32dx-002', 'Temp': 36.5, 'Shock': False, 'Sex': 1 }, { 'StudyNo': '32dx-003', 'Temp': 39.8, 'Shock': True, 'Sex': 2 }, { 'StudyNo': '32dx-004', 'Temp': 37.4, 'Shock': False, 'Sex': 1 }] # Create data data = pd.DataFrame(data) # Create widget widget = RenameWidget().fit(template) # Transform transformed = widget.transform(data) # Show print("\nOriginal:") print(data) print("\nTransformed:") print(transformed) print("\nStacked:")
include = [ 'ENROL', 'DAILY', 'INPFU', 'NS1PLATELIA', 'PCR', 'CBC', 'BIO', 'SEROLOGY', 'LAB_DIAGNOSIS' ] # Excel sheets to exclude exclude = ['Category', 'NS1TRIP'] # Read all data sheets data = pd.read_excel(path_fixed, sheet_name=None) tmps = pd.read_excel(path_ccfgs, sheet_name=None) # Create blender blender = Blender(widgets=[ DateTimeMergeWidget(), RenameWidget(), ReplaceWidget(), #TemplateTransformWidget(), EventWidget() ]) # Fit blender to templates. blender = blender.fit(info=tmps) # Transform data transformed = blender.transform(data, include=include, exclude=exclude) # Stacked data stacked = blender.stack(transformed, index='study_no', include=include,
'wbc': 1.0, 'LabSampleStudyDay': 2 }, ] # Create DataFrames template = pd.DataFrame(template) data = pd.DataFrame(data) #template = template.drop(columns=['timestamp']) #template.timestamp = None #template.event = None #template = template.drop(columns=['to_name']) # Transformed (order matters!) transformed = RenameWidget().fit_transform(template, data) transformed = TemplateTransformWidget().fit_transform(template, transformed) transformed = ReplaceWidget().fit_transform(template, transformed) transformed = DateTimeMergeWidget().fit_transform(template, transformed) transformed = DateFromStudyDayWidget().fit_transform(template, transformed) transformed = EventWidget().fit_transform(template, transformed) # Stack data stacked = StackWidget(index=['study_number']) \ .fit_transform(template, transformed) # Show print("\nOriginal:") print(data) print("\nTransformed:") print(transformed)