@@ -168,17 +168,11 @@ def make_block(self, values, placement=None, ndim=None, **kwargs):
168168
169169 return make_block (values , placement = placement , ndim = ndim , ** kwargs )
170170
171- def make_block_same_class (self , values , placement , copy = False , fastpath = True ,
172- ** kwargs ):
173- """
174- Wrap given values in a block of same type as self.
175-
176- `kwargs` are used in SparseBlock override.
177-
178- """
179- if copy :
180- values = values .copy ()
181- return make_block (values , placement , klass = self .__class__ ,
171+ def make_block_same_class (self , values , placement = None , fastpath = True , ** kwargs ):
172+ """ Wrap given values in a block of same type as self. """
173+ if placement is None :
174+ placement = self .mgr_locs
175+ return make_block (values , placement = placement , klass = self .__class__ ,
182176 fastpath = fastpath , ** kwargs )
183177
184178 @mgr_locs .setter
@@ -573,12 +567,11 @@ def to_native_types(self, slicer=None, na_rep='nan', quoting=None, **kwargs):
573567
574568 # block actions ####
575569 def copy (self , deep = True , mgr = None ):
570+ """ copy constructor """
576571 values = self .values
577572 if deep :
578573 values = values .copy ()
579- return self .make_block (values ,
580- klass = self .__class__ ,
581- fastpath = True )
574+ return self .make_block_same_class (values )
582575
583576 def replace (self , to_replace , value , inplace = False , filter = None ,
584577 regex = False , convert = True , mgr = None ):
@@ -2140,6 +2133,13 @@ def __init__(self, values, placement, ndim=2,
21402133 placement = placement ,
21412134 ndim = ndim ,
21422135 ** kwargs )
2136+ def copy (self , deep = True , mgr = None ):
2137+ """ copy constructor """
2138+ values = self .values
2139+ if deep :
2140+ values = values .copy (deep = True )
2141+ return self .make_block_same_class (values )
2142+
21432143 def external_values (self ):
21442144 """ we internally represent the data as a DatetimeIndex, but for external
21452145 compat with ndarray, export as a ndarray of Timestamps """
@@ -3257,10 +3257,14 @@ def get_scalar(self, tup):
32573257 full_loc = list (ax .get_loc (x )
32583258 for ax , x in zip (self .axes , tup ))
32593259 blk = self .blocks [self ._blknos [full_loc [0 ]]]
3260- full_loc [ 0 ] = self . _blklocs [ full_loc [ 0 ]]
3260+ values = blk . values
32613261
32623262 # FIXME: this may return non-upcasted types?
3263- return blk .values [tuple (full_loc )]
3263+ if values .ndim == 1 :
3264+ return values [full_loc [1 ]]
3265+
3266+ full_loc [0 ] = self ._blklocs [full_loc [0 ]]
3267+ return values [tuple (full_loc )]
32643268
32653269 def delete (self , item ):
32663270 """
@@ -4415,11 +4419,14 @@ def _putmask_smart(v, m, n):
44154419 try :
44164420 nn = n [m ]
44174421 nn_at = nn .astype (v .dtype )
4418- comp = (nn == nn_at )
4419- if is_list_like (comp ) and comp .all ():
4420- nv = v .copy ()
4421- nv [m ] = nn_at
4422- return nv
4422+
4423+ # avoid invalid dtype comparisons
4424+ if not is_numeric_v_string_like (nn , nn_at ):
4425+ comp = (nn == nn_at )
4426+ if is_list_like (comp ) and comp .all ():
4427+ nv = v .copy ()
4428+ nv [m ] = nn_at
4429+ return nv
44234430 except (ValueError , IndexError , TypeError ):
44244431 pass
44254432
0 commit comments