| 188 | |
| 189 | |
| 190 | def describe_numeric_aggregate( |
| 191 | stats, |
| 192 | name=None, |
| 193 | is_timedelta_col=False, |
| 194 | is_datetime_col=False, |
| 195 | unit="ns", |
| 196 | ): |
| 197 | unit = unit or "ns" |
| 198 | assert len(stats) == 6 |
| 199 | count, mean, std, min, q, max = stats |
| 200 | |
| 201 | if is_series_like(count): |
| 202 | typ = type(count.to_frame()) |
| 203 | else: |
| 204 | typ = type(q) |
| 205 | |
| 206 | if is_timedelta_col: |
| 207 | mean = pd.to_timedelta(mean, unit=unit).as_unit(unit) |
| 208 | std = pd.to_timedelta(std, unit=unit).as_unit(unit) |
| 209 | min = pd.to_timedelta(min, unit=unit).as_unit(unit) |
| 210 | max = pd.to_timedelta(max, unit=unit).as_unit(unit) |
| 211 | q = q.apply(lambda x: pd.to_timedelta(x, unit=unit).as_unit(unit)) |
| 212 | |
| 213 | if is_datetime_col: |
| 214 | # mean is not implemented for datetime |
| 215 | min = pd.to_datetime(min, unit=unit).as_unit(unit) |
| 216 | max = pd.to_datetime(max, unit=unit).as_unit(unit) |
| 217 | q = q.apply(lambda x: pd.to_datetime(x, unit=unit).as_unit(unit)) |
| 218 | |
| 219 | if is_datetime_col: |
| 220 | part1 = typ([count, min], index=["count", "min"]) |
| 221 | else: |
| 222 | part1 = typ([count, mean, std, min], index=["count", "mean", "std", "min"]) |
| 223 | |
| 224 | q.index = [f"{l * 100:g}%" for l in tolist(q.index)] |
| 225 | if is_series_like(q) and typ != type(q): |
| 226 | q = q.to_frame() |
| 227 | part3 = typ([max], index=["max"]) |
| 228 | |
| 229 | result = concat([part1, q, part3], sort=False) |
| 230 | |
| 231 | if is_series_like(result): |
| 232 | result.name = name |
| 233 | |
| 234 | return result |
| 235 | |
| 236 | |
| 237 | def describe_nonnumeric_aggregate(stats, name): |