Two of the public formatting functions exported in nucos/__init__.py are broken: format_lat_d() raises NameError on every call (it references an undefined variable), and format_lon_d() silently returns degrees + decimal minutes instead of the decimal-degrees format its own docstring promises.
Environment
- NOAA-ORR-ERD/PyNUCOS @
0583706dee5e0df6cc387ab5f759f80265a30414 (nucos 3.4.1, editable install from source)
- Windows 11 Pro (10.0.26200), Python 3.14.5, pytest 9.0.3
- Full shipped test suite passes (494 passed) — neither function has any test coverage, which is how a function that crashes on every call ships green
Reproduction
Save as repro.py and run python repro.py:
import nucos
try:
print(nucos.format_lat_d(33.5))
except NameError as e:
print("format_lat_d(33.5) -> NameError:", e)
print("format_lon_d(-70.25) ->", repr(nucos.format_lon_d(-70.25)))
Observed output
format_lat_d(33.5) -> NameError: name 'degrees' is not defined
format_lon_d(-70.25) -> '70° 15.00′ West'
Expected
-
format_lat_d(33.5) should return '33.50° North' (FORMAT1 = "{:.2f}\N{DEGREE SIGN} {}", lat_long.py:363).
-
format_lon_d(-70.25) should return '70.25° West' — its own docstring (lat_long.py:429-444) says:
Format a floating point number as longitude in
decimal degrees format.
...
In [4]: nucos.format_lon(-33.2)
Out[4]: '33.2° West'
Root cause
-
nucos/lat_long.py:381-383 — format_latlon1 formats a variable that doesn't exist (the parameter is f):
def format_latlon1(f, positive_direction, negative_direction):
direction = positive_direction if f >= 0.0 else negative_direction
return FORMAT1.format(degrees, direction) # NameError: 'degrees'
format_lat_d (lat_long.py:401-402) calls it, so it always crashes.
-
nucos/lat_long.py:446 — format_lon_d calls format_latlon2 (the degrees + decimal-minutes formatter) instead of format_latlon1:
def format_lon_d(degrees):
...
return format_latlon2(degrees, LON_POSITIVE_DIRECTION, LON_NEGATIVE_DIRECTION)
So it doesn't crash — it just returns the wrong format, silently.
Proposed fix
def format_latlon1(f, positive_direction, negative_direction):
direction = positive_direction if f >= 0.0 else negative_direction
- return FORMAT1.format(degrees, direction)
+ return FORMAT1.format(abs(f), direction)
def format_lon_d(degrees):
...
- return format_latlon2(degrees, LON_POSITIVE_DIRECTION, LON_NEGATIVE_DIRECTION)
+ return format_latlon1(degrees, LON_POSITIVE_DIRECTION, LON_NEGATIVE_DIRECTION)
No existing tests encode the broken behavior (there are none for either function — test_lat_long.py covers format_lat_dms/format_lon_dms but not the _d variants); tests for format_lat_d/format_lon_d should be added with the fix.
Related
Distinct from #5 (lat/long string parsing); this is the "new simple API" formatting layer (lat_long.py:351-352).
Happy to submit a PR for this if useful.
Two of the public formatting functions exported in
nucos/__init__.pyare broken:format_lat_d()raisesNameErroron every call (it references an undefined variable), andformat_lon_d()silently returns degrees + decimal minutes instead of the decimal-degrees format its own docstring promises.Environment
0583706dee5e0df6cc387ab5f759f80265a30414(nucos 3.4.1, editable install from source)Reproduction
Save as
repro.pyand runpython repro.py:Observed output
Expected
format_lat_d(33.5)should return'33.50° North'(FORMAT1 = "{:.2f}\N{DEGREE SIGN} {}",lat_long.py:363).format_lon_d(-70.25)should return'70.25° West'— its own docstring (lat_long.py:429-444) says:Root cause
nucos/lat_long.py:381-383—format_latlon1formats a variable that doesn't exist (the parameter isf):format_lat_d(lat_long.py:401-402) calls it, so it always crashes.nucos/lat_long.py:446—format_lon_dcallsformat_latlon2(the degrees + decimal-minutes formatter) instead offormat_latlon1:So it doesn't crash — it just returns the wrong format, silently.
Proposed fix
def format_latlon1(f, positive_direction, negative_direction): direction = positive_direction if f >= 0.0 else negative_direction - return FORMAT1.format(degrees, direction) + return FORMAT1.format(abs(f), direction)def format_lon_d(degrees): ... - return format_latlon2(degrees, LON_POSITIVE_DIRECTION, LON_NEGATIVE_DIRECTION) + return format_latlon1(degrees, LON_POSITIVE_DIRECTION, LON_NEGATIVE_DIRECTION)No existing tests encode the broken behavior (there are none for either function —
test_lat_long.pycoversformat_lat_dms/format_lon_dmsbut not the_dvariants); tests forformat_lat_d/format_lon_dshould be added with the fix.Related
Distinct from #5 (lat/long string parsing); this is the "new simple API" formatting layer (
lat_long.py:351-352).Happy to submit a PR for this if useful.