FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

SequenceMatcher.ratio() noncommutativity not well-documented · Issue #81185 · python/cpython · GitHub

Repository navigation

SequenceMatcher.ratio() noncommutativity not well-documented #81185

Closed

Description

BPO 37004
Nosy @tim-one, @terryjreedy, @miss-islington, @sweeneyde
PRs
  • bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method #13482
  • [3.8] bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method (GH-13482) #15157
  • [3.7] bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method (GH-13482) #15158
  • [3.6] bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method (GH-13482) #15159
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-08-07.16:13:49.300>
    created_at = <Date 2019-05-22.02:09:15.379>
    labels = ['3.7', '3.8', '3.9']
    title = 'SequenceMatcher.ratio() noncommutativity not well-documented'
    updated_at = <Date 2019-08-07.16:13:49.293>
    user = 'https://github.com/sweeneyde'

    bugs.python.org fields:

    activity = <Date 2019-08-07.16:13:49.293>
    actor = 'tim.peters'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-08-07.16:13:49.300>
    closer = 'tim.peters'
    components = []
    creation = <Date 2019-05-22.02:09:15.379>
    creator = 'Dennis Sweeney'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37004
    keywords = ['patch']
    message_count = 4.0
    messages = ['343138', '349151', '349169', '349170']
    nosy_count = 5.0
    nosy_names = ['tim.peters', 'terry.reedy', 'docs@python', 'miss-islington', 'Dennis Sweeney']
    pr_nums = ['13482', '15157', '15158', '15159']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37004'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    Activity

    1. sweeneyde commented on May 22, 2019

      MemberAuthor

      I understand that the SequenceMatcher's ratio method does not guarantee that SequenceMatcher(None, a, b).ratio() == SequenceMatcher(None, b, a).ratio(). Below is a counterexample:

          # Example from https://mail.python.org/pipermail/python-list/2010-November/593063.html
          >>> SequenceMatcher(None, 'BRADY', 'BYRD').ratio()
          0.6666666666666666
          >>> SequenceMatcher(None, 'BYRD', 'BRADY').ratio()
          0.4444444444444444

      I was recently solving a problem that required a textual similarity ratio function and I wrongly assumed that SequenceMatcher treated both input strings symmetrically, which was an extremely difficult bug to find, especially because for many simple tests, the ratio IS symmetric:

          >>> SequenceMatcher(None, 'apple', 'banana').ratio()
          0.18181818181818182
          >>> SequenceMatcher(None, 'banana', 'apple').ratio()
          0.18181818181818182

      I would like to see a clearer warning of this asymmetry in the documentation for the difflib module. Perhaps something like

        .. note::
      
               Caution: The result of a :meth:`ratio` call is *NOT* symmetric with 
               respect to the order of the arguments. For instance::
                  
                  >>> SequenceMatcher(None, 'brady', 'byrd').ratio()
                  0.6666666666666666
                  >>> SequenceMatcher(None, 'byrd', 'brady').ratio()
                  0.4444444444444444

      Without such a note near the ratio methods' documentations, it is far too easy to google for a Python stdlib functionality for computing text similarity, skip straight to the ratio method, look at the examples given, try some of your own simple examples, and accidentally convince oneself that this symmetry exists.

    2. miss-islington commented on Aug 7, 2019

      Contributor

      New changeset e9cbcd0 by Miss Islington (bot) (sweeneyde) in branch 'master':
      bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method (GH-13482)
      e9cbcd0

    3. terryjreedy commented on Aug 7, 2019

      Member

      New changeset 1a3a40c by Terry Jan Reedy (Miss Islington (bot)) in branch '3.8':
      bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method (GH-13482) (bpo-15157)
      1a3a40c

    4. terryjreedy commented on Aug 7, 2019

      Member

      New changeset 7dafbe8 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.7':
      bpo-37004: Documented asymmetry of string arguments in difflib.SequenceMatcher for ratio method (GH-13482) (bpo-15158)
      7dafbe8

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions


        Back | FazBrowse Home | New Git URL