Skip to content

grass.script: Fix sign and hemisphere handling in float_or_dms - #7932

Merged
petrasovaa merged 2 commits into
OSGeo:mainfrom
bhuvan-somisetty:fix-float-or-dms-sign
Sep 29, 2026
Merged

petrasovaa merged 2 commits into
OSGeo:mainfrom
bhuvan-somisetty:fix-float-or-dms-sign

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor

Description

grass.script.utils.float_or_dms() now applies a leading - and a trailing
S or W hemisphere letter to the whole value. An empty string now raises
ValueError instead of IndexError.

Motivation and context

Fixes #7931.

Previously float_or_dms("-26:45:30") returned -25.24 because the minus sign
only affected the degrees term, and "26:45:30S" returned a positive value
because the letter was dropped without negating.

r.import strips the hemisphere letter before calling the function, so its
behavior is unchanged.

How has this been tested?

  • Added a parametrized pytest test and an empty-string test in
    python/grass/script/tests/utils_test.py.
  • Added doctests for the negative cases to the docstring.
  • pytest python/grass/script/tests/utils_test.py passes, and
    ruff check and ruff format --check are clean.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

A leading minus sign was applied only to the degrees term, so
"-26:45:30" evaluated to -25.24 instead of -26.76. A trailing S or W
letter was dropped without negating the value. Apply the sign and
hemisphere to the whole value. An empty string now raises ValueError
instead of IndexError.

Fixes OSGeo#7931
@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite labels Sep 21, 2026
@petrasovaa

Copy link
Copy Markdown
Contributor

Thank you, could you also update r.import code since the workaround there is not needed anymore?

Since float_or_dms now natively handles hemisphere letters and signs,
remove the manual slicing and negation workaround in r.import.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@github-actions github-actions Bot added raster Related to raster data processing module labels Sep 25, 2026
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Done! I've updated r.import to call gs.float_or_dms() directly without the manual hemisphere slicing and negation workaround.

@petrasovaa petrasovaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@petrasovaa
petrasovaa merged commit 2162f86 into OSGeo:main Sep 29, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] grass.script.utils.float_or_dms() mishandles negative DMS and S/W suffix

2 participants