@@ -312,11 +312,11 @@ def ftype(self):
312
312
def merge (self , other ):
313
313
return _merge_blocks ([self , other ])
314
314
315
- def concat_same_type (self , others ):
315
+ def concat_same_type (self , to_concat ):
316
316
"""
317
317
Concatenate list of single blocks of the same type.
318
318
"""
319
- values = np .concatenate ([self .values ] + [ o . values for o in others ])
319
+ values = np .concatenate ([blk .values for blk in to_concat ])
320
320
return self .make_block_same_class (
321
321
values , placement = slice (0 , len (values ), 1 ))
322
322
@@ -2415,6 +2415,19 @@ def to_native_types(self, slicer=None, na_rep='', quoting=None, **kwargs):
2415
2415
# we are expected to return a 2-d ndarray
2416
2416
return values .reshape (1 , len (values ))
2417
2417
2418
+ def concat_same_type (self , to_concat ):
2419
+ """
2420
+ Concatenate list of single blocks of the same type.
2421
+ """
2422
+ to_concat = [blk .values for blk in to_concat ]
2423
+ values = _concat ._concat_categorical (to_concat )
2424
+
2425
+ if is_categorical_dtype (values .dtype ):
2426
+ return self .make_block_same_class (
2427
+ values , placement = slice (0 , len (values ), 1 ))
2428
+ else :
2429
+ return make_block (values , placement = slice (0 , len (values ), 1 ))
2430
+
2418
2431
2419
2432
class DatetimeBlock (DatetimeLikeBlockMixin , Block ):
2420
2433
__slots__ = ()
@@ -2692,20 +2705,18 @@ def shift(self, periods, axis=0, mgr=None):
2692
2705
return [self .make_block_same_class (new_values ,
2693
2706
placement = self .mgr_locs )]
2694
2707
2695
- def concat_same_type (self , others ):
2708
+ def concat_same_type (self , to_concat ):
2696
2709
"""
2697
2710
Concatenate list of single blocks of the same type.
2698
2711
"""
2699
- # can maybe replace
2700
- # from pandas.core.dtypes.concat._concat_datetimetz ?
2701
- to_concat = [self .values ] + [o .values for o in others ]
2702
-
2703
- if len (set ([str (x .dtype ) for x in to_concat ])) != 1 :
2704
- raise ValueError ('to_concat must have the same tz' )
2712
+ to_concat = [blk .values for blk in to_concat ]
2713
+ values = _concat ._concat_datetime (to_concat )
2705
2714
2706
- values = to_concat [0 ]._concat_same_dtype (to_concat , None )
2707
- return self .make_block_same_class (
2708
- values , placement = slice (0 , len (values ), 1 ))
2715
+ if is_datetimetz (values ):
2716
+ return self .make_block_same_class (
2717
+ values , placement = slice (0 , len (values ), 1 ))
2718
+ else :
2719
+ return make_block (values , placement = slice (0 , len (values ), 1 ))
2709
2720
2710
2721
2711
2722
class SparseBlock (NonConsolidatableMixIn , Block ):
@@ -2874,6 +2885,18 @@ def sparse_reindex(self, new_index):
2874
2885
return self .make_block_same_class (values , sparse_index = new_index ,
2875
2886
placement = self .mgr_locs )
2876
2887
2888
+ def concat_same_type (self , to_concat ):
2889
+ """
2890
+ Concatenate list of single blocks of the same type.
2891
+ """
2892
+ to_concat = [blk .values for blk in to_concat ]
2893
+ values = _concat ._concat_sparse (to_concat )
2894
+
2895
+ return self .make_block_same_class (
2896
+ values , placement = slice (0 , len (values ), 1 ))
2897
+ #else:
2898
+ # return make_block(values, placement=slice(0, len(values), 1))
2899
+
2877
2900
2878
2901
def make_block (values , placement , klass = None , ndim = None , dtype = None ,
2879
2902
fastpath = False ):
0 commit comments