@@ -1994,45 +1994,27 @@ def test_query_on_expr_with_comment():
1994
1994
tm .assert_frame_equal (result , expected )
1995
1995
1996
1996
1997
- def test_query_on_column_names_with_single_quote_character ():
1998
- df = DataFrame (
1999
- [
2000
- {"it's" : 1 , "that's" : 2 },
2001
- {"it's" : 3 , "that's" : 4 },
2002
- {"it's" : - 1 , "that's" : - 2 },
2003
- {"it's" : - 3 , "that's" : - 4 },
2004
- ]
2005
- )
2006
- result = df .query ("`it's` < `that's`" )
2007
- expected = df [df ["it's" ] < df ["that's" ]]
2008
- tm .assert_frame_equal (result , expected )
2009
-
2010
-
2011
- def test_query_on_column_names_with_double_quote_character ():
2012
- df = DataFrame (
2013
- [
2014
- {'it"s' : 1 , 'that"s' : 2 },
2015
- {'it"s' : 3 , 'that"s' : 4 },
2016
- {'it"s' : - 1 , 'that"s' : - 2 },
2017
- {'it"s' : - 3 , 'that"s' : - 4 },
2018
- ]
2019
- )
2020
- result = df .query ('`it"s` < `that"s`' )
2021
- expected = df [df ['it"s' ] < df ['that"s' ]]
2022
- tm .assert_frame_equal (result , expected )
2023
-
2024
-
2025
- def test_query_on_column_names_with_single_quote_and_double_quote_character ():
1997
+ @pytest .mark .parametrize (
1998
+ "col1,col2,expr" ,
1999
+ [
2000
+ ("it's" , "that's" , "`it's` < `that's`" ),
2001
+ ('it"s' , 'that"s' , '`it"s` < `that"s`' ),
2002
+ ("it's" , 'that\' s "nice"' , "`it's` < `that's \" nice\" `" ),
2003
+ ("it's" , "that's #cool" , "`it's` < `that's #cool` # This is a comment" ),
2004
+ ],
2005
+ )
2006
+ def test_query_on_column_names_with_special_characters (col1 , col2 , expr ):
2007
+ # GH 59285
2026
2008
df = DataFrame (
2027
2009
[
2028
- {"it's" : 1 , 'that \' s "nice"' : 2 },
2029
- {"it's" : 3 , 'that \' s "nice"' : 4 },
2030
- {"it's" : - 1 , 'that \' s "nice"' : - 2 },
2031
- {"it's" : - 3 , 'that \' s "nice"' : - 4 },
2010
+ {col1 : 1 , col2 : 2 },
2011
+ {col1 : 3 , col2 : 4 },
2012
+ {col1 : - 1 , col2 : - 2 },
2013
+ {col1 : - 3 , col2 : - 4 },
2032
2014
]
2033
2015
)
2034
- result = df .query ("`it's` < `that's \" nice \" `" )
2035
- expected = df [df ["it's" ] < df ['that \' s "nice"' ]]
2016
+ result = df .query (expr )
2017
+ expected = df [df [col1 ] < df [col2 ]]
2036
2018
tm .assert_frame_equal (result , expected )
2037
2019
2038
2020
0 commit comments