Fix: Resolve TypeError for None variant in plot_frequencies_map_markers (#725)#1030
Fix: Resolve TypeError for None variant in plot_frequencies_map_markers (#725)#1030ArnabTechiee wants to merge 7 commits into
Conversation
|
Hi @ArnabTechiee, Your solution does remove the error message but doesn't really solve the problem (which was that |
|
Hi @jonbrenas, Thank you for the review, and that is a very fair point. You are absolutely right—my current fix treats the symptom (the TypeError) rather than the underlying root cause. To answer your question on my original reasoning: Because ipywidgets (like Dropdowns) often experience brief transitional states—such as during initial rendering or when options are being asynchronously updated—the widget's internal value can temporarily default to None. I assumed the test suite (test_dipclust.py) was simply catching this transient UI initialization state. I added the early return in the core function to gracefully handle that temporary state without crashing the user's Jupyter cell. The better approach moving forward: Instead, we should handle this at the UI boundary. I propose removing my changes to the plotting function and instead creating a wrapper function (_update_map) inside plot_frequencies_interactive_map. This wrapper will: Act as a UI shield: It will filter out the temporary None values emitted by the widgets during initialization and only pass valid data downstream. Improve the interactive call: By defining the wrapper inside the function (closure capture), we avoid having to pass freq_map and ds as clunky ipywidgets.fixed() arguments. Add future-proofing: We can also check taxon and period for None so if those dropdowns ever glitch in the same way, the shield catches them too. Does moving the logic upstream to the widget boundary align better with how you'd like to handle this? If so, I will happily refactor this PR (and fix the trailing newline linting failure that just popped up, too!). Thanks for pushing me to find the cleaner architectural solution! |
8c74de4 to
ed1e649
Compare
Removed unnecessary closing parenthesis in widget layout.
Description
This PR addresses the lingering
TypeErrorreported in Issue #725 during the test suite runs (specifically originating fromtest_dipclust.py).The Bug:
When
plot_frequencies_interactive_mapinitializes itsipywidgets.Dropdownfor thevariantparameter, the widget briefly holds a value ofNonebefore the data is fully populated. Because theplot_frequencies_map_markersfunction strictly enforcedvariant: Union[int, str], thetypeguardlibrary threw aTypeError.The Fix:
plot_frequencies_map_markerstoOptional[Union[int, str]].if variant is None: return) right after the widget imports to safely catch the initial unpopulated state and prevent the downstreamAssertionError.All tests in
tests/anoph/test_dipclust.pynow pass with zero warnings.Resolves: #725