Skip to content

Commit 87101bf

Browse files
committed
Fixup DatetimeTZBlock.get_values
* 1-d return value * reshaping * docstring * always ndarray
1 parent 7dd3ba5 commit 87101bf

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

pandas/core/internals/blocks.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -2997,20 +2997,36 @@ def copy(self, deep=True):
29972997
return self.make_block_same_class(values)
29982998

29992999
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+
"""
30073020
values = self.values
30083021
if is_object_dtype(dtype):
30093022
values = values._box_values(values._data)
30103023

3024+
values = np.asarray(values)
3025+
30113026
if self.ndim == 2:
30123027
# Ensure that our shape is correct for DataFrame.
3013-
return values.reshape(1, -1)
3028+
values = values.reshape(1, -1)
3029+
return values
30143030

30153031
def _to_json_values(self):
30163032
# Patch to get JSON serialization working again.
@@ -3041,13 +3057,17 @@ def _try_coerce_args(self, values, other):
30413057
base-type values, base-type other
30423058
"""
30433059
# 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)
30453061

30463062
if isinstance(other, ABCSeries):
30473063
other = self._holder(other)
30483064

30493065
if isinstance(other, bool):
30503066
raise TypeError
3067+
elif is_datetime64_dtype(other):
3068+
# add the dz back
3069+
other = self._holder(other, dtype=self.dtype)
3070+
30513071
elif (is_null_datelike_scalar(other) or
30523072
(lib.is_scalar(other) and isna(other))):
30533073
other = tslibs.iNaT
@@ -3158,7 +3178,7 @@ def setitem(self, indexer, value):
31583178
# for extension arrays) is designed and implemented.
31593179
try:
31603180
return super(DatetimeTZBlock, self).setitem(indexer, value)
3161-
except ValueError:
3181+
except (ValueError, TypeError):
31623182
newb = make_block(self.values.astype(object),
31633183
placement=self.mgr_locs,
31643184
klass=ObjectBlock,)

0 commit comments

Comments
 (0)