Skip to content

Commit 66d1843

Browse files
committed
updates
1 parent 3c1ffd0 commit 66d1843

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

doc/source/whatsnew/v0.24.0.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,6 @@ The default behavior remains the same, but issues a warning
13101310
The old or new behavior can be obtained by specifying the ``dtype``
13111311

13121312
.. ipython:: python
1313-
:okwarning:
13141313
13151314
# Old behavior
13161315
np.asarray(ser, dtype='datetime64[ns]')
@@ -1319,6 +1318,15 @@ The old or new behavior can be obtained by specifying the ``dtype``
13191318
np.asarray(ser, dtype=object)
13201319
13211320
1321+
Or by using :meth:`Series.to_numpy`
1322+
1323+
.. ipython:: python
1324+
1325+
ser.to_numpy()
1326+
ser.to_numpy(dtype="datetime64[ns]")
1327+
1328+
All the above applies to a :class:`DatetimeIndex` with tz-aware values as well.
1329+
13221330
.. _whatsnew_0240.prior_deprecations:
13231331

13241332
Removal of prior version deprecations/changes

pandas/core/internals/blocks.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,8 +1447,18 @@ def quantile(self, qs, interpolation='linear', axis=0):
14471447
-------
14481448
Block
14491449
"""
1450-
values = self.get_values()
1451-
values, _ = self._try_coerce_args(values, values)
1450+
if self.is_datetimetz:
1451+
# We need to operate on i8 values for datetimetz
1452+
# but `Block.get_values()` returns an ndarray of objects
1453+
# right now.
1454+
values = self.values.asi8
1455+
1456+
# Usual shape inconsistencies for ExtensionBlocks
1457+
if self.ndim > 1:
1458+
values = values[None, :]
1459+
else:
1460+
values = self.get_values()
1461+
values, _ = self._try_coerce_args(values, values)
14521462

14531463
is_empty = values.shape[axis] == 0
14541464
orig_scalar = not is_list_like(qs)
@@ -2480,40 +2490,6 @@ def setitem(self, indexer, value):
24802490
klass=ObjectBlock,)
24812491
return newb.setitem(indexer, value)
24822492

2483-
def quantile(self, qs, interpolation='linear', axis=0, axes=None):
2484-
# TODO: Add quantile as a reduction method.
2485-
# We can't just use Block.quantile, as that converts the DTA
2486-
# to an ndarray[object] via get_values.
2487-
# This method
2488-
# 1. Convert DatetimeTZBlock -> DatetimeBlock
2489-
# 2. Perform the op via Block.quantile
2490-
# 3. Converts back to tz-aware
2491-
# Alternatively, we could special case the call to `get_values`
2492-
# in Block.quantile for DatetimeTZ.
2493-
2494-
new_values = np.asarray(self.values, dtype=_NS_DTYPE)
2495-
if self.ndim == 2:
2496-
new_values = new_values[None, :]
2497-
2498-
new_block = DatetimeBlock(new_values, placement=self.mgr_locs)
2499-
2500-
ax, naive = new_block.quantile(qs, interpolation=interpolation,
2501-
axis=axis, axes=axes)
2502-
2503-
ndim = getattr(naive, 'ndim', None) or 0
2504-
if ndim == 0:
2505-
return ax, self.make_block_scalar(
2506-
tslibs.Timestamp(naive.values.value, tz=self.values.tz)
2507-
)
2508-
else:
2509-
naive = naive.values.ravel()
2510-
2511-
result = DatetimeArray(naive, dtype=self.values.dtype)
2512-
2513-
return ax, make_block(result,
2514-
placement=np.arange(len(result)),
2515-
ndim=ndim)
2516-
25172493

25182494
class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
25192495
__slots__ = ()

0 commit comments

Comments
 (0)