-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Series.str.cat(',') without "sep" keyword arg raises unintuitive TypeError: len() of unsized object
#11334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
sounds reasonable. pull-request? |
Will do. |
I propose to fix this by changing the order of the keyword args, like so: def str_cat(arr, sep=None, others=None, na_rep=None):
"""
Concatenate strings in the Series/Index with given separator.
Parameters
----------
sep : string or None, default None
others : list-like, or list of list-likes
If None, returns str concatenating strings of the Series
na_rep : string or None, default None
If None, an NA in any array will propagate So that This is an API change though and breaks some tests, because @jreback, does that sound reasonable? That way, >>> Series(['a', 'b', 'c']).str.cat('|')
'a|b|c'
>>> Series(['a','b',np.nan,'c']).str.cat(' ', na_rep='?')
'a b ? c'
>>> Series(['a', 'b', 'c']).str.cat(',', others=['A', 'B', 'C'])
0 a,A
1 b,B
2 c,C
dtype: object
>>> Series(['a', 'b']).str.cat(others=[['x', 'y'], ['1', '2']], sep=',')
0 a,x,1
1 b,y,2
dtype: object |
@hack-c no, that doesn't make sense, why just catch and raise a nice error? |
Ok. :) I just like that API design better but realize it's late in the game for a breaking change like that. |
I think you can check for this error conditiion and give a really helpful error (e.g. you can even say, did you mean 'sep') |
I think this easy-to-make mistake should raise a more descriptive error... maybe something like
I might be missing the main usage of
str.cat()
, but all the uses I've found involve concatenating series together with a sep character.The text was updated successfully, but these errors were encountered: