Skip to content

Commit e3a9308

Browse files
reinstate text in docs, shorten some lines
1 parent 7a5fa0c commit e3a9308

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pandas/core/frame.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4546,8 +4546,9 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
45464546
For other characters that fall outside the ASCII range (U+0001..U+007F)
45474547
and those that are not further specified in PEP 3131,
45484548
the query parser will raise an error.
4549-
This excludes whitespace different than the space character
4550-
and the backtick itself (backtick cannot be escaped).
4549+
This excludes whitespace different than the space character,
4550+
but also the hashtag (as it is used for comments) and the backtick
4551+
itself (backtick can also not be escaped).
45514552
45524553
See also the `Python documentation about lexical analysis
45534554
<https://docs.python.org/3/reference/lexical_analysis.html>`__
@@ -4606,16 +4607,15 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46064607
if any(("#" in col) or ("'" in col) or ('"' in col) for col in self.columns):
46074608
# Create a copy of `self` with column names escaped
46084609
escaped_self = self.copy()
4609-
escaped_self.columns = [
4610-
urllib.parse.quote(col) for col in escaped_self.columns
4611-
]
4610+
escaped_self.columns = map(urllib.parse.quote, escaped_self.columns)
46124611

46134612
# In expr, escape column names between backticks
4614-
column_name_to_escaped_name = {
4613+
column_name_to_escaped = {
46154614
col: urllib.parse.quote(col) for col in self.columns
46164615
}
4616+
# Odd-number indexes are column names
46174617
escaped_expr = "`".join(
4618-
(column_name_to_escaped_name.get(token, token) if (i % 2) else token)
4618+
(column_name_to_escaped.get(token, token) if (i % 2) else token)
46194619
for i, token in enumerate(expr.split("`"))
46204620
)
46214621

@@ -4627,7 +4627,7 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46274627
if isinstance(res, Series) and res.name:
46284628
res.name = urllib.parse.unquote(res.name)
46294629
elif isinstance(res, DataFrame):
4630-
res.columns = [urllib.parse.unquote(col) for col in res.columns]
4630+
res.columns = map(urllib.parse.unquote, res.columns)
46314631
else:
46324632
res = self.eval(expr, **kwargs)
46334633

0 commit comments

Comments
 (0)