You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import pandas as pd
import regex as re
s = pd.Series(['foo', 'bar'])
pat = re.compile('a')
s.str.replace(pat, ' ')
Raises the error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-4fc8cf4e83c0> in <module>()
----> 1 s.str.replace(pat, ' ')
~/anaconda3/lib/python3.6/site-packages/pandas/core/strings.py in replace(self, pat, repl, n, case, flags, regex)
2427 def replace(self, pat, repl, n=-1, case=None, flags=0, regex=True):
2428 result = str_replace(self._data, pat, repl, n=n, case=case,
-> 2429 flags=flags, regex=regex)
2430 return self._wrap_result(result)
2431
~/anaconda3/lib/python3.6/site-packages/pandas/core/strings.py in str_replace(arr, pat, repl, n, case, flags, regex)
652 if case is False:
653 flags |= re.IGNORECASE
--> 654 if is_compiled_re or len(pat) > 1 or flags or callable(repl):
655 n = n if n >= 0 else 0
656 compiled = re.compile(pat, flags=flags)
TypeError: object of type '_regex.Pattern' has no len()
I think that the problem comes from the call to the function is_re, namely
from pandas.core.dtypes.common import is_re
is_re(pat)
returns False while I think it should return True.
The text was updated successfully, but these errors were encountered:
I am using pandas 0.23.1 with python 3.6.4
Raises the error
I think that the problem comes from the call to the function
is_re
, namelyreturns
False
while I think it should returnTrue
.The text was updated successfully, but these errors were encountered: