Skip to content

Commit f30b668

Browse files
reinstate text in docs, shorten some lines
1 parent 7f0a7a6 commit f30b668

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
@@ -4555,8 +4555,9 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
45554555
For other characters that fall outside the ASCII range (U+0001..U+007F)
45564556
and those that are not further specified in PEP 3131,
45574557
the query parser will raise an error.
4558-
This excludes whitespace different than the space character
4559-
and the backtick itself (backtick cannot be escaped).
4558+
This excludes whitespace different than the space character,
4559+
but also the hashtag (as it is used for comments) and the backtick
4560+
itself (backtick can also not be escaped).
45604561
45614562
See also the `Python documentation about lexical analysis
45624563
<https://docs.python.org/3/reference/lexical_analysis.html>`__
@@ -4615,16 +4616,15 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46154616
if any(("#" in col) or ("'" in col) or ('"' in col) for col in self.columns):
46164617
# Create a copy of `self` with column names escaped
46174618
escaped_self = self.copy()
4618-
escaped_self.columns = [
4619-
urllib.parse.quote(col) for col in escaped_self.columns
4620-
]
4619+
escaped_self.columns = map(urllib.parse.quote, escaped_self.columns)
46214620

46224621
# In expr, escape column names between backticks
4623-
column_name_to_escaped_name = {
4622+
column_name_to_escaped = {
46244623
col: urllib.parse.quote(col) for col in self.columns
46254624
}
4625+
# Odd-number indexes are column names
46264626
escaped_expr = "`".join(
4627-
(column_name_to_escaped_name.get(token, token) if (i % 2) else token)
4627+
(column_name_to_escaped.get(token, token) if (i % 2) else token)
46284628
for i, token in enumerate(expr.split("`"))
46294629
)
46304630

@@ -4636,7 +4636,7 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46364636
if isinstance(res, Series) and res.name:
46374637
res.name = urllib.parse.unquote(res.name)
46384638
elif isinstance(res, DataFrame):
4639-
res.columns = [urllib.parse.unquote(col) for col in res.columns]
4639+
res.columns = map(urllib.parse.unquote, res.columns)
46404640
else:
46414641
res = self.eval(expr, **kwargs)
46424642

0 commit comments

Comments
 (0)