-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrules_engine.py
3321 lines (2911 loc) · 172 KB
/
rules_engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#This file will contain the python class used to check LAR data using the edits as described in the HMDA FIG
#This class should be able to return a list of row fail counts for each S/V edit for each file passed to the class.
#The return should be JSON formatted data, written to a file?
#input to the class will be a pandas dataframe
from collections import OrderedDict
import pandas as pd
from io import StringIO
import string
import time
import yaml
import utils
class rules_engine(object):
"""docstring for ClassName"""
def __init__(self, lar_schema=None, ts_schema=None, year=2019, geographic_data=None):#tracts=None, counties=None, small_counties=None):
#lar and TS field names (load from schema names?)
#Loading yaml for geographic data.
yaml_file = "configurations/geographic_data.yaml"
with open(yaml_file, 'r') as f:
geographic = yaml.safe_load(f)
self.year = year
self.tracts = list(geographic_data.tract_fips)#tracts #instantiate valid Census tracts
self.counties = list(geographic_data.county_fips) #instantiate valid Census counties
self.small_counties = geographic_data[geographic_data.small_county=="1"]#small_counties #instantiate list of small counties
self.lar_field_names = list(lar_schema.field)
self.ts_field_names = list(ts_schema.field)
self.geographic_data = geographic_data
#self.ts_df, self.lar_df= self.split_ts_row(data_file=data_file)
#if data_row:
#self.lar_df = data_row
self.state_codes = geographic['state_codes']
self.results = []
#Helper Functions
def load_lar_data(self, lar_df=None):
"""Takes a dataframe of LAR data and stores it as a class variable."""
self.lar_df = lar_df
def load_ts_data(self, ts_df=None):
"""Takes a dataframe of TS data and stores it as a class variable. TS data must be a single row."""
self.ts_df = ts_df
def load_data_frames(self, ts_data, lar_data):
"""Receives dataframes for TS and LAR and writes them as object attributes"""
self.ts_df = ts_data
self.lar_df = lar_data
def update_results(self, edit_name="", edit_field_results="", row_type="", fields="", row_ids=None, fail_count=None):
"""Updates the results dictionary by adding a sub-dictionary for the edit, any associated fields, and the result of the edit test.
edit name is the name of the edit, edit field results is a dict containing field names as keys and pass/fail as values, row type is LAR or TS,
row ids contains a list of all rows failing the test"""
add_result = {}
add_result["edit_name"] = edit_name
add_result["row_type"] = row_type
add_result["status"] = edit_field_results
add_result["fields"] = fields
if row_ids is not None:
add_result["row_ids"] = row_ids
if fail_count is not None:
add_result["fail_count"] = fail_count
self.results.append(add_result)
def results_wrapper(self, fail_df=None, field_name=None, edit_name=None, row_type="LAR"):
"""Helper function to create results dictionary/JSON object."""
if len(fail_df) > 0:
count = len(fail_df)
result = "failed"
if row_type == "LAR":
failed_rows = list(fail_df.uli)
self.update_results(edit_name=edit_name, edit_field_results=result, row_type=row_type, fields=field_name, row_ids=failed_rows, fail_count=count)
else:
#Adding an edit report row for an edit related to the Transmittal Sheet. As TS is one row, the fail count is set to 1.
self.update_results(edit_name=edit_name, edit_field_results=result, row_type=row_type, fields=field_name, row_ids='TS', fail_count=1)
else:
result = "passed"
self.update_results(edit_name=edit_name, edit_field_results=result, row_type=row_type, fields=field_name)
def reset_results(self):
"""Resets results list to empty."""
self.results = []
def split_ts_row(self, data_file="../edits_files/passes_all.txt"):
"""This function makes a separate data frame for the TS and LAR portions of a file and returns each as a dataframe."""
with open(data_file, 'r') as infile:
ts_row = infile.readline().strip("\n")
ts_data = []
ts_data.append(ts_row.split("|"))
lar_rows = infile.readlines()
lar_data = [line.strip("\n").split("|") for line in lar_rows]
ts_df = pd.DataFrame(data=ts_data, dtype=object, columns=self.ts_field_names)
lar_df = pd.DataFrame(data=lar_data, dtype=object, columns=self.lar_field_names)
return ts_df, lar_df
def valid_date(self, date):
"""checks if a passed date is valid. If not returns false."""
try:
time.strptime(date,'%Y%m%d')
return True
except:
return False
def check_dupes(self, row, fields=[]):
"""checks for duplicate entries in the ethnicity fields"""
dct = {i:row[fields[i]] for i in range(len(fields))}
#eths = {1: row["app_eth_1"], 2:row["app_eth_2"], 3:row["app_eth_3"], 4:row["app_eth_4"], 5:row["app_eth_5"]}
result = "pass"
for key, value in dct.items():
for key2, value2 in dct.items():
if not key == key2:
if value == value2 and value2 != "":
result = "fail"
return result
def check_number(self, field, min_val=None):
"""Checks if a passed field contains only digits. Optionally a minimum value can be checked as well"""
try:
digit = field.replace(".","").isdigit() #check if data field is a digit
if min_val is not None: #min_val was passed
if digit == True and float(field) > min_val:
return True #digit and min_val are True
else:
return False #digit is True, min_val is False
else:
return digit #no min value passed
except:
return False #passed value is not a number
def compare_nums(self, row, fields=[]):
"""Checks if field_1 is greater than field_2"""
try:
field_1 = float(row[fields[0]])
field_2 = float(row[fields[1]])
if field_1 > field_2:
return True
else:
return False
except:
return False
def check_counts(self, row, fields_1, fields_2, vals_1, vals_2):
"""Checks if two sets of fields have the same count of valid entries"""
count_1 = 0
count_2 = 0
for field in fields_1:
if row[field] in vals_1:
count_1 +=1
for field in fields_2:
if row[field] in vals_2:
count_2 +=1
if count_1 == count_2:
return True
else:
return False
#Edit Rules from FIG
def s300_1(self):
"""1) The first row of your file must begin with a 1;."""
field = "record_id"
edit_name = "s300_1"
fail_df = self.ts_df[self.ts_df.record_id!="1"]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def s300_2(self):
"""2) Any subsequent rows [of your file] must begin with a 2."""
field = "record_id"
edit_name = "s300_2"
fail_df = self.lar_df[self.lar_df.record_id!="2"]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="LAR")
def s301(self):
"""The LEI in this row does not match the reported LEI in the transmittal sheet (the first row of your file). Please update your file accordingly."""
field="LEI"
edit_name = "s301"
#get dataframe of LAR row fails
#fail_df = self.lar_df[self.lar_df.lei != self.ts_df.get_value(0, "lei")]
fail_df = self.lar_df[self.lar_df.lei!=self.ts_df.at[0,"lei"]]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v600(self):
"""1) The required format for LEI is alphanumeric with 20 characters, and it cannot be left blank."""
field = "LEI"
edit_name = "v600"
#get dataframe of failed LAR rows
fail_df = self.lar_df[(self.lar_df.lei=="")|(self.lar_df.lei.map(lambda x: len(x))!=20)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="LAR")
def s302(self):
"""The reported Calendar Year does not match the filing year indicated at the start of the filing."""
field = "calendar_year"
edit_name = "s302"
year = str(self.year)
fail_df = self.ts_df[self.ts_df.calendar_year != self.year]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def s304(self):
"""The reported Total Number of Entries Contained in Submission does not match the total number of LARs in the HMDA file."""
result={}
#if self.ts_df.get_value(0, "lar_entries") != str(len(self.lar_df)):
if self.ts_df.at[0,"lar_entries"]!=str(len(self.lar_df)):
result["lar_entries"] = "failed"
else:
result["lar_entries"] = "passed"
self.update_results(edit_name="s304", edit_field_results=result, row_type="TS/LAR")
def v601_1(self):
"""The following data fields are required, and cannot be left blank. A blank value(s) was provided.
1) Financial Institution Name;"""
field = "inst_name"
edit_name = "v601_1"
fail_df = self.ts_df[self.ts_df.inst_name == ""]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v601_2(self):
"""The following data fields are required, and cannot be left blank. A blank value(s) was provided.
2) Contact Person's Name"""
field = "contact_name"
edit_name = "v601_2"
fail_df = self.ts_df[self.ts_df.contact_name == ""]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v601_3(self):
"""The following data fields are required, and cannot be left blank. A blank value(s) was provided.
3) Contact Person's E-mail Address"""
field = "contact_email"
edit_name = "v601_3"
fail_df = self.ts_df[self.ts_df.contact_email == ""]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v601_4(self):
"""The following data fields are required, and cannot be left blank. A blank value(s) was provided.
4) Contact Person's Office Street Address"""
field = "contact_street_address"
edit_name = "v601_4"
fail_df = self.ts_df[self.ts_df.contact_street_address== ""]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v601_5(self):
"""The following data fields are required, and cannot be left blank. A blank value(s) was provided.
5) Contact Person's Office City"""
field = "office_city"
edit_name = "v601_5"
fail_df = self.ts_df[self.ts_df.office_city == ""]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v602(self):
"""An invalid Calendar Quarter was reported. 1) Calendar Quarter must equal 4, and cannot be left blank."""
field = "calendar_quarter"
edit_name = "v602"
fail_df = self.ts_df.copy()
fail_df.calendar_quarter = fail_df.calendar_quarter.apply(lambda x: int(x))
fail_df = fail_df[(fail_df.calendar_quarter != 4)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v603(self):
"""An invalid Contact Person's Telephone Number was provided.
1) The required format for the Contact Person's Telephone Number is 999-999-9999, and it cannot be left blank."""
edit_name = "v603"
field = "contact_tel"
fail_df = self.ts_df[(self.ts_df.contact_tel.map(lambda x: len(x))!=12)|(self.ts_df.contact_tel.map(lambda x: x.replace("-","").isdigit())==False)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v604(self):
"""An invalid Contact Person's Office State was provided. Please review the information below and update your file accordingly.
1) Contact Person's Office State must be a two letter state code, and cannot be left blank."""
field = "office_state"
edit_name = "v604"
#office code is not valid for US states or territories
fail_df = self.ts_df[~(self.ts_df.office_state.isin(self.state_codes.keys()))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v605(self):
"""An invalid Contact Person's ZIP Code was provided. Please review the information below and update your file accordingly.
1) The required format for the Contact Person's ZIP Code is 12345-1010 or 12345, and it cannot be left blank."""
edit_name = "v605"
field = "office_zip"
fail_df = self.ts_df[~(self.ts_df.office_zip.map(lambda x: len(x) in (5,10)))|(self.ts_df.office_zip.map(lambda x: x.replace("-","").isdigit())==False)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v606(self):
"""The reported Total Number of Entries Contained in Submission is not in the valid format.
1) The required format for the Total Number of Entries Contained in Submission is a whole number that is greater than zero,
and it cannot be left blank."""
field = "lar_entries"
edit_name = "v606"
fail_df = self.ts_df[(self.ts_df.lar_entries.map(lambda x: self.check_number(x, min_val=0))==False)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def v607(self):
"""An invalid Federal Taxpayer Identification Number was provided.
1) The required format for the Federal Taxpayer Identification Number is 99-9999999, and it cannot be left blank."""
edit_name = "v607"
field = "tax_id"
fail_df = self.ts_df[(self.ts_df.tax_id.map(lambda x: len(x))!=10) | (self.ts_df.tax_id.map(lambda x: x.replace("-","").isdigit())==False)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df, row_type="TS")
def s305(self):
"""A duplicate transaction has been reported. No transaction can be an exact duplicate in a LAR file."""
edit_name = "s305"
field = "all"
#dupe_row = self.lar_df.iloc[0:1] #create dupe row for testing
#test_df = pd.concat([self.lar_df, dupe_row]) #merge dupe row into dataframe
fail_df = self.lar_df[self.lar_df.duplicated(keep=False)==True] #pull frame of duplicates
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v608(self):
"""A ULI with an invalid format was provided.
1) The required format for ULI is alphanumeric with at least 23 characters and up to 45 characters,
and it cannot be left blank.
Exempt Filers:
If your institution is reporting a Loan/Application Number, the required format for Loan/Application Number
is alphanumeric with at least 1 character and no more than 22 characters, and it cannot be left blank."""
edit_name = "v608"
field = "ULI"
#if length not between 23 and 45 or if ULI is blank
#get subset of LAR dataframe that fails ULI conditions
#check if LEI present as first 20 digits of ULI
lei = self.lar_df.lei.iloc[0]
#get seperate dataframes for ULI and Loan ID
uli_check_df = self.lar_df[(self.lar_df.uli.apply(lambda x: str(x)[:20]==lei))].copy()
loan_id_check_df = self.lar_df[(self.lar_df.uli.apply(lambda x: str(x)[:20]!=lei))].copy()
#filter each df for failures
uli_fail_df = uli_check_df[(uli_check_df.uli.map(lambda x: len(x)<23))|
(uli_check_df.uli.map(lambda x: len(x))>45)|(uli_check_df.uli=="")].copy()
loan_id_fail_df = loan_id_check_df[(loan_id_check_df.uli=="")|
(loan_id_check_df.uli.apply(lambda x: len(x)>22))].copy()
#recombine dfs
fail_df = pd.concat([uli_fail_df, loan_id_fail_df])
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v609(self):
"""An invalid ULI was reported. Please review the information below and update your file accordingly.
1) Based on the check digit calculation, the ULI contains a transcription error.
This check exempts rows where the first 20 digits of the ULI are not the reported LEI.
If ULI is not required, institution may report a loan id (similar to 2017).
In that situation, this edit is not applicable."""
edit_name = "v609"
field = "ULI"
check_digit = utils.check_digit_gen #establish check digit function alias
#limit check digit checking to records with a ULI
fail_df = self.lar_df[self.lar_df.uli.apply(lambda x: x[:20]==self.lar_df.lei.iloc[0])]
#get dataframe of check digit failures
fail_df = fail_df[fail_df.uli.map(lambda x: str(x)[-2:]) != fail_df.uli.map(lambda x: check_digit(ULI=str(x)[:-2]))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v610_1(self):
"""An invalid date field was reported.
1) Application Date must be either a valid date using YYYYMMDD format or NA, and cannot be left blank."""
edit_name = "v610_1"
field = "app_date"
fail_df = self.lar_df[(self.lar_df.app_date!="NA")&(self.lar_df.app_date.map(lambda x: self.valid_date(x))==False)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v610_2(self):
"""An invalid date field was reported.
2) If Action Taken equals 6, then Application Date must be NA, and the reverse must be true."""
edit_name = "v610_2"
field = "app_date"
fail_df = self.lar_df[((self.lar_df.app_date=="NA")&(self.lar_df.action_taken!="6"))|((self.lar_df.action_taken=="6")&(self.lar_df.app_date!="NA"))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v611(self):
"""An invalid Loan Type was reported.
1) Loan Type must equal 1, 2, 3, or 4, and cannot be left blank."""
edit_name = "v611"
field = "loan_type"
fail_df = self.lar_df[~(self.lar_df.loan_type.isin(("1", "2", "3", "4")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v612_1(self):
"""An invalid Loan Purpose was reported.
1) Loan Purpose must equal 1, 2, 31, 32, 4, or 5 and cannot be left blank."""
edit_name = "v612_1"
field = "loan_purpose"
fail_df = self.lar_df[~self.lar_df.loan_purpose.isin(("1", "2", "31", "32", "4", "5"))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v612_2(self):
"""An invalid Loan Purpose was reported.
2) If Preapproval equals 1, then Loan Purpose must equal 1."""
field = "loan_purpose"
edit_name = "v612_2"
fail_df = self.lar_df[((self.lar_df.preapproval=="1")&(self.lar_df.loan_purpose!="1"))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v613_1(self):
"""An invalid Preapproval data field was provided.
1) Preapproval must equal 1 or 2, and cannot be left blank."""
edit_name = "v613_1"
field = "preapproval"
fail_df = self.lar_df[~(self.lar_df.preapproval.isin(("1", "2")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v613_2(self):
"""An invalid Preapproval data field was provided.
2) If Action Taken equals 7 or 8, then Preapproval must equal 1."""
field = "preapproval"
edit_name = "v613_2"
fail_df = self.lar_df[(self.lar_df.action_taken.isin(("7", "8")))&(self.lar_df.preapproval!="1")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v613_3(self):
"""An invalid Preapproval data field was provided.
3) If Action Taken equals 3, 4, 5 or 6, then Preapproval must equal 2."""
field = "preapproval"
edit_name = "v613_3"
fail_df = self.lar_df[(self.lar_df.action_taken.isin(("3", "4", "5", "6")))&(self.lar_df.preapproval!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v613_4(self):
"""An invalid Preapproval data field was provided.
4) If Preapproval equals 1, then Action Taken must equal 1, 2, 7 or 8."""
field = "preapproval"
edit_name = "v613_4"
fail_df = self.lar_df[(self.lar_df.preapproval=="1")&(~(self.lar_df.action_taken.isin(("1","2","7","8"))))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v614_1(self):
"""An invalid Preapproval was provided.
1) If Loan Purpose equals 2, 4, 31, 32, or 5, then Preapproval must equal 2."""
field = "preapproval"
edit_name = "v614_1"
fail_df = self.lar_df[(self.lar_df.loan_purpose.isin(("2", "4", "31", "32", "5")))&(self.lar_df.preapproval!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v614_2(self):
"""An invalid Preapproval was provided.
2) If Multifamily Affordable Units is a number, then Preapproval must equal 2."""
field = "preapproval"
edit_name = "v614_2"
fail_df = self.lar_df[(self.lar_df.affordable_units.map(lambda x: x.isdigit())==True)&(self.lar_df.preapproval!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v614_3(self):
"""An invalid Preapproval was provided.
3) If Reverse Mortgage equals 1, then Preapproval must equal 2."""
field = "preapproval"
edit_name = "v614_3"
fail_df = self.lar_df[(self.lar_df.reverse_mortgage=="1")&(self.lar_df.preapproval!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v614_4(self):
"""An invalid Preapproval was provided.
4) If Open-End Line of Credit equals 1, then Preapproval must equal 2."""
field = "preapproval"
edit_name = "v614_4"
fail_df = self.lar_df[(self.lar_df.open_end_credit=="1")&(self.lar_df.preapproval!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v615_1(self):
"""An invalid Construction Method was reported.
1) Construction Method must equal 1 or 2, and cannot be left blank."""
field = "const_method"
edit_name = "v615_1"
fail_df = self.lar_df[~self.lar_df.const_method.isin(("1","2"))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v615_2(self):
"""An invalid Construction Method was reported.
2) If Manufactured Home Land Property Interest equals 1, 2, 3 or 4, then Construction Method must equal 2."""
field = "const_method"
edit_name = "v615_2"
fail_df = self.lar_df[(self.lar_df.manufactured_interest.isin(("1","2", "3","4")))&(self.lar_df.const_method!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v615_3(self):
"""An invalid Construction Method was reported.
3) If Manufactured Home Secured Property Type equals 1 or 2 then Construction Method must equal 2."""
field = "const_method"
edit_name = "v615_3"
fail_df = self.lar_df[(self.lar_df.manufactured_type.isin(("1","2")))&(self.lar_df.const_method!="2")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v616(self):
"""An invalid Occupancy Type was reported.
1) Occupancy Type must equal 1, 2, or 3, and cannot be left blank."""
field = "occupancy"
edit_name = "v616"
fail_df = self.lar_df[~(self.lar_df.occ_type.isin(("1","2","3")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v617(self):
"""An invalid Loan Amount was reported.
1) Loan Amount must be a number greater than 0, and cannot be left blank."""
field = "loan_amount"
edit_name = "v617"
fail_df = self.lar_df.copy()
fail_df["amount"] = fail_df.loan_amount
fail_df.amount = fail_df.amount.map(lambda x: 0 if x == "" else x)
fail_df = fail_df[(fail_df.amount.map(lambda x: float(x))<=0)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v618(self):
"""An invalid Action Taken was reported.
1) Action Taken must equal 1, 2, 3, 4, 5, 6, 7, or 8, and cannot be left blank."""
field = "action_taken"
edit_name = "v618"
fail_df = self.lar_df[~(self.lar_df.action_taken.isin(("1","2","3","4","5","6","7","8")))|(self.lar_df.action_taken=="")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v619_1(self):
"""An invalid Action Taken Date was reported.
1) Action Taken Date must be a valid date using YYYYMMDD format, and cannot be left blank."""
field = "action_date"
edit_name = "v619_1"
fail_df = self.lar_df[(self.lar_df.action_date=="")|(self.lar_df.action_date.map(lambda x: self.valid_date(x))==False)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v619_2(self):
"""An invalid Action Taken Date was reported.
2) The Action Taken Date must be in the reporting year."""
field = "action_date"
edit_name = "v619_2"
fail_df = self.lar_df[(self.lar_df.action_date.map(lambda x: str(x)[:4])!=str(self.year))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v619_3(self):
"""An invalid Action Taken Date was reported.
3) The Action Taken Date must be on or after the Application Date."""
field = "action_date"
edit_name = "v619_3"
fail_df = self.lar_df[(self.lar_df.action_date < self.lar_df.app_date)&(self.lar_df.app_date!="NA")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v620(self):
"""An invalid Street Address was provided.
1) Street Address cannot be left blank."""
field = "street_address"
edit_name = "v620"
fail_df = self.lar_df[(self.lar_df.street_address=="")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v621(self):
"""An invalid City was provided.
1) City cannot be left blank."""
field = "city"
edit_name = "v621"
fail_df = self.lar_df[(self.lar_df.city=="")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v622_1(self):
"""An invalid City, State and/or Zip Code were provided.
1) If Street Address was not reported NA, then City, State, and Zip Code must be provided, and not reported NA.
Impact of S2155: Update to: 1) If Street Address was not reported NA or Exempt,
then City, State and Zip Code must be provided, and not reported NA."""
field = "city"
edit_name = "v622_1"
fail_df = self.lar_df[~(self.lar_df.street_address.isin(["NA", "Exempt"]))&(self.lar_df.city=="NA")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v622_2(self):
"""An invalid City, State and/or Zip Code were provided.
1) If Street Address was not reported NA, then City, State, and Zip Code must be provided, and not reported NA.
Impact of S2155: Update to: 1) If Street Address was not reported NA or Exempt,
then City, State and Zip Code must be provided, and not reported NA."""
field = "state"
edit_name = "v622_2"
fail_df = self.lar_df[~(self.lar_df.street_address.isin(["NA", "Exempt"]))&(self.lar_df.state=="NA")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v622_3(self):
"""An invalid City, State and/or Zip Code were provided.
1) If Street Address was not reported NA, then City, State, and Zip Code must be provided, and not reported NA.
Impact of S2155: Update to: 1) If Street Address was not reported NA or Exempt,
then City, State and Zip Code must be provided, and not reported NA."""
field = "zip_code"
edit_name = "v622_3"
fail_df = self.lar_df[~(self.lar_df.street_address.isin(["NA", "Exempt"]))&(self.lar_df.zip_code=="NA")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v623(self):
"""An invalid State was provided.
1) State must be either a two letter state code or NA, and cannot be left blank."""
field = "state"
edit_name = "v623"
fail_df = self.lar_df[~(self.lar_df.state.isin(self.state_codes))|(self.lar_df.state=="NA")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v624(self):
"""An invalid Zip Code was provided.
1) The required format for Zip Code is 12345-1010 or 12345 or NA, and it cannot be left blank.
Impact of S2155: Update to 1) The required format for Zip Code is 12345-1010, 12345,
Exempt, or NA, and it cannot be left blank."""
field = "zip_code"
edit_name = "v624"
fail_df = self.lar_df[((self.lar_df.zip_code.map(lambda x: len(x)
not in (10, 5)))|(self.lar_df.zip_code.map(lambda x: x.replace("-","").isdigit())==False))
&(~self.lar_df.zip_code.isin(["NA", "Exempt"]))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v625_1(self):
"""An invalid Census Tract was provided.
1) The required format for Census Tract is an eleven digit number or NA, and it cannot be left blank."""
field = "tract"
edit_name = "v625_1"
fail_df = self.lar_df[(self.lar_df.tract!="NA")&((self.lar_df.tract.map(lambda x: len(x)!=11))|(self.lar_df.tract.map(lambda x: x.isdigit())==False))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v625_2(self):
"""An invalid Census Tract was provided.
2) If Census Tract is not reported NA, then the number provided must be a valid census tract number defined by the U.S. Census Bureau."""
field = "tract"
edit_name = "v625_2"
fail_df = self.lar_df[(self.lar_df.tract!="NA")&(~self.lar_df.tract.isin(self.tracts))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v626(self):
"""v626 An invalid County was provided.
1) The required format for County is a five digit FIPS code or NA, and it cannot be left blank"""
field = "county"
edit_name = "v626"
fail_df = self.lar_df[(self.lar_df.county!="NA")&((self.lar_df.county.map(lambda x: len(x))!=5)|(self.lar_df.county.map(lambda x: x.isdigit())==False))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v627(self):
"""An invalid Census Tract or County was provided.
1) If County and Census Tract are not reported NA, they must be a valid combination of information.
The first five digits of the Census Tract must match the reported five digit County FIPS code."""
field = "tract/county"
edit_name = "v627"
fail_df = self.lar_df[((self.lar_df.county!="NA")&(self.lar_df.tract!="NA"))&(self.lar_df.tract.map(lambda x: str(x)[:5])!=self.lar_df.county)]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v628_1(self):
"""An invalid Ethnicity data field was reported.
1) Ethnicity of Applicant or Borrower: 1 must equal 1, 11, 12, 13, 14, 2, 3, or 4, and cannot be left blank,
unless an ethnicity is provided in Ethnicity of Applicant or Borrower: Free Form Text Field for Other Hispanic or Latino."""
field = "app_eth_1"
edit_name = "v628_1"
fail_df = self.lar_df[~(self.lar_df.app_eth_1.isin(("1","11", "12", "13", "14", "2", "3","4")))|((self.lar_df.app_eth_free=="")&(self.lar_df.app_eth_1==""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v628_2(self):
"""An invalid Ethnicity data field was reported.
2) Ethnicity of Applicant or Borrower: 2 must equal 1, 11, 12, 13, 14, 2, or be left blank."""
field = "app ethnicities 2-4"
edit_name = "v628_2"
fail_df = self.lar_df[~(self.lar_df.app_eth_2.isin(("1","11", "12", "13", "14", "2","")))|
~(self.lar_df.app_eth_3.isin(("1","11", "12", "13", "14", "2","")))|
~(self.lar_df.app_eth_4.isin(("1","11", "12", "13", "14", "2","")))|
~(self.lar_df.app_eth_5.isin(("1","11", "12", "13", "14", "2","")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v628_3(self):
"""An invalid Ethnicity data field was reported.
3) Each Ethnicity of Applicant or Borrower code can only be reported once."""
field = "applicant ethnicities"
edit_name = "v628_3"
dupe_fields = ["app_eth_1", "app_eth_2", "app_eth_3", "app_eth_4", "app_eth_5"]
fail_df = self.lar_df[(self.lar_df.apply(lambda x: self.check_dupes(x, fields=dupe_fields), axis=1)=="fail")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v628_4(self):
"""An invalid Ethnicity data field was reported.
4) If Ethnicity of Applicant or Borrower: 1 equals 3 or 4; then Ethnicity of Applicant or Borrower: 2; Ethnicity of Applicant or Borrower: 3;
Ethnicity of Applicant or Borrower: 4; Ethnicity of Applicant or Borrower: 5 must be left blank."""
field = "applicant ethnicities"
edit_name = "v628_4"
fail_df = self.lar_df[(self.lar_df.app_eth_1.isin(("3","4")))&((self.lar_df.app_eth_2!="")|(self.lar_df.app_eth_3!="")|(self.lar_df.app_eth_4!="")|(self.lar_df.app_eth_5!=""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v629_1(self):
"""An invalid Ethnicity data field was reported.
1) Ethnicity of Applicant or Borrower Collected on the Basis of Visual Observation or Surname must equal 1, 2, or 3, and cannot be left blank."""
field = "app ethnicity basis"
edit_name = "v629_1"
fail_df = self.lar_df[~(self.lar_df.app_eth_basis.isin(("1", "2", "3")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v629_2(self):
"""An invalid Ethnicity data field was reported.
2) If Ethnicity of Applicant or Borrower Collected on the Basis of Visual Observation or Surname equals 1,
then Ethnicity of Applicant or Borrower: 1 must equal 1 or 2; and Ethnicity of Applicant or Borrower: 2 must equal 1, 2 or be left blank;
and Ethnicity of Applicant or Borrower: 3; Ethnicity of Applicant or Borrower: 4; and Ethnicity of Applicant or Borrower: 5 must all be left blank."""
field = "app ethnicity basis"
edit_name = "v629_2"
fail_df = self.lar_df[(self.lar_df.app_eth_basis=="1")&(~(self.lar_df.app_eth_1.isin(("1","2")))|(~self.lar_df.app_eth_2.isin(("1", "2", "")))|
(self.lar_df.app_eth_3!="")|(self.lar_df.app_eth_4!="")|(self.lar_df.app_eth_5!=""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v629_3(self):
"""An invalid Ethnicity data field was reported.
3) If Ethnicity of Applicant or Borrower Collected on the Basis of Visual Observation or Surname equals 2 then Ethnicity of Applicant or Borrower: 1 must equal 1, 11, 12, 13, 14, 2 or 3."""
field = "app ethnicity basis"
edit_name = "v629_3"
fail_df = self.lar_df[(self.lar_df.app_eth_basis=="2")&(~self.lar_df.app_eth_1.isin(("1", "11", "12", "13", "14", "2", "3")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v630_1(self):
"""An invalid Ethnicity data field was reported.
1) If Ethnicity of Applicant or Borrower: 1 equals 4, then Ethnicity of Applicant or Borrower Collected on the Basis of Visual Observation or Surname must equal 3."""
field = "app ethnicity basis"
edit_name = "v630_1"
fail_df = self.lar_df[(self.lar_df.app_eth_basis!="3")&(self.lar_df.app_eth_1=="4")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v630_2(self):
"""An invalid Ethnicity data field was reported.
2) If Ethnicity of Applicant or Borrower Collected on the Basis of Visual Observation or Surname equals 3, then
Ethnicity of Applicant or Borrower: 1 must equal 3 or 4."""
field = "app ethnicity basis"
edit_name = "v630_2"
fail_df = self.lar_df[(self.lar_df.app_eth_basis=="3")&(~self.lar_df.app_eth_1.isin(("3","4")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v631_1(self):
"""An invalid Ethnicity data field was reported.
1) Ethnicity of Co-Applicant or Co-Borrower: 1 must equal 1, 11, 12, 13, 14, 2, 3, 4, or 5, and cannot be left blank,
unless an ethnicity is provided in Ethnicity of Co-Applicant or Co-Borrower: Free Form Text Field for Other Hispanic or Latino."""
field = "co-app ethnicities"
edit_name = "v631_1"
fail_df = self.lar_df[(self.lar_df.co_app_eth_free=="")&(~self.lar_df.co_app_eth_1.isin(("1","11","12","13", "14", "2", "3", "4", "5")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v631_2(self):
"""An invalid Ethnicity data field was reported.
2) Ethnicity of Co-Applicant or Co-Borrower: 2; Ethnicity of Co-Applicant or Co-Borrower: 3; Ethnicity of Co-Applicant or Co-Borrower: 4;
Ethnicity of Co- Applicant or Co-Borrower: 5 must equal 1, 11, 12, 13, 14, 2, or be left blank."""
field = "co-app ethnicities"
edit_name = "v631_2"
fail_df = self.lar_df[(~self.lar_df.co_app_eth_2.isin(("1", "11", "12", "13", "14", "2", "")))|(~self.lar_df.co_app_eth_3.isin(("1", "11", "12", "13", "14", "2", "")))|
(~self.lar_df.co_app_eth_4.isin(("1", "11", "12", "13", "14", "2", "")))|(~self.lar_df.co_app_eth_5.isin(("1", "11", "12", "13", "14", "2", "")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v631_3(self):
"""An invalid Ethnicity data field was reported.
3) Each Ethnicity of Co-Applicant or Co-Borrower code can only be reported once."""
field = "Co-App Ethnicities"
edit_name = "v631_3"
dupe_fields = ["co_app_eth_1", "co_app_eth_2", "co_app_eth_3", "co_app_eth_4", "co_app_eth_5"]
fail_df = self.lar_df[(self.lar_df.apply(lambda x: self.check_dupes(x, fields=dupe_fields), axis=1)=="fail")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v631_4(self):
"""An invalid Ethnicity data field was reported.
4) If Ethnicity of Co-Applicant or Co-Borrower: 1 equals 3, 4, or 5; then
Ethnicity of Co-Applicant or Co-Borrower: 2; Ethnicity of Co-Applicant or Co- Borrower: 3; Ethnicity of Co-Applicant or Co- Borrower: 4;
Ethnicity of Co-Applicant or Co- Borrower: 5 must be left blank."""
field = "Co-App Ethnicities"
edit_name = "v631_4"
fail_df = self.lar_df[(self.lar_df.co_app_eth_1.isin(("3", "4", "5")))&((self.lar_df.co_app_eth_2!="")|(self.lar_df.co_app_eth_3!="")|
(self.lar_df.co_app_eth_4!="")|(self.lar_df.co_app_eth_5!=""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v632_1(self):
"""An invalid Ethnicity data field was reported.
1) ethnicity of co-applicant or co-borrow collected on the basis of visual observation or surname must equal 1,2,3,4 and cannot be left blank"""
field = "Co-App Ethnicity Basis"
edit_name = "v632_1"
fail_df = self.lar_df[~(self.lar_df.co_app_eth_basis.isin(("1", "2", "3", "4")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v632_2(self):
"""An invalid Ethnicity data field was reported.
2) if ethnicity of co-applicant or co-borrower collected on the basis of visual observation or surname equals 1;
then ethnicity of co-applicant or co-borrower: 1 must equal 1 or 2; and ethnicity of co-applicant or co-borrower: 2 must equal 1 or 2 or be blank
and the remaining co borrower ethnicity fields must be left blank."""
field = "Co-App Ethnicity Basis"
edit_name = "v632_2"
fail_df = self.lar_df[(self.lar_df.co_app_eth_basis=="1")&(~(self.lar_df.co_app_eth_1.isin(("1", "2")))|(~self.lar_df.co_app_eth_2.isin(("1", "2")))|
(self.lar_df.co_app_eth_3!="")|(self.lar_df.co_app_eth_4!="")|(self.lar_df.co_app_eth_5!=""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v632_3(self):
"""An invalid Ethnicity data field was reported.
2) if ethnicity of co-applicant or co-borrower collected on the basis of visual observation or surname equals 2;
then ethnicity of co-applicant or co-borrower: 1 must equal 1, 11, 12, 13, 14, 2 or 3."""
field = "Co-App Ethnicity Basis"
edit_name = "v632_3"
fail_df = self.lar_df[(self.lar_df.co_app_eth_basis=="2")&(~self.lar_df.co_app_eth_1.isin(("1", "11", "12", "13", "14", "2", "3")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v633(self):
"""An invalid Ethnicity data field was reported.
1) If Ethnicity of Co-Applicant or Co-Borrower: 1 equals 4,
then Ethnicity of Co-Applicant or Co- Borrower Collected on the Basis of Visual Observation or Surname must equal 3."""
field = "Co-App Ethnicity basis"
edit_name = "v633_1"
fail_df = self.lar_df[(self.lar_df.co_app_eth_1=="4")&(self.lar_df.co_app_eth_basis!="3")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v634(self):
"""An invalid Ethnicity data field was reported.
1) If Ethnicity of Co-Applicant or Co-Borrower: 1 equals 5,
then Ethnicity of Co-Applicant or Co- Borrower Collected on the Basis of Visual Observation or Surname must equal 4, and the reverse must be true."""
field = "Co-App Ethnicity Basis"
edit_name = "v634"
fail_df = self.lar_df[((self.lar_df.co_app_eth_1=="5")&(self.lar_df.co_app_eth_basis!="4"))|
((self.lar_df.co_app_eth_basis=="4")&(self.lar_df.co_app_eth_1!="5"))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v635_1(self):
"""An invalid Race data field was reported.
1) Race of Applicant or Borrower: 1 must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, 6, or 7, and cannot be left blank,
unless a race is provided in Race of Applicant or Borrower: Free Form Text Field for American Indian or Alaska Native Enrolled or Principal Tribe,
Race of Applicant or Borrower: Free Form Text Field for Other Asian, or Race of Applicant or Borrower: Free Form Text Field for Other Pacific Islander."""
field = "App Race 1"
edit_name = "v635_1"
fail_df = self.lar_df[(~self.lar_df.app_race_1.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "6", "7")))|
((self.lar_df.app_race_1=="")&((self.lar_df.app_race_native_text=="")&(self.lar_df.app_race_islander_text=="")&(self.lar_df.app_race_asian_text=="")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v635_2(self):
"""An invalid Race data field was reported.
2) Race of Applicant or Borrower: 2; Race of Applicant or Borrower: 3; Race of Applicant or Borrower: 4;
Race of Applicant or Borrower: 5 must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, or be left blank."""
field = "App Race 2 - 5"
edit_name = "v635_2"
fail_df = self.lar_df[~(self.lar_df.app_race_2.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))|
~(self.lar_df.app_race_3.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))|
~(self.lar_df.app_race_4.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))|
~(self.lar_df.app_race_5.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v635_3(self):
"""An invalid Race data field was reported.
3) Each Race of Applicant or Borrower code can only be reported once."""
field = "Applicant Races"
edit_name = "v635_3"
race_fields = ["app_race_1", "app_race_2", "app_race_3", "app_race_4", "app_race_5"]
fail_df = self.lar_df[(self.lar_df.apply(lambda x: self.check_dupes(x, fields=race_fields), axis=1)=="fail")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v635_4(self):
"""An invalid Race data field was reported.
4) If Race of Applicant or Borrower: 1 equals 6 or 7; then Race of Applicant or Borrower: 2;
Race of Applicant or Borrower: 3; Race of Applicant or Borrower: 4; Race of Applicant or Borrower: 5 must all be left blank."""
field = "Applicant Races"
edit_name = "v635_4"
fail_df = self.lar_df[(self.lar_df.app_race_1.isin(("6", "7")))&((self.lar_df.app_race_2!="")|(self.lar_df.app_race_3!="")|(self.lar_df.app_race_4!="")
|(self.lar_df.app_race_5!=""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v636_1(self):
"""An invalid Race data field was reported.
1) Race of Applicant or Borrower Collected on the Basis of Visual Observation or Surname must equal 1, 2, or 3, and cannot be left blank."""
field = "Applicant Race Basis"
edit_name = "v636_1"
fail_df = self.lar_df[~(self.lar_df.app_race_basis.isin(("1", "2", "3")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v636_2(self):
"""An invalid Race data field was reported.
2) If Race of Applicant or Borrower Collected on the Basis of Visual Observation or Surname equals 1;
then Race of Applicant or Borrower: 1 must equal 1, 2, 3, 4, or 5; and Race of Applicant or Borrower: 2; Race of Applicant or Borrower: 3;
Race of Applicant or Borrower: 4; Race of Applicant or Borrower: 5 must equal 1, 2, 3, 4, or 5, or be left blank."""
field = "Applicant Race Basis"
edit_name = "v636_2"
fail_df = self.lar_df[(self.lar_df.app_race_basis=="1")&((~self.lar_df.app_race_1.isin(("1", "2", "3", "4", "5")))|
(~self.lar_df.app_race_2.isin(("1", "2", "3", "4", "5","")))|(~self.lar_df.app_race_3.isin(("1", "2", "3", "4", "5","")))|
(~self.lar_df.app_race_4.isin(("1", "2", "3", "4", "5","")))|(~self.lar_df.app_race_5.isin(("1", "2", "3", "4", "5",""))))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v636_3(self):
"""An invalid Race data field was reported.
3) If Race of Applicant or Borrower Collected on the Basis of Visual Observation or Surname equals 2,
Race of Applicant or Borrower: 1 must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5 or 6; and
Race of Applicant or Borrower: 2; Race of Applicant or Borrower: 3; Race of Applicant or Borrower: 4;
Race of Applicant or Borrower: 5 must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, or be left blank."""
field = "Applicant Race Basis"
edit_name = "v636_3"
app_1_races = ["1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "6"]
app_n_races = app_1_races[:-1]
app_n_races.append("")
fail_df = self.lar_df[(self.lar_df.app_race_basis=="2")&((~self.lar_df.app_race_1.isin(app_1_races))|
(~self.lar_df.app_race_2.isin(app_n_races))|(~self.lar_df.app_race_3.isin(app_n_races))|
(~self.lar_df.app_race_4.isin(app_n_races))|(~self.lar_df.app_race_4.isin(app_n_races)))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v637_1(self):
"""An invalid Race data field was reported.
1) If Race of Applicant or Borrower: 1 equals 7, then Race of Applicant or Borrower Collected on the Basis of Visual Observation or Surname must equal 3."""
field = "Applicant Race Basis"
edit_name = "v637_1"
fail_df = self.lar_df[(self.lar_df.app_race_1=="7")&(self.lar_df.app_race_basis!="3")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v637_2(self):
"""An invalid Race data field was reported.
2) If Race of Applicant or Borrower Collected on the Basis of Visual Observation or Surname equals 3; then Race of Applicant or Borrower: 1 must equal 6 or 7."""
field = "Applicant Race 1"
edit_name ="v637_2"
fail_df = self.lar_df[(self.lar_df.app_race_basis=="3")&(~self.lar_df.app_race_1.isin(("6", "7")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v638_1(self):
"""An invalid Race data field was reported.
1) Race of Co-Applicant or Co-Borrower: 1 must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, 6, 7, or 8, and cannot be left blank,
unless a race is provided in Race of Co-Applicant or Co- Borrower: Free Form Text Field for American Indian or Alaska Native Enrolled or Principal Tribe,
Race of Co-Applicant or Co-Borrower: Free Form Text Field for Other Asian, or
Race of Co-Applicant or Co- Borrower: Free Form Text Field for Other Pacific Islander."""
field = "Co-Applicant Race 1"
edit_name = "v638_1"
fail_df = self.lar_df[(~self.lar_df.co_app_race_1.isin(("1", "2", "21", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "6", "7", "8")))&
((self.lar_df.co_app_race_1=="")&((self.lar_df.co_app_race_native_text=="")&(self.lar_df.co_app_race_islander_text=="")&
(self.lar_df.co_app_race_asian_text=="")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v638_2(self):
"""An invalid Race data field was reported.
2) Race of Co-Applicant or Co-Borrower: 2; Race of Co-Applicant or Co-Borrower: 3;
Race of Co- Applicant or Co-Borrower: 4; Race of Co-Applicant or Co-Borrower: 5
must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, or be left blank."""
field = "Co-Applicant Race 2-5"
edit_name = "v638_2"
fail_df = self.lar_df[~(self.lar_df.co_app_race_2.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))|
~(self.lar_df.co_app_race_3.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))|
~(self.lar_df.co_app_race_4.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))|
~(self.lar_df.co_app_race_5.isin(("1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v638_3(self):
"""An invalid Race data field was reported.
3) Each Race of Co-Applicant or Co-Borrower code can only be reported once."""
field = "Co-Applicant Races"
edit_name = "v638_3"
race_fields = ["co_app_race_1", "co_app_race_2", "co_app_race_3", "co_app_race_4", "co_app_race_5"]
fail_df = self.lar_df[(self.lar_df.apply(lambda x: self.check_dupes(x, fields=race_fields), axis=1)=="fail")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v638_4(self):
"""An invalid Race data field was reported.
4) If Race of Co-Applicant or Co-Borrower: 1 equals 6, 7, or 8, then Race of Co-Applicant or Co-Borrower: 2;
Race of Co-Applicant or Co-Borrower: 3; Race of Co-Applicant or Co-Borrower: 4; and Race of Co- Applicant or Co-Borrower: 5 must be left blank."""
field = "Co-Applicant Races"
edit_name = "v638_4"
fail_df = self.lar_df[(self.lar_df.co_app_race_1.isin(("6", "7", "8")))&((self.lar_df.co_app_race_2!="")|(self.lar_df.co_app_race_3!="")|(self.lar_df.co_app_race_4!="")
|(self.lar_df.co_app_race_5!=""))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v639_1(self):
"""An invalid Race data field was reported.
1) Race of Co-Applicant or Co-Borrower Collected on the Basis of Visual Observation or Surname must equal 1, 2, 3, or 4, and cannot be left blank."""
field = "Co-Applicant Race Basis"
edit_name = "v639_1"
fail_df = self.lar_df[(~self.lar_df.co_app_race_basis.isin(("1", "2", "3", "4")))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v639_2(self):
"""An invalid Race data field was reported.
2) If Race of Co-Applicant or Co-Borrower Collected on the Basis of Visual Observation or Surname equals 1,
then Race of Co-Applicant or Co-Borrower: 1must equal 1,2,3,4,or 5; and Race of Co- Applicant or Co-Borrower: 2;
Race of Co-Applicant or Co-Borrower: 3; Race of Co-Applicant or Co- Borrower: 4;
Race of Co-Applicant or Co-Borrower: 5 must equal 1, 2, 3, 4, or 5, or be left blank."""
field = "Co-Applicant Race Basis"
edit_name = "v639_2"
fail_df = self.lar_df[(self.lar_df.co_app_race_basis=="1")&((~self.lar_df.co_app_race_1.isin(("1", "2", "3", "4", "5", "")))|
(~self.lar_df.co_app_race_2.isin(("1", "2", "3", "4", "5", "")))|(~self.lar_df.co_app_race_3.isin(("1", "2", "3", "4", "5", "")))|
(~self.lar_df.co_app_race_4.isin(("1", "2", "3", "4", "5", "")))|(~self.lar_df.co_app_race_5.isin(("1", "2", "3", "4", "5", ""))))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v639_3(self):
"""An invalid Race data field was reported.
3) If Race of Co-Applicant or Co-Borrower Collected on the Basis of Visual Observation or Surname equals 2, then
Race of Co-Applicant or Co-Borrower: 1must equal 1,2,21,22,23,24,25,26,27,3,4,41, 42, 43, 44, 5 or 6; and Race of Co-Applicant or Co- Borrower: 2;
Race of Co-Applicant or Co-Borrower: 3; Race of Co-Applicant or Co-Borrower: 4; Race of Co- Applicant or Co-Borrower: 5
must equal 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, or be left blank."""
field = "Co-Applicant Race Basis"
edit_name = "v639_3"
race_1 = ["1", "2", "21", "22", "23", "24", "25", "26", "27", "3", "4", "41", "42", "43", "44", "5", "6"]
race_n = race_1[:-1]
race_n.append("")
fail_df = self.lar_df[(self.lar_df.co_app_race_basis=="2")&((~self.lar_df.co_app_race_1.isin(race_1))|
(~self.lar_df.co_app_race_2.isin(race_n))|(~self.lar_df.co_app_race_3.isin(race_n))|(~self.lar_df.co_app_race_4.isin(race_n))|
(~self.lar_df.co_app_race_5.isin(race_n)))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v640(self):
"""An invalid Race data field was reported.
If Race of Co-Applicant or Co-Borrower: 1 equals 7, then
Race of Co-Applicant or Co-Borrower Collected on the Basis of Visual Observation or Surname must equal 3."""
field = "Co-Applicant Race Basis"
edit_name = "v640_1"
fail_df = self.lar_df[(self.lar_df.co_app_race_1=="7")&(self.lar_df.co_app_race_basis!="3")]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v641(self):
"""An invalid Race data field was reported.
1) If Race of Co-Applicant or Co-Borrower: 1 equals 8, then
Race of Co-Applicant or Co-Borrower Collected on the Basis of Visual Observation or Surname must equal 4, and the reverse must be true."""
field = "Co-Applicant Race Basis"
edit_name = "v641"
fail_df = self.lar_df[((self.lar_df.co_app_race_1=="8")&(self.lar_df.co_app_race_basis!="4"))|
((self.lar_df.co_app_race_basis=="4")&(self.lar_df.co_app_race_1!="8"))]
self.results_wrapper(edit_name=edit_name, field_name=field, fail_df=fail_df)
def v642_1(self):
"""An invalid Sex data field was reported.
1) Sex of Applicant or Borrower must equal 1, 2, 3, 4, or 6, and cannot be left blank."""
field = "Applicant Sex"
edit_name = "v642_1"