diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 117eb85..73776e4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/src/pandas_indexing/utils.py b/src/pandas_indexing/utils.py index 6b1fdd7..7bdbcd8 100644 --- a/src/pandas_indexing/utils.py +++ b/src/pandas_indexing/utils.py @@ -3,6 +3,7 @@ Simple utility functions not of greater interest """ +import re from typing import Union from pandas import DataFrame, Index, Series @@ -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):