Skip to content

Commit ff73c78

Browse files
committed
use internal series methods for datetime describe (#30209)
1 parent 2f57671 commit ff73c78

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

doc/source/whatsnew/v1.1.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Enhancements
1818
Other enhancements
1919
^^^^^^^^^^^^^^^^^^
2020

21+
- :meth:`Series.describe` will now show distribution percentiles for ``datetime`` dtypes, statistics ``first`` and ``last``
22+
will now be ``min`` and ``max`` to match with numeric dtypes in :meth:`DataFrame.describe` (:issue:`30164`)
2123
-
2224
-
2325

pandas/core/generic.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from pandas._config import config
3232

33-
from pandas._libs import NaT, Timestamp, iNaT, lib, properties
33+
from pandas._libs import Timestamp, iNaT, lib, properties
3434
from pandas._typing import (
3535
Axis,
3636
Dtype,
@@ -9640,18 +9640,11 @@ def describe_categorical_1d(data):
96409640

96419641
def describe_timestamp_1d(data):
96429642
# GH-30164
9643-
tz = data.dt.tz
9644-
asint = data.dropna().values.view("i8")
9645-
is_empty = asint.shape[0] == 0
96469643
stat_index = ["count", "mean", "min"] + formatted_percentiles + ["max"]
96479644
d = (
9648-
[
9649-
asint.shape[0],
9650-
Timestamp(asint.mean(), tz=tz) if not is_empty else NaT,
9651-
Timestamp(asint.min(), tz=tz) if not is_empty else NaT,
9652-
]
9645+
[data.count(), data.mean(), data.min(),]
96539646
+ data.quantile(percentiles).tolist()
9654-
+ [Timestamp(asint.max(), tz=tz) if not is_empty else NaT]
9647+
+ [data.max()]
96559648
)
96569649
return pd.Series(d, index=stat_index, name=data.name)
96579650

0 commit comments

Comments
 (0)