Skip to content

Commit 73f549a

Browse files
Be specific about more indexes or values
The generic "are not equal" really frustrated me just now when someone was conveying their issue. This specific two errors lets me know which way around, although I believe having more indexes than data shows a place in the api for a default value (possibly per-index) which would allow this to later be reduced to the case I feel I fully understand of more data than indexes, which I think probably is unsolvable generally. I can see that both have problems, but I still think it's more important to be specific about which side is mismatched.
1 parent 37662ea commit 73f549a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pandas/core/internals/construction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,10 @@ def sanitize_index(data, index: Index):
743743
Sanitize an index type to return an ndarray of the underlying, pass
744744
through a non-Index.
745745
"""
746-
if len(data) != len(index):
747-
raise ValueError("Length of values does not match length of index")
746+
if len(data) > len(index):
747+
raise ValueError("Length of values is greater than length of index")
748+
if len(index) > len(data):
749+
raise ValueError("Length of index is greater than length of values")
748750

749751
if isinstance(data, np.ndarray):
750752

0 commit comments

Comments
 (0)