Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_clean_loan_info.py 16 KB

You have to be logged in to leave a comment. Sign In
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
  1. '''
  2. Tests for clean_loan_info.py which contains functions used in 04_clean_loan_info.py
  3. '''
  4. import numpy as np
  5. import pandas as pd
  6. import pandas.api.types as ptypes
  7. from lendingclub.csv_preparation import clean_loan_info as cli
  8. def test_loan_info_fmt_date():
  9. test_cases = [
  10. pd.DataFrame({
  11. 'id': {
  12. 856: 141066548
  13. },
  14. 'grade': {
  15. 856: 'A'
  16. },
  17. 'sub_grade': {
  18. 856: 'A4'
  19. },
  20. 'emp_title': {
  21. 856: 'Remote Storage Cataloger'
  22. },
  23. 'emp_length': {
  24. 856: '10+ years'
  25. },
  26. 'home_ownership': {
  27. 856: 'MORTGAGE'
  28. },
  29. 'verification_status': {
  30. 856: 'Not Verified'
  31. },
  32. 'issue_d': {
  33. 856: 'Sep-2018'
  34. },
  35. 'loan_status': {
  36. 856: 'Current'
  37. },
  38. 'pymnt_plan': {
  39. 856: 'n'
  40. },
  41. 'url': {
  42. 856:
  43. 'https://lendingclub.com/browse/loanDetail.action?loan_id=141066548'
  44. },
  45. 'desc': {
  46. 856: np.nan
  47. },
  48. 'purpose': {
  49. 856: 'credit_card'
  50. },
  51. 'title': {
  52. 856: 'Credit card refinancing'
  53. },
  54. 'zip_code': {
  55. 856: '488xx'
  56. },
  57. 'addr_state': {
  58. 856: 'MI'
  59. },
  60. 'earliest_cr_line': {
  61. 856: 'Sep-1978'
  62. },
  63. 'revol_util': {
  64. 856: '27.3%'
  65. },
  66. 'initial_list_status': {
  67. 856: 'w'
  68. },
  69. 'last_pymnt_d': {
  70. 856: 'Aug-2019'
  71. },
  72. 'next_pymnt_d': {
  73. 856: 'Sep-2019'
  74. },
  75. 'last_credit_pull_d': {
  76. 856: 'Aug-2019'
  77. },
  78. 'application_type': {
  79. 856: 'Individual'
  80. },
  81. 'verification_status_joint': {
  82. 856: np.nan
  83. },
  84. 'sec_app_earliest_cr_line': {
  85. 856: np.nan
  86. },
  87. 'hardship_flag': {
  88. 856: 'N'
  89. },
  90. 'hardship_type': {
  91. 856: np.nan
  92. },
  93. 'hardship_reason': {
  94. 856: np.nan
  95. },
  96. 'hardship_status': {
  97. 856: np.nan
  98. },
  99. 'hardship_start_date': {
  100. 856: np.nan
  101. },
  102. 'hardship_end_date': {
  103. 856: np.nan
  104. },
  105. 'payment_plan_start_date': {
  106. 856: np.nan
  107. },
  108. 'hardship_loan_status': {
  109. 856: np.nan
  110. },
  111. 'debt_settlement_flag': {
  112. 856: 'N'
  113. },
  114. 'debt_settlement_flag_date': {
  115. 856: np.nan
  116. },
  117. 'settlement_status': {
  118. 856: np.nan
  119. },
  120. 'settlement_date': {
  121. 856: np.nan
  122. },
  123. 'loan_amnt': {
  124. 856: 13000.0
  125. },
  126. 'funded_amnt': {
  127. 856: 13000.0
  128. },
  129. 'funded_amnt_inv': {
  130. 856: 13000.0
  131. },
  132. 'term': {
  133. 856: 36
  134. },
  135. 'int_rate': {
  136. 856: 7.840000152587891
  137. },
  138. 'installment': {
  139. 856: 406.4200134277344
  140. },
  141. 'annual_inc': {
  142. 856: 67000.0
  143. },
  144. 'dti': {
  145. 856: 20.030000686645508
  146. },
  147. 'delinq_2yrs': {
  148. 856: 0.0
  149. },
  150. 'fico_range_low': {
  151. 856: 760.0
  152. },
  153. 'fico_range_high': {
  154. 856: 764.0
  155. },
  156. 'inq_last_6mths': {
  157. 856: 1.0
  158. },
  159. 'mths_since_last_delinq': {
  160. 856: np.nan
  161. },
  162. 'mths_since_last_record': {
  163. 856: np.nan
  164. },
  165. 'open_acc': {
  166. 856: 11.0
  167. },
  168. 'pub_rec': {
  169. 856: 0.0
  170. },
  171. 'revol_bal': {
  172. 856: 13573.0
  173. },
  174. 'total_acc': {
  175. 856: 21.0
  176. },
  177. 'out_prncp': {
  178. 856: 9688.9501953125
  179. },
  180. 'out_prncp_inv': {
  181. 856: 9688.9501953125
  182. },
  183. 'total_pymnt': {
  184. 856: 4067.0400390625
  185. },
  186. 'total_pymnt_inv': {
  187. 856: 4067.0400390625
  188. },
  189. 'total_rec_prncp': {
  190. 856: 3311.050048828125
  191. },
  192. 'total_rec_int': {
  193. 856: 755.989990234375
  194. },
  195. 'total_rec_late_fee': {
  196. 856: 0.0
  197. },
  198. 'recoveries': {
  199. 856: 0.0
  200. },
  201. 'collection_recovery_fee': {
  202. 856: 0.0
  203. },
  204. 'last_pymnt_amnt': {
  205. 856: 406.4200134277344
  206. },
  207. 'last_fico_range_high': {
  208. 856: 794.0
  209. },
  210. 'last_fico_range_low': {
  211. 856: 790.0
  212. },
  213. 'collections_12_mths_ex_med': {
  214. 856: 0.0
  215. },
  216. 'mths_since_last_major_derog': {
  217. 856: np.nan
  218. },
  219. 'policy_code': {
  220. 856: 1.0
  221. },
  222. 'annual_inc_joint': {
  223. 856: np.nan
  224. },
  225. 'dti_joint': {
  226. 856: np.nan
  227. },
  228. 'acc_now_delinq': {
  229. 856: 0.0
  230. },
  231. 'tot_coll_amt': {
  232. 856: 0.0
  233. },
  234. 'tot_cur_bal': {
  235. 856: 108625.0
  236. },
  237. 'open_acc_6m': {
  238. 856: 1.0
  239. },
  240. 'open_act_il': {
  241. 856: 2.0
  242. },
  243. 'open_il_12m': {
  244. 856: 1.0
  245. },
  246. 'open_il_24m': {
  247. 856: 1.0
  248. },
  249. 'mths_since_rcnt_il': {
  250. 856: 10.0
  251. },
  252. 'total_bal_il': {
  253. 856: 18068.0
  254. },
  255. 'il_util': {
  256. 856: 48.0
  257. },
  258. 'open_rv_12m': {
  259. 856: 2.0
  260. },
  261. 'open_rv_24m': {
  262. 856: 2.0
  263. },
  264. 'max_bal_bc': {
  265. 856: 2846.0
  266. },
  267. 'all_util': {
  268. 856: 36.0
  269. },
  270. 'total_rev_hi_lim': {
  271. 856: 49800.0
  272. },
  273. 'inq_fi': {
  274. 856: 1.0
  275. },
  276. 'total_cu_tl': {
  277. 856: 6.0
  278. },
  279. 'inq_last_12m': {
  280. 856: 3.0
  281. },
  282. 'acc_open_past_24mths': {
  283. 856: 4.0
  284. },
  285. 'avg_cur_bal': {
  286. 856: 9875.0
  287. },
  288. 'bc_open_to_buy': {
  289. 856: 35392.0
  290. },
  291. 'bc_util': {
  292. 856: 13.0
  293. },
  294. 'chargeoff_within_12_mths': {
  295. 856: 0.0
  296. },
  297. 'delinq_amnt': {
  298. 856: 0.0
  299. },
  300. 'mo_sin_old_il_acct': {
  301. 856: 216.0
  302. },
  303. 'mo_sin_old_rev_tl_op': {
  304. 856: 480.0
  305. },
  306. 'mo_sin_rcnt_rev_tl_op': {
  307. 856: 5.0
  308. },
  309. 'mo_sin_rcnt_tl': {
  310. 856: 5.0
  311. },
  312. 'mort_acc': {
  313. 856: 2.0
  314. },
  315. 'mths_since_recent_bc': {
  316. 856: 5.0
  317. },
  318. 'mths_since_recent_bc_dlq': {
  319. 856: np.nan
  320. },
  321. 'mths_since_recent_inq': {
  322. 856: 5.0
  323. },
  324. 'mths_since_recent_revol_delinq': {
  325. 856: np.nan
  326. },
  327. 'num_accts_ever_120_pd': {
  328. 856: 0.0
  329. },
  330. 'num_actv_bc_tl': {
  331. 856: 2.0
  332. },
  333. 'num_actv_rev_tl': {
  334. 856: 3.0
  335. },
  336. 'num_bc_sats': {
  337. 856: 6.0
  338. },
  339. 'num_bc_tl': {
  340. 856: 7.0
  341. },
  342. 'num_il_tl': {
  343. 856: 8.0
  344. },
  345. 'num_op_rev_tl': {
  346. 856: 8.0
  347. },
  348. 'num_rev_accts': {
  349. 856: 11.0
  350. },
  351. 'num_rev_tl_bal_gt_0': {
  352. 856: 3.0
  353. },
  354. 'num_sats': {
  355. 856: 11.0
  356. },
  357. 'num_tl_120dpd_2m': {
  358. 856: 0.0
  359. },
  360. 'num_tl_30dpd': {
  361. 856: 0.0
  362. },
  363. 'num_tl_90g_dpd_24m': {
  364. 856: 0.0
  365. },
  366. 'num_tl_op_past_12m': {
  367. 856: 3.0
  368. },
  369. 'pct_tl_nvr_dlq': {
  370. 856: 100.0
  371. },
  372. 'percent_bc_gt_75': {
  373. 856: 0.0
  374. },
  375. 'pub_rec_bankruptcies': {
  376. 856: 0.0
  377. },
  378. 'tax_liens': {
  379. 856: 0.0
  380. },
  381. 'tot_hi_cred_lim': {
  382. 856: 168943.0
  383. },
  384. 'total_bal_ex_mort': {
  385. 856: 31641.0
  386. },
  387. 'total_bc_limit': {
  388. 856: 40700.0
  389. },
  390. 'total_il_high_credit_limit': {
  391. 856: 37696.0
  392. },
  393. 'revol_bal_joint': {
  394. 856: np.nan
  395. },
  396. 'sec_app_fico_range_low': {
  397. 856: np.nan
  398. },
  399. 'sec_app_fico_range_high': {
  400. 856: np.nan
  401. },
  402. 'sec_app_inq_last_6mths': {
  403. 856: np.nan
  404. },
  405. 'sec_app_mort_acc': {
  406. 856: np.nan
  407. },
  408. 'sec_app_open_acc': {
  409. 856: np.nan
  410. },
  411. 'sec_app_revol_util': {
  412. 856: np.nan
  413. },
  414. 'sec_app_open_act_il': {
  415. 856: np.nan
  416. },
  417. 'sec_app_num_rev_accts': {
  418. 856: np.nan
  419. },
  420. 'sec_app_chargeoff_within_12_mths': {
  421. 856: np.nan
  422. },
  423. 'sec_app_collections_12_mths_ex_med': {
  424. 856: np.nan
  425. },
  426. 'sec_app_mths_since_last_major_derog': {
  427. 856: np.nan
  428. },
  429. 'deferral_term': {
  430. 856: np.nan
  431. },
  432. 'hardship_amount': {
  433. 856: np.nan
  434. },
  435. 'hardship_length': {
  436. 856: np.nan
  437. },
  438. 'hardship_dpd': {
  439. 856: np.nan
  440. },
  441. 'orig_projected_additional_accrued_interest': {
  442. 856: np.nan
  443. },
  444. 'hardship_payoff_balance_amount': {
  445. 856: np.nan
  446. },
  447. 'hardship_last_payment_amount': {
  448. 856: np.nan
  449. },
  450. 'settlement_amount': {
  451. 856: np.nan
  452. },
  453. 'settlement_percentage': {
  454. 856: np.nan
  455. },
  456. 'settlement_term': {
  457. 856: np.nan
  458. }
  459. })
  460. ]
  461. test_col = 'issue_d'
  462. cli.loan_info_fmt_date(test_cases[0], test_col)
  463. assert ptypes.is_datetime64_any_dtype(test_cases[0][test_col])
  464. def test_apply_end_d():
  465. test_cases = [
  466. pd.DataFrame({
  467. 'last_pymnt_d': {
  468. 105800: pd.NaT
  469. },
  470. 'issue_d': {
  471. 105800: pd.Timestamp('2018-07-01 00:00:00')
  472. },
  473. 'loan_status': {
  474. 105800: 'charged_off'
  475. },
  476. 'total_pymnt': {
  477. 105800: 3495.889892578125
  478. },
  479. 'total_pymnt_inv': {
  480. 105800: 3495.889892578125
  481. },
  482. 'total_rec_prncp': {
  483. 105800: 0.0
  484. },
  485. 'total_rec_int': {
  486. 105800: 0.0
  487. },
  488. 'total_rec_late_fee': {
  489. 105800: 0.0
  490. },
  491. 'recoveries': {
  492. 105800: 3495.889892578125
  493. },
  494. 'collection_recovery_fee': {
  495. 105800: 629.2601928710938
  496. },
  497. 'last_pymnt_amnt': {
  498. 105800: 0.0
  499. }
  500. }),
  501. pd.DataFrame({
  502. 'last_pymnt_d': {
  503. 49998: pd.Timestamp('2018-10-01 00:00:00')
  504. },
  505. 'issue_d': {
  506. 49998: pd.Timestamp('2018-08-01 00:00:00')
  507. },
  508. 'loan_status': {
  509. 49998: 'charged_off'
  510. },
  511. 'total_pymnt': {
  512. 49998: 216.10000610351562
  513. },
  514. 'total_pymnt_inv': {
  515. 49998: 216.10000610351562
  516. },
  517. 'total_rec_prncp': {
  518. 49998: 124.16000366210938
  519. },
  520. 'total_rec_int': {
  521. 49998: 91.94000244140625
  522. },
  523. 'total_rec_late_fee': {
  524. 49998: 0.0
  525. },
  526. 'recoveries': {
  527. 49998: 0.0
  528. },
  529. 'collection_recovery_fee': {
  530. 49998: 0.0
  531. },
  532. 'last_pymnt_amnt': {
  533. 49998: 111.37000274658203
  534. }
  535. }),
  536. pd.DataFrame({
  537. 'last_pymnt_d': {
  538. 7565: pd.Timestamp('2019-07-01 00:00:00')
  539. },
  540. 'issue_d': {
  541. 7565: pd.Timestamp('2018-09-01 00:00:00')
  542. },
  543. 'loan_status': {
  544. 7565: 'paid'
  545. },
  546. 'total_pymnt': {
  547. 7565: 5585.24609375
  548. },
  549. 'total_pymnt_inv': {
  550. 7565: 5585.25
  551. },
  552. 'total_rec_prncp': {
  553. 7565: 4800.0
  554. },
  555. 'total_rec_int': {
  556. 7565: 785.25
  557. },
  558. 'total_rec_late_fee': {
  559. 7565: 0.0
  560. },
  561. 'recoveries': {
  562. 7565: 0.0
  563. },
  564. 'collection_recovery_fee': {
  565. 7565: 0.0
  566. },
  567. 'last_pymnt_amnt': {
  568. 7565: 53.5
  569. }
  570. }), pd.DataFrame({
  571. 'last_pymnt_d': {
  572. 856: pd.Timestamp('2019-08-01 00:00:00')
  573. },
  574. 'issue_d': {
  575. 856: pd.Timestamp('2018-09-01 00:00:00')
  576. },
  577. 'loan_status': {
  578. 856: 'current'
  579. },
  580. 'total_pymnt': {
  581. 856: 4067.0400390625
  582. },
  583. 'total_pymnt_inv': {
  584. 856: 4067.0400390625
  585. },
  586. 'total_rec_prncp': {
  587. 856: 3311.050048828125
  588. },
  589. 'total_rec_int': {
  590. 856: 755.989990234375
  591. },
  592. 'total_rec_late_fee': {
  593. 856: 0.0
  594. },
  595. 'recoveries': {
  596. 856: 0.0
  597. },
  598. 'collection_recovery_fee': {
  599. 856: 0.0
  600. },
  601. 'last_pymnt_amnt': {
  602. 856: 406.4200134277344
  603. }
  604. })
  605. ]
  606. max_date = pd.Timestamp('2019-08-01')
  607. assert cli.apply_end_d('charged_off', test_cases[0],
  608. max_date).iat[0] == pd.Timestamp('2018-12-01')
  609. assert cli.apply_end_d('charged_off', test_cases[1],
  610. max_date).iat[0] == pd.Timestamp('2019-03-01')
  611. assert cli.apply_end_d('paid', test_cases[2],
  612. max_date).iat[0] == pd.Timestamp('2019-07-01')
  613. assert cli.apply_end_d('current', test_cases[3],
  614. max_date).iat[0] == max_date
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...