Skip to content

Commit fc97251

Browse files
reinstate text in docs, shorten some lines
1 parent 70f9315 commit fc97251

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
@@ -4560,8 +4560,9 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
45604560
For other characters that fall outside the ASCII range (U+0001..U+007F)
45614561
and those that are not further specified in PEP 3131,
45624562
the query parser will raise an error.
4563-
This excludes whitespace different than the space character
4564-
and the backtick itself (backtick cannot be escaped).
4563+
This excludes whitespace different than the space character,
4564+
but also the hashtag (as it is used for comments) and the backtick
4565+
itself (backtick can also not be escaped).
45654566
45664567
See also the `Python documentation about lexical analysis
45674568
<https://docs.python.org/3/reference/lexical_analysis.html>`__
@@ -4620,16 +4621,15 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46204621
if any(("#" in col) or ("'" in col) or ('"' in col) for col in self.columns):
46214622
# Create a copy of `self` with column names escaped
46224623
escaped_self = self.copy()
4623-
escaped_self.columns = [
4624-
urllib.parse.quote(col) for col in escaped_self.columns
4625-
]
4624+
escaped_self.columns = map(urllib.parse.quote, escaped_self.columns)
46264625

46274626
# In expr, escape column names between backticks
4628-
column_name_to_escaped_name = {
4627+
column_name_to_escaped = {
46294628
col: urllib.parse.quote(col) for col in self.columns
46304629
}
4630+
# Odd-number indexes are column names
46314631
escaped_expr = "`".join(
4632-
(column_name_to_escaped_name.get(token, token) if (i % 2) else token)
4632+
(column_name_to_escaped.get(token, token) if (i % 2) else token)
46334633
for i, token in enumerate(expr.split("`"))
46344634
)
46354635

@@ -4641,7 +4641,7 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46414641
if isinstance(res, Series) and res.name:
46424642
res.name = urllib.parse.unquote(res.name)
46434643
elif isinstance(res, DataFrame):
4644-
res.columns = [urllib.parse.unquote(col) for col in res.columns]
4644+
res.columns = map(urllib.parse.unquote, res.columns)
46454645
else:
46464646
res = self.eval(expr, **kwargs)
46474647

0 commit comments

Comments
 (0)