Skip to content

Commit 321c508

Browse files
improve splitting
1 parent 2697f02 commit 321c508

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

pandas/core/computation/parsing.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,23 @@ def _split_by_backtick(s: str) -> list[tuple[bool, str]]:
211211
else:
212212
quote_index = min(single_quote_index, double_quote_index)
213213

214-
# No quotes
215-
if quote_index == -1:
216-
next_backtick_index = s.find("`", backtick_index + 1)
214+
# No quotes, or
217215
# Backtick opened before quote
218-
elif backtick_index < quote_index:
216+
if (quote_index == -1) or (backtick_index < quote_index):
219217
next_backtick_index = s.find("`", backtick_index + 1)
218+
219+
# Backtick is unmatched (Possibly a mistake)
220+
if next_backtick_index == -1:
221+
substrings.append((False, substring + s[i:]))
222+
break
223+
# Backtick is matched
224+
else:
225+
if i != backtick_index:
226+
substrings.append((False, substring + s[i:backtick_index]))
227+
substrings.append((True, s[backtick_index : next_backtick_index + 1]))
228+
substring = ""
229+
i = next_backtick_index + 1
230+
220231
# Quote opened before backtick
221232
else:
222233
next_quote_index = -1
@@ -241,18 +252,6 @@ def _split_by_backtick(s: str) -> list[tuple[bool, str]]:
241252
i = next_quote_index + 1
242253
continue
243254

244-
# Backtick is unmatched (Possibly a mistake)
245-
if next_backtick_index == -1:
246-
substrings.append((False, substring + s[i:]))
247-
break
248-
# Backtick is matched
249-
else:
250-
if i != backtick_index:
251-
substrings.append((False, substring + s[i:backtick_index]))
252-
substrings.append((True, s[backtick_index : next_backtick_index + 1]))
253-
substring = ""
254-
i = next_backtick_index + 1
255-
256255
return substrings
257256

258257

0 commit comments

Comments
 (0)