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

ENH: adding suggested names to ColormapRegistry missing key error #28115

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tacaswell
Copy link
Member

difflib.get_close_match has been in the standard library from Python 2.1

PR summary

Make use of a function in the standard library to give suggestions for missed

PR checklist

I don't think this needs to be called out in the release notes.

difflib.get_close_match has been in the standard library from Python 2.1
lib/matplotlib/cm.py Outdated Show resolved Hide resolved
@anntzer
Copy link
Contributor

anntzer commented Apr 22, 2024

(We don't have to do this now; just leaving a comment as a note.) It would be nice to be able to reuse CPython's attribute suggestions algorithm, but it looks like it's not exposed externally (other than calling excepthook and parsing stderr...); see also ipython/ipython#13445 (ipython having to reimplement it).

@tacaswell
Copy link
Member Author

Ah, I thought this was cpython's suggestion algorithm.

Maintains the status-quo

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@tacaswell
Copy link
Member Author

For reference, cpython appears to use Levenshtein distance (python/cpython@37494b4#diff-aad873b2c81d05628e415ef526dbd8845ebe4bf85b2d9c6d83d6cdf804b6e7b7) where as difflibe.get_close_matches uses a different (more general?) algorithm.

It looks like traceback has a (private) implementation of Levenshtein distance, but given that using private methods makes Guido sad (and makes us sad when people use our private API) we should not do that.

I think the reasonable options are:

  • stick with difflib
  • vendor a copy of Levenshtein distance (CPython's implementation is only 60 lines with comments)

@tacaswell tacaswell marked this pull request as draft April 24, 2024 02:36
@tacaswell
Copy link
Member Author

I'm leaning to

  • vendor Levenshtein
  • use it in check_list

which means a bunch more work. I'll try to get back to this, but if someone wants to take this over I will not be mad!

@QuLogic
Copy link
Member

QuLogic commented Apr 24, 2024

Would that produce better results?

@timhoffm
Copy link
Member

Yes, what's the difference? If difflib gives reasonable results. I would stick with that as "good enough" before writing/vendoring any additional code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants