@@ -504,3 +504,42 @@ def domath(a, b):
504
504
result = package .code ()
505
505
assert target .lstrip ('\n ' ) == result
506
506
assert '\t ' not in result
507
+
508
+
509
+ def test_bugfix_27 ():
510
+ """NaN values should be converted to null before being sent to MAS
511
+
512
+ https://github.com/sassoftware/python-sasctl/issues/27
513
+ """
514
+
515
+ import io
516
+ from sasctl .core import RestObj
517
+ from sasctl .services import microanalytic_score as mas
518
+ pd = pytest .importorskip ('pandas' )
519
+
520
+ df = pd .read_csv (io .StringIO ('\n ' .join ([
521
+ 'BAD,LOAN,MORTDUE,VALUE,REASON,JOB,YOJ,DEROG,DELINQ,CLAGE,NINQ,CLNO,DEBTINC' ,
522
+ '0,1.0,1100.0,25860.0,39025.0,HomeImp,Other,10.5,0.0,0.0,94.36666667,1.0,9.0,' ,
523
+ '1,1.0,1300.0,70053.0,68400.0,HomeImp,Other,7.0,0.0,2.0,121.8333333,0.0,14.0,'
524
+ ])))
525
+
526
+ with mock .patch ('sasctl._services.microanalytic_score.MicroAnalyticScore.get_module' ) as get_module :
527
+ get_module .return_value = RestObj ({
528
+ 'name' : 'Mock Module' ,
529
+ 'id' : 'mockmodule'
530
+ })
531
+ with mock .patch ('sasctl._services.microanalytic_score.MicroAnalyticScore.post' ) as post :
532
+ x = df .iloc [0 , :]
533
+ mas .execute_module_step ('module' , 'step' , ** x )
534
+
535
+ # Ensure we're passing NaN to execute_module_step
536
+ assert pd .isna (x ['DEBTINC' ])
537
+
538
+ # Make sure the value has been converted to None before being serialized to JSON.
539
+ # This ensures that the JSON value will be null.
540
+ json = post .call_args [1 ]['json' ]
541
+ inputs = json ['inputs' ]
542
+ debtinc = [i for i in inputs if i ['name' ] == 'DEBTINC' ].pop ()
543
+ assert debtinc ['value' ] is None
544
+
545
+
0 commit comments