mmcloughlin / luhn

Generate and verify Luhn check digits
MIT License
43 stars 14 forks source link

add drop function to drop a luhn checksum if it exists in the string #2

Closed bandersen23 closed 4 years ago

bandersen23 commented 4 years ago

This way I can just drop it if I no longer need the checksum rather than check if it was there.

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 35ea7069161b267d22dd4a8b32fe16e739034dd7 on bandersen23:master into d6f3fa71072f99334a4c1d2a3f062fa93982797f on mmcloughlin:master.

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 3ee3bd05214bc8e9cfc0f816e9bab57a5325f4ee on bandersen23:master into d6f3fa71072f99334a4c1d2a3f062fa93982797f on mmcloughlin:master.

mmcloughlin commented 4 years ago

Thank you for the pull request!

However I will say this feels a little odd to me. Do other similar libraries provide such a function?

bandersen23 commented 4 years ago

I haven’t found any other libraries that have this feature either in my research and since it’s not a standard feature it’s probably worth closing this PR. Thank you for replying though!

mmcloughlin commented 4 years ago

I'm not saying no outright, I just need some convincing. Perhaps you could show a code snippet where this makes things simpler? I'm also fine if you decide to close this.

bandersen23 commented 4 years ago

Used when taking data that might (or may not) have a checksum and dropping the digit to query databases that choose not to include checksum digits. I should add a commit that returns just the string if no luhn checksum value present.

def drop(string):
  """ 
  returns string minus checksum value if checksum exists
  """
  if verify(string):
    return string[:-1]
  else:
    return string

# dataset with multiple columns (df)
# some with luhn checksum (df['a'])
# some without luhn checksum (df['b'])

# need to query fields in another dataset without checksums entirely
my_values = pd.concat([df['a'], df['b'])

my_values = my_values.apply(drop)

# query other dataset now with all normalized values

For context we also use luhn.append to add checksums when we have values from databases that don't contain checksum and look in ones that do.