Skip to content

US_LETTER false negatives #358

Closed

Description

@yakra

widen the net only enough to catch:

nc.us001:US1AWak_S
nc.us001:US1AWak_N
nc.us001:US1AFra_S
nc.us001:US1AFra_N

Activity

  1. self-assigned this
    on Nov 16, 2020
  2. yakra commented on Nov 16, 2020

    @yakra
    ContributorAuthor
    if re.fullmatch('\*?US[0-9]+[AB]', w.label) \
    or re.fullmatch('\*?US[0-9]+[AB][/_(].*', w.label) \
    or re.fullmatch('\*?US[0-9]+[AB][A-Z][a-z]{2}', w.label) \
    or re.fullmatch('\*?US[0-9]+[AB][A-Z][a-z]{2}[/_(].*', w.label):
        datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
    

    is nice and clean and readable and we can tell what's going on relatively easily. But it spends a lot of time rechecking long strings at the beginning of the label that we already know are the same.

    m = re.search('^\*?US[0-9]+[AB]', w.label)
    if m:
        c = m.end(0)
        if c == len(w.label) or w.label[c] in '/_(':
            datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
        else:
            # is it followed by a city abbrev?
            m = re.search('^[A-Z][a-z]{2}', w.label[c:])
            if m:
                c += m.end(0)
                if c == len(w.label) or w.label[c] in '/_(':
                    datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
    

    runs over 3 times as fast.


    On a side note, I really miss the null terminator that C and C++ use; it comes in handy. I'd have preferred to not use the 2nd re.search, but I wanted to avoid a bunch of checking whether array indices overrun the string length. Yes, sometimes I will sacrifice a bit of speed in favor of some brevity of code. :)
    Edit: More experimentation... Looks like we can get away with it in this case, because of the checks for c == len(w.label). Invalid indices when slicing will just produce an empty string. Huzzah!

  3. yakra commented on Nov 17, 2020

    @yakra
    ContributorAuthor

    Putting way more time & effort into this than is sane.

    box v.8 v.8A comments
    noreaster 320
    334
    312
    329
    Only ran 200 passes. Results multiplied by 10.
    lab1 191.3
    198.1
    197.9
    195.5
     
    lab1.5 161.9
    158.6
    158.0
    161.3
     
    lab2 231.5
    240.4
    226.7
    238.5
     
    lab3 341.7
    339.9
    334.1
    336.2
    Python 2
    BiggaTomato 317.2
    307.2
    320.9
    315.2
     
    epoch 394.4
    419.3
    423
    434.1
     

    I don't need to worry about checking my array indices manually if I enclose the whole thing within try:/except IndexError: Dropping regexes altogether in favor of a more C-like approach that examines the individual characters runs 3-4x as fast depending on what machine.

    try:
        c = 3 if w.label[0] == '*' else 2
        if w.label[c-2] == 'U' and w.label[c-1] == 'S' and w.label[c].isdigit():
            while w.label[c].isdigit():
                c += 1
            if w.label[c] in 'AB':
                c += 1
                if c == len(w.label) or w.label[c] in '/_(':
                    datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
                # is it followed by a city abbrev?
                elif w.label[c].isupper() and w.label[c+1].islower() and w.label[c+2].islower() \
                and (c+3 == len(w.label) or w.label[c+3] in '/_('):
                    datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
    except IndexError:
        pass
    

    How much time will this actually save per update? About 0.3s! 🤣

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions