BUG: fix _contains_nan (#16209)
BUG: fix _contains_nan (#16209)

Co-authored-by: Pamphile Roy <5382f7c16494af1b573fda9cacaa4290463e84b1@gmail.com>
endolith/scipy,Stefan-Endres/scipy,mdhaber/scipy,endolith/scipy,andyfaff/scipy,endolith/scipy,rgommers/scipy,anntzer/scipy,scipy/scipy,mdhaber/scipy,andyfaff/scipy,anntzer/scipy,ilayn/scipy,anntzer/scipy,anntzer/scipy,perimosocordiae/scipy,perimosocordiae/scipy,perimosocordiae/scipy,perimosocordiae/scipy,perimosocordiae/scipy,rgommers/scipy,Stefan-Endres/scipy,scipy/scipy,Stefan-Endres/scipy,WarrenWeckesser/scipy,ilayn/scipy,andyfaff/scipy,scipy/scipy,rgommers/scipy,WarrenWeckesser/scipy,Stefan-Endres/scipy,anntzer/scipy,mdhaber/scipy,WarrenWeckesser/scipy,ilayn/scipy,rgommers/scipy,WarrenWeckesser/scipy,scipy/scipy,mdhaber/scipy,mdhaber/scipy,perimosocordiae/scipy,WarrenWeckesser/scipy,Stefan-Endres/scipy,endolith/scipy,ilayn/scipy,anntzer/scipy,scipy/scipy,ilayn/scipy,endolith/scipy,andyfaff/scipy,rgommers/scipy,andyfaff/scipy,ilayn/scipy,scipy/scipy,Stefan-Endres/scipy,mdhaber/scipy,endolith/scipy,andyfaff/scipy,WarrenWeckesser/scipy