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

Improve TypeError message for str.cat #22722

Closed
h-vetinari opened this issue Sep 15, 2018 · 4 comments · Fixed by #22725 or #26607
Closed

Improve TypeError message for str.cat #22722

h-vetinari opened this issue Sep 15, 2018 · 4 comments · Fixed by #22725 or #26607
Labels
Error Reporting Incorrect or improved errors from pandas Series Series data structure
Milestone

Comments

@h-vetinari
Copy link
Contributor

Currently,

s = pd.Series(['a', 'b', 'c'])
s.str.cat([1, 2, 3])

yields

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Axel Obermeier\eclipse-workspace\pddev\pandas\core\strings.py", line 2222, in cat
    res = str_cat(data, others=others, sep=sep, na_rep=na_rep)
  File "C:\Users\Axel Obermeier\eclipse-workspace\pddev\pandas\core\strings.py", line 111, in str_cat
    cats = [sep.join(tup) for tup in tuples]
  File "C:\Users\Axel Obermeier\eclipse-workspace\pddev\pandas\core\strings.py", line 111, in <listcomp>
    cats = [sep.join(tup) for tup in tuples]
TypeError: sequence item 1: expected str instance, int found

IMO, this should be improved to have a better error message, and shallower stack trace.

@WillAyd
Copy link
Member

WillAyd commented Sep 15, 2018

What are you suggesting exactly? Error message reflects what you would get from a standard Python operation:

>>> "".join(['foo', 1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sequence item 1: expected str instance, int found

@WillAyd WillAyd added Error Reporting Incorrect or improved errors from pandas Needs Info Clarification about behavior needed to assess issue labels Sep 15, 2018
@h-vetinari
Copy link
Contributor Author

@WillAyd

That's of course correct, but users are not dealing with str/int instances, but usually with Series/ndarray, etc., and so the mentioned warning gives the right hint, but is not necessarily the best we can do. I opened this issue as it was a side product of cleaning up some internals/tests for #22725.

@jreback jreback added this to the 0.24.0 milestone Oct 5, 2018
@h-vetinari
Copy link
Contributor Author

@jreback

I'll open another PR for this, but this will not be closed by #22725 (was split off due to review)

@h-vetinari
Copy link
Contributor Author

@WillAyd The code for this was splitt off of #22725 to focus that PR (I had edited the OP to reflect that) - this issue is still open.

@WillAyd WillAyd reopened this Oct 15, 2018
@jreback jreback modified the milestones: 0.24.0, Contributions Welcome Dec 2, 2018
@gfyoung gfyoung added Series Series data structure and removed Needs Info Clarification about behavior needed to assess issue labels Jun 1, 2019
@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Jun 13, 2019
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 Series Series data structure
Projects
None yet
4 participants