Skip to content
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

ERR: better error message for trying to concat non-pandas objects #15796

Closed
jreback opened this issue Mar 23, 2017 · 4 comments · Fixed by #17885
Closed

ERR: better error message for trying to concat non-pandas objects #15796

jreback opened this issue Mar 23, 2017 · 4 comments · Fixed by #17885
Labels
Error Reporting Incorrect or improved errors from pandas good first issue Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Mar 23, 2017

In [3]: pd.concat([Series(), 'foo'])
TypeError: cannot concatenate a non-NDFrame object

trivially non-NDFrame -> non-pandas. but I think even better would be something like

In [4]: objs = [Series(), 'foo']

In [7]: "cannot concatenate [{pandas}] with non-pandas objects of type [{non_pandas}]".format(
   ...: pandas=','.join(set([str(o.__class__.__name__) for o in objs if isinstance(o, pandas.core.generic.NDFrame)])),
   ...: non_pandas=','.join(set([str(type(o)) for o in objs if not isinstance(o, pandas.core.generic.NDFrame)])))
Out[7]: "cannot concatenate [Series] with non-pandas objects of type [<class 'str'>]"
@jreback jreback added Difficulty Novice Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 23, 2017
@jreback jreback added this to the Next Major Release milestone Mar 23, 2017
@petioptrv
Copy link
Contributor

I would like to take care of this one. There could be more than two objects in the concatenation, so how about "cannot concatenate objects of type [<class 'str'>], all objects must be pandas objects"?

@jreback
Copy link
Contributor Author

jreback commented Mar 23, 2017

@petioptrv yes that's why I put the list comprehension and set things. Should work with many objects.

Its just meant to be more instructive to the user.

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Mar 24, 2017

I think "pandas objects" is still a bit vague. Eg an Index, or a Timestamp are also pandas objects, but cannot be concatenated.
Are there other things than Series, DataFrame and Panel that can be concatenated? If not, let's just list those in the error message?

eg

TypeError: cannot only concatenate with Series, DataFrame or Panel objects, an object of type [<class 'str'>] was passed.

@higs4281
Copy link

Looking at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants