open-location-code icon indicating copy to clipboard operation
open-location-code copied to clipboard

Python: recoverNearest implementation does not do what documentation says it does

Open shoeper opened this issue 9 years ago • 2 comments

While the documentation says it returns an unchanged code for full code input, it actually raises a ValueError instead.

 Returns:
   The nearest full Open Location Code to the reference location that matches
   the short code. If the passed code was not a valid short code, but was a
   valid full code, it is returned unchanged.
openlocationcode.recoverNearest("9FMC3QQP+29", 0.0, 0.0)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/shoeper/Documents/dev/jodelbot/libs/openlocationcode.py", line 285, in recoverNearest
    raise ValueError('Passed short code is not valid - ' + str(shortcode))
ValueError: Passed short code is not valid - 9FMC3QQP+29
# expected output would be 9FMC3QQP+29
openlocationcode.recoverNearest("3QQP+29", 0.0, 0.0)
'6CGX3QQP+29'

shoeper avatar Dec 02 '17 21:12 shoeper

I find the word unchanged in the function documentation a bit misleading. The OLC specification states:

  1. Open Location Code implementations must return upper case codes. They must include the "+" character and zero padding when returning codes.

Should the function return the original, unchanged code or the uppercase code?

salvioner avatar Dec 11 '17 18:12 salvioner

From my point of view this has been fixed in #129.

And it looks like your comments are also part of the change.

shoeper avatar Jan 16 '18 16:01 shoeper