@@ -1070,6 +1070,34 @@ def test_query_string_scalar_variable(self, parser, engine):
1070
1070
r = df .query ("Symbol == @symb" , parser = parser , engine = engine )
1071
1071
tm .assert_frame_equal (e , r )
1072
1072
1073
+ @pytest .mark .parametrize (
1074
+ "in_list" ,
1075
+ [
1076
+ [None , "asdf" , "ghjk" ],
1077
+ ["asdf" , None , "ghjk" ],
1078
+ ["asdf" , "ghjk" , None ],
1079
+ [None , None , "asdf" ],
1080
+ ["asdf" , None , None ],
1081
+ [None , None , None ],
1082
+ ],
1083
+ )
1084
+ def test_query_string_null_elements (self , in_list ):
1085
+ # GITHUB ISSUE #31516
1086
+ parser = "pandas"
1087
+ engine = "python"
1088
+ expected = {i : value for i , value in enumerate (in_list ) if value == "asdf" }
1089
+
1090
+ df_expected = DataFrame ({"a" : expected }, dtype = "string" )
1091
+ df_expected .index = df_expected .index .astype ("int64" )
1092
+ df = DataFrame ({"a" : in_list }, dtype = "string" )
1093
+ res1 = df .query ("a == 'asdf'" , parser = parser , engine = engine )
1094
+ res2 = df [df ["a" ] == "asdf" ]
1095
+ res3 = df .query ("a <= 'asdf'" , parser = parser , engine = engine )
1096
+ tm .assert_frame_equal (res1 , df_expected )
1097
+ tm .assert_frame_equal (res1 , res2 )
1098
+ tm .assert_frame_equal (res1 , res3 )
1099
+ tm .assert_frame_equal (res2 , res3 )
1100
+
1073
1101
1074
1102
class TestDataFrameEvalWithFrame :
1075
1103
@pytest .fixture
0 commit comments