@@ -168,17 +168,11 @@ def make_block(self, values, placement=None, ndim=None, **kwargs):
168
168
169
169
return make_block (values , placement = placement , ndim = ndim , ** kwargs )
170
170
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__ ,
182
176
fastpath = fastpath , ** kwargs )
183
177
184
178
@mgr_locs .setter
@@ -573,12 +567,11 @@ def to_native_types(self, slicer=None, na_rep='nan', quoting=None, **kwargs):
573
567
574
568
# block actions ####
575
569
def copy (self , deep = True , mgr = None ):
570
+ """ copy constructor """
576
571
values = self .values
577
572
if deep :
578
573
values = values .copy ()
579
- return self .make_block (values ,
580
- klass = self .__class__ ,
581
- fastpath = True )
574
+ return self .make_block_same_class (values )
582
575
583
576
def replace (self , to_replace , value , inplace = False , filter = None ,
584
577
regex = False , convert = True , mgr = None ):
@@ -2140,6 +2133,13 @@ def __init__(self, values, placement, ndim=2,
2140
2133
placement = placement ,
2141
2134
ndim = ndim ,
2142
2135
** 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
+
2143
2143
def external_values (self ):
2144
2144
""" we internally represent the data as a DatetimeIndex, but for external
2145
2145
compat with ndarray, export as a ndarray of Timestamps """
@@ -3257,10 +3257,14 @@ def get_scalar(self, tup):
3257
3257
full_loc = list (ax .get_loc (x )
3258
3258
for ax , x in zip (self .axes , tup ))
3259
3259
blk = self .blocks [self ._blknos [full_loc [0 ]]]
3260
- full_loc [ 0 ] = self . _blklocs [ full_loc [ 0 ]]
3260
+ values = blk . values
3261
3261
3262
3262
# 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 )]
3264
3268
3265
3269
def delete (self , item ):
3266
3270
"""
@@ -4415,11 +4419,14 @@ def _putmask_smart(v, m, n):
4415
4419
try :
4416
4420
nn = n [m ]
4417
4421
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
4423
4430
except (ValueError , IndexError , TypeError ):
4424
4431
pass
4425
4432
0 commit comments