#NEWLINE# def find_range( values , soft_range = [ ] ) : #NEWLINE# #INDENT# '\n    Safely finds either the numerical min and max of\n    a set of values, falling back to the first and\n    the last value in the sorted list of values.\n    ' #NEWLINE# try : #NEWLINE# #INDENT# values = np . array ( soft_range ) #NEWLINE# values = ( np . squeeze ( values ) if ( len ( values . shape ) > 1 ) else values ) #NEWLINE# if len ( soft_range ) : #NEWLINE# #INDENT# values = np . concatenate ( [ values , soft_range ] ) #NEWLINE# #UNINDENT# if ( values . dtype . kind == 'M' ) : #NEWLINE# #INDENT# return ( values . min ( ) , values . max ( ) ) #NEWLINE# #UNINDENT# return ( np . nanmin ( values ) , np . nanmax ( values ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# values = sorted ( values ) #NEWLINE# return ( values [ 0 ] , values [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return ( None , None )