Skip to content

Commit e15dcdf

Browse files
author
Joost Kranendonk
authored
fix bug catch TypeError with wrong number of args
The regex filtering TypeErrors with argument number problems is now unified and suitable for Python 2.7
1 parent 40c0d97 commit e15dcdf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

pandas/core/strings.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,9 @@ def _map(f, arr, na_mask=False, na_value=np.nan, dtype=object):
170170
except (TypeError, AttributeError) as e:
171171
# Reraise the exception if callable `f` got wrong number of args.
172172
# The user may want to be warned by this, instead of getting NaN
173-
re_missing = (r'missing \d+ required (positional|keyword-only) '
174-
'arguments?')
175-
re_takes = (r'takes (from)?\d+ (to \d+)?positional arguments? '
176-
'but \d+ (was|were) given')
177-
if len(e.args) >= 1 and (re.search(re_missing, e.args[0])
178-
or re.search(re_takes, e.args[0])):
173+
re_error = (r'(takes|(missing)) (no|(exactly )?\d+) '
174+
r'(?(2)required )(positional )?arguments?')
175+
if len(e.args) >= 1 and re.search(re_error, e.args[0]):
179176
raise e
180177

181178
def g(x):

0 commit comments

Comments
 (0)