@@ -371,3 +371,63 @@ def set_default_locators_and_formatters(self, axis):
371371 # cleanup - there's no public unregister_scale()
372372 del mscale ._scale_mapping ["custom" ]
373373 del mscale ._scale_has_axis_parameter ["custom" ]
374+
375+
376+ def test_val_in_range ():
377+
378+ test_cases = [
379+ # LinearScale: Always True (even for Inf/NaN)
380+ ('linear' , 10.0 , True ),
381+ ('linear' , - 10.0 , True ),
382+ ('linear' , 0.0 , True ),
383+ ('linear' , np .inf , True ),
384+ ('linear' , np .nan , True ),
385+
386+ # LogScale: Only positive values (> 0)
387+ ('log' , 1.0 , True ),
388+ ('log' , 1e-300 , True ),
389+ ('log' , 0.0 , False ),
390+ ('log' , - 1.0 , False ),
391+ ('log' , np .inf , True ),
392+ ('log' , np .nan , False ),
393+
394+ # LogitScale: Strictly between 0 and 1
395+ ('logit' , 0.5 , True ),
396+ ('logit' , 0.0 , False ),
397+ ('logit' , 1.0 , False ),
398+ ('logit' , - 0.1 , False ),
399+ ('logit' , 1.1 , False ),
400+ ('logit' , np .inf , False ),
401+ ('logit' , np .nan , False ),
402+
403+ # SymmetricalLogScale: Valid for all real numbers
404+ # Uses ScaleBase fallback. NaN returns False since NaN != NaN
405+ ('symlog' , 10.0 , True ),
406+ ('symlog' , - 10.0 , True ),
407+ ('symlog' , 0.0 , True ),
408+ ('symlog' , np .inf , True ),
409+ ('symlog' , np .nan , False ),
410+ ]
411+
412+ for name , val , expected in test_cases :
413+ scale_cls = mscale ._scale_mapping [name ]
414+ s = scale_cls (axis = None )
415+
416+ result = s .val_in_range (val )
417+ assert result is expected , (
418+ f"Failed { name } .val_in_range({ val } )."
419+ f"Expected { expected } , got { result } "
420+ )
421+
422+
423+ def test_val_in_range_base_fallback ():
424+ # Directly test the ScaleBase fallback for custom scales.
425+ # ScaleBase.limit_range_for_scale returns values unchanged by default
426+ s = mscale .ScaleBase (axis = None )
427+
428+ # Normal values should be True
429+ assert s .val_in_range (1.0 ) is True
430+ assert s .val_in_range (- 5.5 ) is True
431+
432+ # NaN check: fallback uses 'vmin == vmax'
433+ assert s .val_in_range (np .nan ) is False
0 commit comments