@@ -125,15 +125,9 @@ def reindex_axis(self, indexer, mask, needs_masking, axis=0,
125125 """
126126 Reindex using pre-computed indexer information
127127 """
128- if self .values .size > 0 :
129- new_values = com .take_fast (self .values , indexer , mask ,
130- needs_masking , axis = axis ,
131- fill_value = fill_value )
132- else :
133- shape = list (self .shape )
134- shape [axis ] = len (indexer )
135- new_values = np .empty (shape )
136- new_values .fill (fill_value )
128+ new_values = com .take_fast (self .values , indexer ,
129+ mask , needs_masking , axis = axis ,
130+ fill_value = fill_value )
137131 return make_block (new_values , self .items , self .ref_items )
138132
139133 def reindex_items_from (self , new_ref_items , copy = True ):
@@ -155,12 +149,9 @@ def reindex_items_from(self, new_ref_items, copy=True):
155149 mask = indexer != - 1
156150 masked_idx = indexer [mask ]
157151
158- if self .values .ndim == 2 :
159- new_values = com .take_2d (self .values , masked_idx , axis = 0 ,
160- needs_masking = False )
161- else :
162- new_values = self .values .take (masked_idx , axis = 0 )
163-
152+ new_values = com .take_fast (self .values , masked_idx ,
153+ mask = None , needs_masking = False ,
154+ axis = 0 )
164155 new_items = self .items .take (masked_idx )
165156 return make_block (new_values , new_items , new_ref_items )
166157
@@ -301,24 +292,23 @@ def putmask(self, mask, new, inplace=False):
301292 new_values = self .values if inplace else self .values .copy ()
302293
303294 # may need to align the new
304- if hasattr (new ,'reindex_axis' ):
305- axis = getattr (new ,'_het_axis' ,0 )
295+ if hasattr (new , 'reindex_axis' ):
296+ axis = getattr (new , '_het_axis' , 0 )
306297 new = new .reindex_axis (self .items , axis = axis , copy = False ).values .T
307298
308299 # may need to align the mask
309- if hasattr (mask ,'reindex_axis' ):
310- axis = getattr (mask ,'_het_axis' ,0 )
300+ if hasattr (mask , 'reindex_axis' ):
301+ axis = getattr (mask , '_het_axis' , 0 )
311302 mask = mask .reindex_axis (self .items , axis = axis , copy = False ).values .T
312303
313304 if self ._can_hold_element (new ):
314305 new = self ._try_cast (new )
315306 np .putmask (new_values , mask , new )
316-
317307 # upcast me
318308 else :
319-
320309 # type of the new block
321- if isinstance (new ,np .ndarray ) and issubclass (new .dtype ,np .number ) or issubclass (type (new ),float ):
310+ if ((isinstance (new , np .ndarray ) and issubclass (new .dtype , np .number )) or
311+ isinstance (new , float )):
322312 typ = float
323313 else :
324314 typ = object
@@ -369,9 +359,8 @@ def interpolate(self, method='pad', axis=0, inplace=False,
369359 def take (self , indexer , axis = 1 , fill_value = np .nan ):
370360 if axis < 1 :
371361 raise AssertionError ('axis must be at least 1, got %d' % axis )
372- new_values = com .take_fast (self .values , indexer , None ,
373- None , axis = axis ,
374- fill_value = fill_value )
362+ new_values = com .take_fast (self .values , indexer , None , False ,
363+ axis = axis , fill_value = fill_value )
375364 return make_block (new_values , self .items , self .ref_items )
376365
377366 def get_values (self , dtype ):
@@ -401,22 +390,21 @@ def where(self, func, other, cond = None, raise_on_error = True, try_cast = Fals
401390
402391 Parameters
403392 ----------
404- func : how to combine self,other
393+ func : how to combine self, other
405394 other : a ndarray/object
406395 cond : the condition to respect, optional
407- raise_on_error : if True, raise when I can't perform the function, False by default (and just return
408- the data that we had coming in)
396+ raise_on_error : if True, raise when I can't perform the function,
397+ False by default (and just return the data that we had coming in)
409398
410399 Returns
411400 -------
412401 a new block, the result of the func
413402 """
414-
415403 values = self .values
416404
417405 # see if we can align other
418- if hasattr (other ,'reindex_axis' ):
419- axis = getattr (other ,'_het_axis' ,0 )
406+ if hasattr (other , 'reindex_axis' ):
407+ axis = getattr (other , '_het_axis' , 0 )
420408 other = other .reindex_axis (self .items , axis = axis , copy = True ).values
421409
422410 # make sure that we can broadcast
@@ -428,17 +416,20 @@ def where(self, func, other, cond = None, raise_on_error = True, try_cast = Fals
428416
429417 # see if we can align cond
430418 if cond is not None :
431- if not hasattr (cond ,'shape' ):
432- raise ValueError ("where must have a condition that is ndarray like" )
433- if hasattr (cond ,'reindex_axis' ):
434- axis = getattr (cond ,'_het_axis' ,0 )
435- cond = cond .reindex_axis (self .items , axis = axis , copy = True ).values
419+ if not hasattr (cond , 'shape' ):
420+ raise ValueError ('where must have a condition that is ndarray'
421+ ' like' )
422+ if hasattr (cond , 'reindex_axis' ):
423+ axis = getattr (cond , '_het_axis' , 0 )
424+ cond = cond .reindex_axis (self .items , axis = axis ,
425+ copy = True ).values
436426 else :
437427 cond = cond .values
438428
439429 # may need to undo transpose of values
440430 if hasattr (values , 'ndim' ):
441- if values .ndim != cond .ndim or values .shape == cond .shape [::- 1 ]:
431+ if (values .ndim != cond .ndim or
432+ values .shape == cond .shape [::- 1 ]):
442433 values = values .T
443434 is_transposed = not is_transposed
444435
@@ -494,7 +485,7 @@ class FloatBlock(NumericBlock):
494485
495486 def _can_hold_element (self , element ):
496487 if isinstance (element , np .ndarray ):
497- return issubclass (element .dtype .type , (np .floating ,np .integer ))
488+ return issubclass (element .dtype .type , (np .floating , np .integer ))
498489 return isinstance (element , (float , int ))
499490
500491 def _try_cast (self , element ):
@@ -541,7 +532,8 @@ def _try_cast(self, element):
541532 def _try_cast_result (self , result ):
542533 # this is quite restrictive to convert
543534 try :
544- if isinstance (result , np .ndarray ) and issubclass (result .dtype .type , np .floating ):
535+ if (isinstance (result , np .ndarray ) and
536+ issubclass (result .dtype .type , np .floating )):
545537 if com .notnull (result ).all ():
546538 new_result = result .astype (self .dtype )
547539 if (new_result == result ).all ():
@@ -958,7 +950,8 @@ def _get_clean_block_types(self, type_list):
958950 return type_list
959951
960952 def get_bool_data (self , copy = False , as_blocks = False ):
961- return self .get_numeric_data (copy = copy , type_list = (BoolBlock ,), as_blocks = as_blocks )
953+ return self .get_numeric_data (copy = copy , type_list = (BoolBlock ,),
954+ as_blocks = as_blocks )
962955
963956 def get_slice (self , slobj , axis = 0 ):
964957 new_axes = list (self .axes )
@@ -1429,7 +1422,7 @@ def take(self, indexer, axis=1):
14291422 if axis == 0 :
14301423 raise NotImplementedError
14311424
1432- indexer = np . asarray (indexer , dtype = 'i4' )
1425+ indexer = com . _ensure_platform_int (indexer )
14331426
14341427 n = len (self .axes [axis ])
14351428 if ((indexer == - 1 ) | (indexer >= n )).any ():
@@ -1440,8 +1433,8 @@ def take(self, indexer, axis=1):
14401433 new_axes [axis ] = self .axes [axis ].take (indexer )
14411434 new_blocks = []
14421435 for blk in self .blocks :
1443- new_values = com .take_fast (blk .values , indexer ,
1444- None , False , axis = axis )
1436+ new_values = com .take_fast (blk .values , indexer , None , False ,
1437+ axis = axis )
14451438 newb = make_block (new_values , blk .items , self .items )
14461439 new_blocks .append (newb )
14471440
@@ -1765,8 +1758,6 @@ def _consolidate(blocks, items):
17651758 return new_blocks
17661759
17671760
1768- # TODO: this could be much optimized
1769-
17701761def _merge_blocks (blocks , items ):
17711762 if len (blocks ) == 1 :
17721763 return blocks [0 ]
0 commit comments