@@ -375,3 +375,59 @@ def test_nonetype_dropping(self):
375
375
'info.last_updated' : '26/05/2012' }]
376
376
377
377
assert result == expected
378
+
379
+ def test_nonetype_top_level_bottom_level (self ):
380
+ # GH21158: If inner level json has a key with a null value
381
+ # make sure it doesnt do a new_d.pop twice and except
382
+ data = {
383
+ "id" : None ,
384
+ "location" : {
385
+ "country" : {
386
+ "state" : {
387
+ "id" : None ,
388
+ "town.info" : {
389
+ "id" : None ,
390
+ "region" : None ,
391
+ "x" : 49.151580810546875 ,
392
+ "y" : - 33.148521423339844 ,
393
+ "z" : 27.572303771972656 }}}
394
+ }
395
+ }
396
+ result = nested_to_record (data )
397
+ expected = {
398
+ 'location.country.state.id' : None ,
399
+ 'location.country.state.town.info.id' : None ,
400
+ 'location.country.state.town.info.region' : None ,
401
+ 'location.country.state.town.info.x' : 49.151580810546875 ,
402
+ 'location.country.state.town.info.y' : - 33.148521423339844 ,
403
+ 'location.country.state.town.info.z' : 27.572303771972656 }
404
+ assert result == expected
405
+
406
+ def test_nonetype_multiple_levels (self ):
407
+ # GH21158: If inner level json has a key with a null value
408
+ # make sure it doesnt do a new_d.pop twice and except
409
+ data = {
410
+ "id" : None ,
411
+ "location" : {
412
+ "id" : None ,
413
+ "country" : {
414
+ "id" : None ,
415
+ "state" : {
416
+ "id" : None ,
417
+ "town.info" : {
418
+ "region" : None ,
419
+ "x" : 49.151580810546875 ,
420
+ "y" : - 33.148521423339844 ,
421
+ "z" : 27.572303771972656 }}}
422
+ }
423
+ }
424
+ result = nested_to_record (data )
425
+ expected = {
426
+ 'location.id' : None ,
427
+ 'location.country.id' : None ,
428
+ 'location.country.state.id' : None ,
429
+ 'location.country.state.town.info.region' : None ,
430
+ 'location.country.state.town.info.x' : 49.151580810546875 ,
431
+ 'location.country.state.town.info.y' : - 33.148521423339844 ,
432
+ 'location.country.state.town.info.z' : 27.572303771972656 }
433
+ assert result == expected
0 commit comments