#NEWLINE# def _transform_indices( self , key ) : #NEWLINE# #INDENT# '\n        Transforms indices by snapping to the closest value if\n        values are numeric, otherwise applies no transformation.\n        ' #NEWLINE# ndims = self . ndims #NEWLINE# if all ( ( ( not isinstance ( el , slice ) ) for el in key ) ) : #NEWLINE# #INDENT# dim_inds = [ ] #NEWLINE# for dim in self . kdims : #NEWLINE# #INDENT# dim_type = self . get_dimension_type ( dim ) #NEWLINE# if ( isinstance ( dim_type , type ) and issubclass ( dim_type , Number ) ) : #NEWLINE# #INDENT# dim_inds . append ( self . get_dimension_index ( dim ) ) #NEWLINE# #UNINDENT# #UNINDENT# str_keys = iter ( ( key [ i ] for i in range ( self . ndims ) if ( i not in dim_inds ) ) ) #NEWLINE# num_keys = [ ] #NEWLINE# if len ( dim_inds ) : #NEWLINE# #INDENT# keys = list ( { tuple ( ( ( k [ i ] if ( ndims > 1 ) else k ) for i in dim_inds ) ) for k in self . keys ( ) } ) #NEWLINE# q = np . array ( [ tuple ( ( ( key [ i ] if ( ndims > 1 ) else key ) for i in dim_inds ) ) ] ) #NEWLINE# idx = np . argmin ( [ ( np . inner ( ( q - np . array ( x ) ) , ( q - np . array ( x ) ) ) if ( len ( dim_inds ) == 2 ) else np . abs ( ( q - x ) ) ) for x in keys ] ) #NEWLINE# num_keys = iter ( keys [ idx ] ) #NEWLINE# #UNINDENT# key = tuple ( ( ( next ( num_keys ) if ( i in dim_inds ) else next ( str_keys ) ) for i in range ( self . ndims ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if any ( ( ( not isinstance ( el , slice ) ) for el in key ) ) : #NEWLINE# #INDENT# index_inds = [ idx for ( idx , el ) in enumerate ( key ) if ( not isinstance ( el , ( slice , str ) ) ) ] #NEWLINE# if len ( index_inds ) : #NEWLINE# #INDENT# index_ind = index_inds [ 0 ] #NEWLINE# dim_keys = np . array ( [ k [ index_ind ] for k in self . keys ( ) ] ) #NEWLINE# snapped_val = dim_keys [ np . argmin ( np . abs ( ( dim_keys - key [ index_ind ] ) ) ) ] #NEWLINE# key = list ( key ) #NEWLINE# key [ index_ind ] = snapped_val #NEWLINE# key = tuple ( key ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return key