Skip to content

Length information in error message of sanitize_index #26967

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

Closed
vishal-srini-rao opened this issue Jun 20, 2019 · 4 comments
Closed

Length information in error message of sanitize_index #26967

vishal-srini-rao opened this issue Jun 20, 2019 · 4 comments
Labels
Error Reporting Incorrect or improved errors from pandas good first issue
Milestone

Comments

@vishal-srini-rao
Copy link

It may be helpful for quicker debugging to provide information of data and index lengths in the error message in sanitize_index function:

raise ValueError('Length of values does not match length of index')

The modified code could be:
raise ValueError(f'Length of values {len(data)} does not match length of index {len(index)}')

@WillAyd
Copy link
Member

WillAyd commented Jun 22, 2019

Thanks for the suggestion, but I personally don't see that being much more incrementally useful.

Let's see if anyone else sees value otherwise will close out in a few days

@WillAyd WillAyd added the Error Reporting Incorrect or improved errors from pandas label Jun 22, 2019
@TomAugspurger
Copy link
Contributor

This seems reasonable to me. A PR updating the error message and a test would be welcome.

@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Jun 24, 2019
@WillAyd
Copy link
Member

WillAyd commented Jun 24, 2019

Is this solved by #26911?

@TomAugspurger
Copy link
Contributor

Not sure if it was #26911, but we should be OK now.

In [1]: import pandas as pd
 =
In [2]: pd.Series([0,1], index=[0, 1, 2])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-23ab3324fbf7> in <module>
----> 1 pd.Series([0,1], index=[0, 1, 2])

~/sandbox/pandas/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    241                             'Length of passed values is {val}, '
    242                             'index implies {ind}'
--> 243                             .format(val=len(data), ind=len(index)))
    244                 except TypeError:
    245                     pass

ValueError: Length of passed values is 2, index implies 3

LMK if you were taking a different path @vishal-srini-rao

@TomAugspurger TomAugspurger modified the milestones: Contributions Welcome, 0.25.0 Jun 26, 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 good first issue
Projects
None yet
Development

No branches or pull requests

3 participants