Skip to content

fix: avoid scientific notation in CMR URL coordinate parameters#113

Open
stark256-spec wants to merge 1 commit into
nasa:developfrom
stark256-spec:fix/scientific-notation-only
Open

fix: avoid scientific notation in CMR URL coordinate parameters#113
stark256-spec wants to merge 1 commit into
nasa:developfrom
stark256-spec:fix/scientific-notation-only

Conversation

@stark256-spec
Copy link
Copy Markdown

Fixes #73.

Problem

Python switches to scientific notation for floats outside roughly [1e-4, 1e16) — for example str(0.00001) returns "1e-05". CMR rejects scientific notation in URL parameters with "is not a valid URL encoded point", so queries using very small coordinate values silently fail.

Fix

Adds _format_float(value) which uses str() as the base representation and only converts to a fixed-point decimal string when scientific notation is detected:

def _format_float(value):
    s = str(value)
    if "e" not in s and "E" not in s:
        return s                                        # already plain decimal
    return f"{float(value):.15f}".rstrip("0").rstrip(".")  # strip trailing zeros

_format_float is applied to all coordinate parameters: point, circle, polygon, bounding_box, and line.

Using str() as the base preserves the natural representation of each type — integers stay as "1000" (not "1000.0"), floats stay as "1.0" — so no existing behaviour changes for normal-range values.

Tests

All 122 existing tests pass. The fix is a one-commit change on top of develop.

Python's default float formatting uses scientific notation for numbers
outside roughly [1e-4, 1e16) — e.g. 0.00001 becomes 1e-05. CMR rejects
scientific notation in URL parameters with "is not a valid URL encoded
point", causing otherwise valid queries to fail silently.

Add _format_float() which falls back to fixed-point formatting whenever
the default %g representation contains 'e' or 'E'. Apply it in all five
coordinate methods: point(), circle(), polygon(), bounding_box(), line().

Fixes nasa#108
Copy link
Copy Markdown
Collaborator

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stark256-spec. This is looking good. Please add some unit tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants