@@ -1070,6 +1070,37 @@ 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 : list ):
1085
+ # GITHUB ISSUE #31516
1086
+ parser = "pandas"
1087
+ engine = "python"
1088
+ expected = {
1089
+ i : value
1090
+ for value , i in zip (in_list , range (len (in_list )))
1091
+ if value == "asdf"
1092
+ }
1093
+ df_expected = DataFrame ({"a" : expected }, dtype = "string" )
1094
+ df_expected .index = df_expected .index .astype ("int64" )
1095
+ df = DataFrame ({"a" : in_list }, dtype = "string" )
1096
+ res1 = df .query ("a == 'asdf'" , parser = parser , engine = engine )
1097
+ res2 = df [df ["a" ] == "asdf" ]
1098
+ res3 = df .query ("a <= 'asdf'" , parser = parser , engine = engine )
1099
+ tm .assert_frame_equal (res1 , df_expected )
1100
+ tm .assert_frame_equal (res1 , res2 )
1101
+ tm .assert_frame_equal (res1 , res3 )
1102
+ tm .assert_frame_equal (res2 , res3 )
1103
+
1073
1104
1074
1105
class TestDataFrameEvalWithFrame :
1075
1106
@pytest .fixture
0 commit comments