Fix get_nexrad_location mutating shared NEXRAD_LOCATIONS table - #1879
Fix get_nexrad_location mutating shared NEXRAD_LOCATIONS table#1879Yuxiang-Ren-HUB wants to merge 3 commits into
Conversation
loc is a reference into the shared NEXRAD_LOCATIONS dict, not a copy. Writing the feet->meters conversion back into loc["elev"] mutated the table permanently, so a second call for the same station applied the conversion again and silently corrupted the elevation.
Added unit tests for the nexrad_common module to verify location retrieval and stability across repeated calls.
|
Friendly ping on this one — it looks like no CI has run yet. I believe workflows need a maintainer to approve them for a first-time contributor. |
|
Hey! Patience please! We are updating our contributors guide right now. We are also considering requiring submitters to know who they are as purely AI generated PRs will not be allowed. A real person must review code. We're not saying this is a pure AI generated PR but you do not have much of a GitHub history (as you said) and we need to ensure you are not an agent. If you could let us know who you are in real life that would speed things up. |
|
Great! And greetings! And thanks for the AI disclosure. We'll get to this soon. |
|
Thanks for the reply, and for taking the time to check. |
|
Thank you, much appreciated. |
The previous commit left a single blank line between get_nexrad_location and the following module-level comment block. Black requires two blank lines after a top-level definition, so the Check Black job would have failed once CI is allowed to run. No functional change.
350b88a to
80964ea
Compare
| # converted the already-converted value again, silently corrupting | ||
| # the elevation (e.g. KTLX: 1213 ft -> 369.72 m on the first call, | ||
| # then -> 112.7 m on the second). | ||
| elev_m = loc["elev"] * 0.3048 |
There was a problem hiding this comment.
I think the behavior table values changes should be preserved as some code in the wild may be relying on it. We may add units to know if the height is already changed in meters or not. If yes then conversion will return the values but will not change it back in the table again. This will preserved the behavior.
Problem
get_nexrad_location()converts the station's elevation from feet tometers by writing the result back into the dict it just read from:
locis not a copy -- it's a reference into the shared, module-levelNEXRAD_LOCATIONSdict, so the conversion is applied permanently.Calling
get_nexrad_location()a second time for the same stationapplies the conversion again, silently corrupting the result:
Any code path that calls this function more than once for the same
station -- e.g. processing multiple files/sweeps from the same radar
in one process -- silently gets a wrong altitude after the first call.
Fix
Store the converted elevation in a local variable and return that,
instead of writing back into the shared table.
NEXRAD_LOCATIONSisnow never mutated by this function.
Testing
Added
tests/io/test_nexrad_common.py(previously no dedicated testfile existed for this module):
test_get_nexrad_location_known_station: sanity-checks the returnedlat/lon/elev for a known station.
test_get_nexrad_location_repeated_calls_are_stable: regression testfor this bug -- calls the function 3 times for the same station and
asserts the elevation doesn't change, and that the underlying table
entry stays at its original (feet) value.
Both pass locally.