Conversation
compute_angular_windspeeds declares `cyclostrophic: Optional[bool] = False` but guards its deprecation shim with `if cyclostrophic is not None`. Because `False is not None`, the shim ran on every call, including the internal one from compute_windfields_sparse which never passes the argument. That raised a DeprecationWarning for an argument nobody passed, and overwrote the caller's own `model_kwargs["cyclostrophic"]` with False, making the setting unreachable through the very route the deprecation message recommends. Use None as the sentinel default, and copy model_kwargs so the shim cannot mutate the caller's dict. Existing default behaviour is unchanged: without the injected False, each model falls back to its own signature default (False for H1980, H08 and ER11, True for H10), which is what TropCyclone.from_tracks already documents. Fixes CLIMADA-project#1209
aa0aeb5 to
a1b74d1
Compare
peanutfun
left a comment
There was a problem hiding this comment.
@dylanpulver Thank you for your contribution! I would appreciate if you used your advertised agentic AI systems to shorten your PR description to only include relevant information. It took me some time to figure out what this PR was actually about.
While your changes are obvious and solid, the tests are not. They re-define data that is already present in other tests. Please make sure testing and reference data is only defined once, and then "shared" between tests that are using them. See my comments below.
Review follow-up: - Move the track/centroid inputs and the reference wind speeds into a single source, used by both test_er_2011_pass and the compute_angular_windspeeds tests, instead of re-defining them. - Drop the assertion that the cyclostrophic result differs from the Coriolis one; it cannot be anything else once the first assertion holds. - Add the missing half of the deprecation check: passing the deprecated cyclostrophic argument must warn, not only that omitting it must not. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
|
Thanks — all four addressed, and the description is rewritten to lead with what the PR is about rather than burying it.
One thing I should flag rather than let CI surface it: I could not run the suite for this revision — CLIMADA's geospatial stack does not build in my environment. So instead of asserting the refactor is safe, I parsed both revisions and compared: the shared fixture's literals and |
|
@dylanpulver Thank you! I improved the tests to use the unittest fixture scheme and added an explicit test for the ER 2011 model with |
compute_angular_windspeedsdeclarescyclostrophic: Optional[bool] = Falsebut guards the deprecation shim withif cyclostrophic is not None:. SinceFalse is not None, the shim fires on every call, including internal ones that never pass the argument, and then doesmodel_kwargs["cyclostrophic"] = False— overwriting the caller's own setting withFalse. That makescyclostrophicunreachable throughmodel_kwargs, which is the exact route the deprecation message tells users to take.Fixes #1209.
Changes
cyclostrophicdefaults toNoneinstead ofFalse, so the shim only runs when a caller actually passes it.model_kwargsis copied before the shim writes to it, so a caller's dict is never mutated.Evidence, on
develop, ER11 at r = 30 km (r_max = 40 km, v_max = 40 m/s):_stat_er_2011(..., cyclostrophic=True)_stat_er_2011(..., cyclostrophic=False)compute_angular_windspeeds(..., model_kwargs={"cyclostrophic": True})The third row is the bug: the request is silently ignored. The caller's dict also comes back as
{'cyclostrophic': False}.No change to existing behaviour. Without the injected
cyclostrophic=Falseeach model falls back to its own signature default, which is whatTropCyclone.from_tracksalready documents. Numbers move only for callers who explicitly asked forcyclostrophicand were previously ignored.Tests. Four tests in
TestWindfieldHelpers, asserting values derived from Emanuel and Rotunno (2011) eq. (36) rather than from the code. The first three took the file 9 passed -> 12 and each fails against the unpatched source. The fourth (the warning is raised when the argument is passed) was added in review and is unexecuted here — CLIMADA's geospatial stack will not build in this environment, so CI is the check for it. Inputs and reference values are now defined once and shared withtest_er_2011_pass; I parsed both revisions to confirm the shared fixture and expected array are identical to the literals that test used before, so it is unchanged by construction.black24.4.2 andisort, the pinned versions, report no changes.Two boxes left unticked deliberately:
test_cross_antimeridiandownloads the coast-distance grid from Zenodo (504 here; CI caches it), and I have not run the full suite for this revision.Written with AI assistance; the wind speeds are function output and 38.4 m/s is hand-derived from the published equation.
PR Author Checklist
develop)PR Reviewer Checklist