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 exception for validate_key #10765

Merged
merged 2 commits into from Jan 10, 2024

Conversation

hendrikmakait
Copy link
Member

@hendrikmakait hendrikmakait commented Jan 10, 2024

The exception now indicates the index of the invalid key type and the traceback reveals the actual problem. The latter is important for nested tuples.

Traceback (most recent call last):
  File "/Users/hendrikmakait/projects/dask/dask/dask/core.py", line 235, in validate_key
    validate_key(part)
  File "/Users/hendrikmakait/projects/dask/dask/dask/core.py", line 240, in validate_key
    raise TypeError(f"Unexpected key type {typ} ({key=!r})")
TypeError: Unexpected key type <class 'numpy.int64'> (key=2)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/hendrikmakait/projects/dask/dask/dask/core.py", line 237, in validate_key
    raise TypeError(
TypeError: Composite key contains unexpected key type at _index=1 (key=(1, 2, 3))

Copy link
Collaborator

@phofl phofl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

dask/core.py Outdated
validate_key(part)
except TypeError as e:
raise TypeError(
f"Composite key contains unexpected key type at {_index=} ({key=!r})"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"Composite key contains unexpected key type at {_index=} ({key=!r})"
f"Composite key contains unexpected key type at index={_index} ({key=!r})"

That would get ci passing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shouldn't have followed flake8s advice there. Reverted to index and ignoring the check.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

@hendrikmakait hendrikmakait merged commit 8b82f99 into dask:main Jan 10, 2024
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception from validate_key is misleading for composite keys
2 participants