Skip to content

Commit

Permalink
fix(utils): Fix shell_pattern_to_regex to work with brackets (#56)
Browse files Browse the repository at this point in the history
* fix(utils): Fix shell_pattern_to_regex to work with brackets

* Update CHANGELOG
  • Loading branch information
coroa authored May 20, 2024
1 parent b5e09f4 commit 549ffff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Changelog
=========

* Fix :func:`~selectors.ismatch` to not interpret brackets as regex symbols
* Fix :func:`~selectors.isin` to always return a series (instead of a numpy array)

v0.5.0 (2024-04-09)
Expand Down
14 changes: 2 additions & 12 deletions src/pandas_indexing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Simple utility functions not of greater interest
"""

import re
from typing import Union

from pandas import DataFrame, Index, Series
Expand All @@ -15,18 +16,7 @@ def shell_pattern_to_regex(s):
"""
Escape characters with specific regexp use.
"""
return (
str(s)
.replace("|", r"\|")
.replace(".", r"\.") # `.` has to be replaced before `*`
.replace("**", "__starstar__") # temporarily __starstar__
.replace("*", r"[^|]*")
.replace("__starstar__", r".*")
.replace("+", r"\+")
.replace("(", r"\(")
.replace(")", r"\)")
.replace("$", r"\$")
)
return re.escape(s).replace(r"\*\*", ".*").replace(r"\*", r"[^|]*")


def print_list(x, n):
Expand Down

0 comments on commit 549ffff

Please sign in to comment.