@@ -2997,20 +2997,36 @@ def copy(self, deep=True):
2997
2997
return self .make_block_same_class (values )
2998
2998
2999
2999
def get_values (self , dtype = None ):
3000
- # TODO: We really need to pin down this type
3001
- # Previously it was Union[ndarray, DatetimeIndex]
3002
- # but now it's Union[ndarray, DatetimeArray]
3003
- # I suspect we really want ndarray, so we need to
3004
- # check with the callers....
3005
- # return object dtype as Timestamps with the zones
3006
- # We added an asarray to BlockManager.as_array to work around this.
3000
+ """
3001
+ Returns an ndarray of values.
3002
+
3003
+ Parameters
3004
+ ----------
3005
+ dtype : np.dtype
3006
+ Only `object`-like dtypes are respected here (not sure
3007
+ why).
3008
+
3009
+ Returns
3010
+ -------
3011
+ values : ndarray
3012
+ When ``dtype=object``, then and object-dtype ndarray of
3013
+ boxed values is returned. Otherwise, an M8[ns] ndarray
3014
+ is returned.
3015
+
3016
+ DatetimeArray is always 1-d. ``get_values`` will reshape
3017
+ the return value to be the same dimensionality as the
3018
+ block.
3019
+ """
3007
3020
values = self .values
3008
3021
if is_object_dtype (dtype ):
3009
3022
values = values ._box_values (values ._data )
3010
3023
3024
+ values = np .asarray (values )
3025
+
3011
3026
if self .ndim == 2 :
3012
3027
# Ensure that our shape is correct for DataFrame.
3013
- return values .reshape (1 , - 1 )
3028
+ values = values .reshape (1 , - 1 )
3029
+ return values
3014
3030
3015
3031
def _to_json_values (self ):
3016
3032
# Patch to get JSON serialization working again.
@@ -3041,13 +3057,17 @@ def _try_coerce_args(self, values, other):
3041
3057
base-type values, base-type other
3042
3058
"""
3043
3059
# asi8 is a view, needs copy
3044
- values = _block_shape (values .asi8 , ndim = self .ndim )
3060
+ values = _block_shape (values .view ( "i8" ) , ndim = self .ndim )
3045
3061
3046
3062
if isinstance (other , ABCSeries ):
3047
3063
other = self ._holder (other )
3048
3064
3049
3065
if isinstance (other , bool ):
3050
3066
raise TypeError
3067
+ elif is_datetime64_dtype (other ):
3068
+ # add the dz back
3069
+ other = self ._holder (other , dtype = self .dtype )
3070
+
3051
3071
elif (is_null_datelike_scalar (other ) or
3052
3072
(lib .is_scalar (other ) and isna (other ))):
3053
3073
other = tslibs .iNaT
@@ -3158,7 +3178,7 @@ def setitem(self, indexer, value):
3158
3178
# for extension arrays) is designed and implemented.
3159
3179
try :
3160
3180
return super (DatetimeTZBlock , self ).setitem (indexer , value )
3161
- except ValueError :
3181
+ except ( ValueError , TypeError ) :
3162
3182
newb = make_block (self .values .astype (object ),
3163
3183
placement = self .mgr_locs ,
3164
3184
klass = ObjectBlock ,)
0 commit comments