@@ -175,16 +175,6 @@ def itemsize(self):
175
175
def dtype (self ):
176
176
return self .values .dtype
177
177
178
- def copy (self , deep = True , ref_items = None ):
179
- values = self .values
180
- if deep :
181
- values = values .copy ()
182
- if ref_items is None :
183
- ref_items = self .ref_items
184
- return make_block (
185
- values , self .items , ref_items , ndim = self .ndim , klass = self .__class__ ,
186
- fastpath = True , placement = self ._ref_locs )
187
-
188
178
@property
189
179
def ftype (self ):
190
180
return "%s:%s" % (self .dtype , self ._ftype )
@@ -293,17 +283,23 @@ def split_block_at(self, item):
293
283
def fillna (self , value , inplace = False , downcast = None ):
294
284
if not self ._can_hold_na :
295
285
if inplace :
296
- return self
286
+ return [ self ]
297
287
else :
298
- return self .copy ()
288
+ return [ self .copy ()]
299
289
300
290
mask = com .isnull (self .values )
301
291
value = self ._try_fill (value )
302
292
blocks = self .putmask (mask , value , inplace = inplace )
303
293
304
- if downcast :
305
- blocks = [ b .downcast () for b in blocks ]
306
- return blocks
294
+ # possibily downcast the blocks
295
+ if not downcast :
296
+ return blocks
297
+
298
+ result_blocks = []
299
+ for b in blocks :
300
+ result_blocks .extend (b .downcast ())
301
+
302
+ return result_blocks
307
303
308
304
def downcast (self , dtypes = None ):
309
305
""" try to downcast each item to the dict of dtypes if present """
@@ -361,14 +357,14 @@ def _astype(self, dtype, copy=False, raise_on_error=True, values=None,
361
357
"(%s [%s]) with smaller itemsize that current "
362
358
"(%s [%s])" % (copy , self .dtype .name ,
363
359
self .itemsize , newb .dtype .name , newb .itemsize ))
364
- return newb
360
+ return [ newb ]
365
361
366
362
def convert (self , copy = True , ** kwargs ):
367
363
""" attempt to coerce any object types to better types
368
364
return a copy of the block (if copy = True)
369
365
by definition we are not an ObjectBlock here! """
370
366
371
- return self .copy () if copy else self
367
+ return [ self .copy () ] if copy else [ self ]
372
368
373
369
def prepare_for_merge (self , ** kwargs ):
374
370
""" a regular block is ok to merge as is """
@@ -428,6 +424,17 @@ def to_native_types(self, slicer=None, na_rep='', **kwargs):
428
424
values [mask ] = na_rep
429
425
return values .tolist ()
430
426
427
+ #### block actions ####
428
+ def copy (self , deep = True , ref_items = None ):
429
+ values = self .values
430
+ if deep :
431
+ values = values .copy ()
432
+ if ref_items is None :
433
+ ref_items = self .ref_items
434
+ return make_block (
435
+ values , self .items , ref_items , ndim = self .ndim , klass = self .__class__ ,
436
+ fastpath = True , placement = self ._ref_locs )
437
+
431
438
def replace (self , to_replace , value , inplace = False , filter = None ,
432
439
regex = False ):
433
440
""" replace the to_replace value with value, possible to create new
@@ -541,7 +548,7 @@ def create_block(v, m, n, item, reshape=True):
541
548
if inplace :
542
549
return [self ]
543
550
544
- return make_block (new_values , self .items , self .ref_items , fastpath = True )
551
+ return [ make_block (new_values , self .items , self .ref_items , fastpath = True )]
545
552
546
553
def interpolate (self , method = 'pad' , axis = 0 , inplace = False ,
547
554
limit = None , missing = None , coerce = False ):
@@ -551,20 +558,20 @@ def interpolate(self, method='pad', axis=0, inplace=False,
551
558
if coerce :
552
559
if not self ._can_hold_na :
553
560
if inplace :
554
- return self
561
+ return [ self ]
555
562
else :
556
- return self .copy ()
563
+ return [ self .copy ()]
557
564
558
565
values = self .values if inplace else self .values .copy ()
559
566
values = com .interpolate_2d (values , method , axis , limit , missing )
560
- return make_block (values , self .items , self .ref_items , ndim = self .ndim , klass = self .__class__ , fastpath = True )
567
+ return [ make_block (values , self .items , self .ref_items , ndim = self .ndim , klass = self .__class__ , fastpath = True )]
561
568
562
569
def take (self , indexer , ref_items , axis = 1 ):
563
570
if axis < 1 :
564
571
raise AssertionError ('axis must be at least 1, got %d' % axis )
565
572
new_values = com .take_nd (self .values , indexer , axis = axis ,
566
573
allow_fill = False )
567
- return make_block (new_values , self .items , ref_items , ndim = self .ndim , klass = self .__class__ , fastpath = True )
574
+ return [ make_block (new_values , self .items , ref_items , ndim = self .ndim , klass = self .__class__ , fastpath = True )]
568
575
569
576
def get_values (self , dtype = None ):
570
577
return self .values
@@ -575,7 +582,7 @@ def get_merge_length(self):
575
582
def diff (self , n ):
576
583
""" return block for the diff of the values """
577
584
new_values = com .diff (self .values , n , axis = 1 )
578
- return make_block (new_values , self .items , self .ref_items , ndim = self .ndim , fastpath = True )
585
+ return [ make_block (new_values , self .items , self .ref_items , ndim = self .ndim , fastpath = True )]
579
586
580
587
def shift (self , indexer , periods ):
581
588
""" shift the block by periods, possibly upcast """
@@ -588,7 +595,7 @@ def shift(self, indexer, periods):
588
595
new_values [:, :periods ] = fill_value
589
596
else :
590
597
new_values [:, periods :] = fill_value
591
- return make_block (new_values , self .items , self .ref_items , ndim = self .ndim , fastpath = True )
598
+ return [ make_block (new_values , self .items , self .ref_items , ndim = self .ndim , fastpath = True )]
592
599
593
600
def eval (self , func , other , raise_on_error = True , try_cast = False ):
594
601
"""
@@ -644,7 +651,7 @@ def eval(self, func, other, raise_on_error=True, try_cast=False):
644
651
if try_cast :
645
652
result = self ._try_cast_result (result )
646
653
647
- return make_block (result , self .items , self .ref_items , ndim = self .ndim , fastpath = True )
654
+ return [ make_block (result , self .items , self .ref_items , ndim = self .ndim , fastpath = True )]
648
655
649
656
def where (self , other , cond , raise_on_error = True , try_cast = False ):
650
657
"""
@@ -1054,6 +1061,14 @@ def _try_fill(self, value):
1054
1061
value = tslib .iNaT
1055
1062
return value
1056
1063
1064
+ def fillna (self , value , inplace = False , downcast = None ):
1065
+ values = self .values if inplace else self .values .copy ()
1066
+ mask = com .isnull (self .values )
1067
+ value = self ._try_fill (value )
1068
+ np .putmask (values ,mask ,value )
1069
+ return [self if inplace else make_block (values , self .items ,
1070
+ self .ref_items , fastpath = True )]
1071
+
1057
1072
def to_native_types (self , slicer = None , na_rep = None , ** kwargs ):
1058
1073
""" convert to our native types format, slicing if desired """
1059
1074
@@ -1250,7 +1265,7 @@ def fillna(self, value, inplace=False, downcast=None):
1250
1265
if issubclass (self .dtype .type , np .floating ):
1251
1266
value = float (value )
1252
1267
values = self .values if inplace else self .values .copy ()
1253
- return self .make_block (values .get_values (value ), fill_value = value )
1268
+ return [ self .make_block (values .get_values (value ), fill_value = value ) ]
1254
1269
1255
1270
def shift (self , indexer , periods ):
1256
1271
""" shift the block by periods """
@@ -1263,15 +1278,15 @@ def shift(self, indexer, periods):
1263
1278
new_values [:periods ] = fill_value
1264
1279
else :
1265
1280
new_values [periods :] = fill_value
1266
- return self .make_block (new_values )
1281
+ return [ self .make_block (new_values ) ]
1267
1282
1268
1283
def take (self , indexer , ref_items , axis = 1 ):
1269
1284
""" going to take our items
1270
1285
along the long dimension"""
1271
1286
if axis < 1 :
1272
1287
raise AssertionError ('axis must be at least 1, got %d' % axis )
1273
1288
1274
- return self .make_block (self .values .take (indexer ))
1289
+ return [ self .make_block (self .values .take (indexer )) ]
1275
1290
1276
1291
def reindex_axis (self , indexer , method = None , axis = 1 , fill_value = None , limit = None , mask_info = None ):
1277
1292
"""
0 commit comments