Skip to content

Series.str.cat(',') without "sep" keyword arg raises unintuitive TypeError: len() of unsized object #11334

Closed
@hack-c

Description

@hack-c

I think this easy-to-make mistake should raise a more descriptive error... maybe something like

ValueError: Did you mean to supply a 'sep' keyword?

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.

In [1]: import pandas as pd

In [2]: s = pd.Series(['foo', 'bar', 'baz'])

In [3]: s.str.cat('|')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-8bc5f2a1347b> in <module>()
----> 1 s.str.cat('|')

/home/charles.hack/anaconda/envs/seahydra/lib/python2.7/site-packages/pandas/core/strings.pyc in cat(self, others, sep, na_rep)
   1137     @copy(str_cat)
   1138     def cat(self, others=None, sep=None, na_rep=None):
-> 1139         result = str_cat(self.series, others=others, sep=sep, na_rep=na_rep)
   1140         return self._wrap_result(result)
   1141

/home/charles.hack/anaconda/envs/seahydra/lib/python2.7/site-packages/pandas/core/strings.pyc in str_cat(arr, others, sep, na_rep)
     71         arrays = _get_array_list(arr, others)
     72
---> 73         n = _length_check(arrays)
     74         masks = np.array([isnull(x) for x in arrays])
     75         cats = None

/home/charles.hack/anaconda/envs/seahydra/lib/python2.7/site-packages/pandas/core/strings.pyc in _length_check(others)
    111         if n is None:
    112             n = len(x)
--> 113         elif len(x) != n:
    114             raise ValueError('All arrays must be same length')
    115

TypeError: len() of unsized object

In [4]: s.str.cat(sep='|')
Out[4]: 'foo|bar|baz'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasStringsString extension data type and string data

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions