@@ -9776,26 +9776,8 @@ def describe_categorical_1d(data):
9776
9776
dtype = None
9777
9777
if result [1 ] > 0 :
9778
9778
top , freq = objcounts .index [0 ], objcounts .iloc [0 ]
9779
-
9780
- if is_datetime64_any_dtype (data ):
9781
- tz = data .dt .tz
9782
- asint = data .dropna ().values .view ("i8" )
9783
- top = Timestamp (top )
9784
- if top .tzinfo is not None and tz is not None :
9785
- # Don't tz_localize(None) if key is already tz-aware
9786
- top = top .tz_convert (tz )
9787
- else :
9788
- top = top .tz_localize (tz )
9789
- names += ["top" , "freq" , "first" , "last" ]
9790
- result += [
9791
- top ,
9792
- freq ,
9793
- Timestamp (asint .min (), tz = tz ),
9794
- Timestamp (asint .max (), tz = tz ),
9795
- ]
9796
- else :
9797
- names += ["top" , "freq" ]
9798
- result += [top , freq ]
9779
+ names += ["top" , "freq" ]
9780
+ result += [top , freq ]
9799
9781
9800
9782
# If the DataFrame is empty, set 'top' and 'freq' to None
9801
9783
# to maintain output shape consistency
@@ -9806,11 +9788,28 @@ def describe_categorical_1d(data):
9806
9788
9807
9789
return pd .Series (result , index = names , name = data .name , dtype = dtype )
9808
9790
9791
+ def describe_timestamp_1d (data ):
9792
+ tz = data .dt .tz
9793
+ asint = data .dropna ().values .view ("i8" )
9794
+ stat_index = ["count" , "mean" , "min" ] + formatted_percentiles + ["max" ]
9795
+ d = (
9796
+ [
9797
+ asint .shape [0 ],
9798
+ Timestamp (asint .mean (), tz = tz ),
9799
+ Timestamp (asint .min (), tz = tz ),
9800
+ ]
9801
+ + data .quantile (percentiles ).tolist ()
9802
+ + [Timestamp (asint .max (), tz = tz )]
9803
+ )
9804
+ return pd .Series (d , index = stat_index , name = data .name )
9805
+
9809
9806
def describe_1d (data ):
9810
9807
if is_bool_dtype (data ):
9811
9808
return describe_categorical_1d (data )
9812
9809
elif is_numeric_dtype (data ):
9813
9810
return describe_numeric_1d (data )
9811
+ elif is_datetime64_any_dtype (data ):
9812
+ return describe_timestamp_1d (data )
9814
9813
elif is_timedelta64_dtype (data ):
9815
9814
return describe_numeric_1d (data )
9816
9815
else :
@@ -9819,8 +9818,8 @@ def describe_1d(data):
9819
9818
if self .ndim == 1 :
9820
9819
return describe_1d (self )
9821
9820
elif (include is None ) and (exclude is None ):
9822
- # when some numerics are found, keep only numerics
9823
- data = self .select_dtypes (include = [np .number ])
9821
+ # when some numerics or timestamps are found, keep only those
9822
+ data = self .select_dtypes (include = [np .number , np . datetime64 ])
9824
9823
if len (data .columns ) == 0 :
9825
9824
data = self
9826
9825
elif include == "all" :
0 commit comments