@@ -32,6 +32,9 @@ def __init__(self, values, items, ref_items, ndim=2):
32
32
self .items = _ensure_index (items )
33
33
self .ref_items = _ensure_index (ref_items )
34
34
35
+ def _gi (self , arg ):
36
+ return self .values [arg ]
37
+
35
38
@property
36
39
def ref_locs (self ):
37
40
if self ._ref_locs is None :
@@ -229,20 +232,20 @@ def replace(self, to_replace, value, inplace=False):
229
232
if not isinstance (to_replace , (list , np .ndarray )):
230
233
if self ._can_hold_element (to_replace ):
231
234
to_replace = self ._try_cast (to_replace )
232
- np . putmask ( new_values , com .mask_missing (new_values , to_replace ),
233
- value )
235
+ msk = com .mask_missing (new_values , to_replace )
236
+ np . putmask ( new_values , msk , value )
234
237
else :
235
238
try :
236
239
to_replace = np .array (to_replace , dtype = self .dtype )
237
- np . putmask ( new_values , com .mask_missing (new_values , to_replace ),
238
- value )
239
- except :
240
+ msk = com .mask_missing (new_values , to_replace )
241
+ np . putmask ( new_values , msk , value )
242
+ except Exception :
240
243
to_replace = np .array (to_replace , dtype = object )
241
244
for r in to_replace :
242
245
if self ._can_hold_element (r ):
243
246
r = self ._try_cast (r )
244
- np . putmask ( new_values , com .mask_missing (new_values , to_replace ),
245
- value )
247
+ msk = com .mask_missing (new_values , to_replace )
248
+ np . putmask ( new_values , msk , value )
246
249
247
250
if inplace :
248
251
return self
@@ -312,8 +315,6 @@ def _mask_missing(array, missing_values):
312
315
mask |= array == missing_values
313
316
return mask
314
317
315
- #-------------------------------------------------------------------------------
316
- # Is this even possible?
317
318
318
319
class FloatBlock (Block ):
319
320
_can_hold_na = True
@@ -332,6 +333,7 @@ def should_store(self, value):
332
333
# unnecessarily
333
334
return issubclass (value .dtype .type , np .floating )
334
335
336
+
335
337
class ComplexBlock (Block ):
336
338
_can_hold_na = True
337
339
@@ -347,6 +349,7 @@ def _try_cast(self, element):
347
349
def should_store (self , value ):
348
350
return issubclass (value .dtype .type , np .complexfloating )
349
351
352
+
350
353
class IntBlock (Block ):
351
354
_can_hold_na = False
352
355
@@ -362,6 +365,7 @@ def _try_cast(self, element):
362
365
def should_store (self , value ):
363
366
return com .is_integer_dtype (value )
364
367
368
+
365
369
class BoolBlock (Block ):
366
370
_can_hold_na = False
367
371
@@ -377,6 +381,7 @@ def _try_cast(self, element):
377
381
def should_store (self , value ):
378
382
return issubclass (value .dtype .type , np .bool_ )
379
383
384
+
380
385
class ObjectBlock (Block ):
381
386
_can_hold_na = True
382
387
@@ -402,6 +407,9 @@ def __init__(self, values, items, ref_items, ndim=2):
402
407
403
408
Block .__init__ (self , values , items , ref_items , ndim = ndim )
404
409
410
+ def _gi (self , arg ):
411
+ return lib .Timestamp (self .values [arg ])
412
+
405
413
def _can_hold_element (self , element ):
406
414
return com .is_integer (element ) or isinstance (element , datetime )
407
415
@@ -807,10 +815,9 @@ def fast_2d_xs(self, loc, copy=False):
807
815
n = len (items )
808
816
result = np .empty (n , dtype = dtype )
809
817
for blk in self .blocks :
810
- values = blk .values
811
818
for j , item in enumerate (blk .items ):
812
819
i = items .get_loc (item )
813
- result [i ] = values [ j , loc ]
820
+ result [i ] = blk . _gi (( j , loc ))
814
821
815
822
return result
816
823
0 commit comments