@@ -471,6 +471,51 @@ def test_sparql_write_triples(neptune_endpoint, neptune_port) -> dict[str, Any]:
471471 assert len (batch_df .index ) == len (final_df .index ) + 50
472472
473473
474+ def test_sparql_bindings_nan_safe () -> None :
475+ class _DummyClient :
476+ def read_sparql (self , _query : str ) -> dict [str , Any ]:
477+ return {
478+ "head" : {"vars" : ["book_id" , "title" , "checked_out" , "last_updated" , "category_code" ]},
479+ "results" : {
480+ "bindings" : [
481+ {
482+ "title" : {
483+ "xml:lang" : "en" ,
484+ "type" : "literal" ,
485+ "value" : "The Art of Space Travel" ,
486+ },
487+ "book_id" : {"type" : "literal" , "value" : "B10045982" },
488+ "last_updated" : {
489+ "datatype" : "http://www.w3.org/2001/XMLSchema#dateTime" ,
490+ "type" : "literal" ,
491+ "value" : "2025-10-01T10:30:00.000Z" ,
492+ },
493+ "category_code" : {
494+ "datatype" : "http://www.w3.org/2001/XMLSchema#integer" ,
495+ "type" : "literal" ,
496+ "value" : "5" ,
497+ },
498+ },
499+ ]
500+ },
501+ }
502+
503+ client : Any = _DummyClient ()
504+ df = wr .neptune .execute_sparql (
505+ client ,
506+ "SELECT ?book_id ?title ?checked_out ?last_updated ?category_code WHERE { ?s ?p ?o }" ,
507+ )
508+ assert df .shape == (1 , 5 )
509+ # Row 1
510+ v1 = df .iloc [0 ].tolist ()
511+ book_id , title , checked_out , last_updated , category_code = v1
512+ assert book_id == "B10045982"
513+ assert title == "The Art of Space Travel"
514+ assert checked_out is None # missing binding becomes None
515+ assert last_updated == "2025-10-01T10:30:00.000Z"
516+ assert category_code == "5"
517+
518+
474519def test_sparql_write_quads (neptune_endpoint , neptune_port ) -> dict [str , Any ]:
475520 label = f"foo_{ uuid .uuid4 ()} "
476521 sparkql_query = f"SELECT ?p ?o FROM <bar> WHERE {{ <{ label } > ?p ?o .}}"
0 commit comments